First time here? Check out the FAQ!
1

Let wing running a script when user close/exit it.
 

Hi,

How can I let wing running a script when user close/exit it?

Regards.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
hongyi-zhao's avatar
557
hongyi-zhao
asked 4 years ago, updated 4 years ago

Comments

see more comments

2 Answers

0

If you are talking about the Debugger, it should work to use the Debug > Processes > Detach from Process menu item and then the debug process will continue and not be terminated when Wing quits.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Wingware Support's avatar
4.2k
Wingware Support
answered 4 years ago
link

Comments

No, I mean the general case. When I exit/close wing, this event can trigger some script to do a post-processing job for me.

hongyi-zhao's avatar hongyi-zhao (4 years ago)
see more comments
0

You can write an extension script as described in https://wingware.com/doc/scripting and connect to a signal that is emitted when Wing quits. This isn't currently exposed in the API (I'll see if we can add this, and thus am marking this ticket as a feature-request) but you can reach through the API to do it, something like this:

import wingapi

def _quitting():
  # Do something here
  pass

wingapi.gApplication.fSingletons.fGuiMgr.connect('about-to-quit', _quitting)

There is also a signal called 'quit' that can be used instead. The one above is emitted when the mainloop is still running while 'quit' is emitted after the mainloop exits. In your case either is probably fine.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Wingware Support's avatar
4.2k
Wingware Support
answered 4 years ago
link

Comments

Thanks a lot, based on your above instructions. I write the following script in ~/.wingpro7/scripts named as preferences-strip.py and it does the trick:

import wingapi

def _quitting():
  # Do something here
  import os
  import re

  # https://ask.wingware.com/question/2091/the-meaning-for-the-perference-option-mainlast-prefs-page/
  # https://ask.wingware.com/question/2085/duplicates-entries-generated-for-mainupdate-history-list-in-the-wingpro7preferences/
  flag = False
  preferences = os.environ['HOME'] + '/.wingpro7/preferences'
  lines = []
  with open(preferences, 'r') as f:
      for line in f:
          line = line.strip('\n')
          if re.match(r'^main[.](update-history|last-prefs-page)', line):
              flag = True
          else:
              if flag and not re.match(r'[ ]', line):
                  flag = False
          if not flag:
              lines.append(line)

  with open(preferences, "w") as f:
      f.write('\n'.join(str(item) for item in lines))
      f.write('\n')

  pass

wingapi.gApplication.fSingletons.fGuiMgr.connect('about-to-quit', _quitting)

But I still cannot figure out why you use pass command on the example codes. Any hints?

Regards.

hongyi-zhao's avatar hongyi-zhao (4 years ago)

"pass" does nothing. It's used in Python as a place-holder so you can write something that's syntactically correct but doesn't have actual code in it yet. You can remove it from your code above...

Wingware Support's avatar Wingware Support (4 years ago)
see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)