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.
First time here? Check out the FAQ!
Hi,
How can I let wing running a script when user close/exit it?
Regards.
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...
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.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2020-06-02 18:08:39 -0500
Seen: 500 times
Last updated: Jun 03 '20
Why does wing-internal-python need to receive incoming connections?
Issue with loading modules on hpc system
Debug probe last evaluated code selection doesn't remain in history
Test discovery without test running?
Importing GitHub.com repo as new project
Auto-reformatting using Black doesn't use config in pyproject.toml
How load PYTHONSTARTUP for Debug Probe?
Are colors in built-in python shell planned to be supported?