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.
Hi,
How can I let wing running a script when user close/exit it?
Regards.
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.
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.
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.
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.
"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...
To enter a block of code:
Comments