Hi,
I've looked through some old posts about this here
http://wxpython-users.1045709.n5.nabble.com/Catching-Shutdown-Events-td2365230.html
and on the wxWiki.
I have tried catching the application shutdown events on my Windows XP
system with Python 2.3.4 and WxPython 2.8.9.1 (msw-ansi)
I can't make it work on my system either, and I'm wondering if anyone
has.
Do I need to get a newer version of wxPython?
No, those events unfortunately don't work. You can workaround it using
system libraries to install a termination handler. Included below is a
method from one of my libraries.
This method requires win32api extensions on Windows. You just need
call it with a function as an argument to use as a callback. The
function will get called when the os tries to shutdown the
application.
def InstallTermHandler(callback, *args, **kwargs):
"""Install exit app handler for sigterm (unix/linux)
and uses SetConsoleCtrlHandler on Windows.
@param callback: callable(*args, **kwargs)
@return: bool (installed or not)
"""
assert callable(callback), "callback must be callable!"
installed = True
if wx.Platform == '__WXMSW__':
if HASWIN32:
win32api.SetConsoleCtrlHandler(lambda dummy :
callback(*args, **kwargs),
True)
else:
installed = False
else:
signal.signal(signal.SIGTERM,
lambda signum, frame : callback(*args, **kwargs))
return installed
Works for what I needed it for but YMMV
Cody
···
On Tue, Dec 14, 2010 at 1:00 PM, cappy2112 <cappy2112@gmail.com> wrote: