Shutdown woes

Hi all,

I am trying to let Task Coach behave in the face of a system shutdown or the user logging off, i.e. if there are any unsaved changes, give the user the option to save, not save, or cancel the shutdown/log-off.

Based on the documentation, I thought I had to bind wx.EVT_QUERY_END_SESSION and wx.EVT_END_SESSION, however event handlers for those two events are never invoked. You can experiment with the attached program if you like.

However, the handler for wx.EVT_CLOSE is called when I log off or try to shutdown the system. I can distinguish between a 'normal' close event and a shutdown event by asking the event whether it can be vetoed. Normal close events can and shutdown/log-off close events cannot. I thought a work around would be to simply not call event.Skip() for shutdown/log-off close events. This works, sort of: the shutdown/log-off is postponed until the user quits Task Coach. After quitting Task Coach, the shutdown or log-off continues!

By contrast, Firefox is able to really cancel a shutdown/log-off: if you have multiple tabs opened and try to log off, Firefox asks whether you want to close all tabs. If the user chooses cancel, the shutdown/log-off is canceled too.

So I guess my question is: is it possible to cancel a shutdown/log-off from a wxPython program?

Cheers, Frank

shutdown.py (1.39 KB)

Frank Niessink wrote:

So I guess my question is: is it possible to cancel a shutdown/log-off from a wxPython program?

I don't know. I see the code there, and it appears valid according to the API docs. But I can't trace through it with the debugger to see what's wrong because the debugger also catches the query end session and terminates the shutdown before the wxPython app gets a chance... If I change so the code that sends the end session events is called for some other event, then the end session events are being caught in wxPython, so the binding is correct. If I can think of anything else to try I will...

ยทยทยท

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!