[wxPython-users] Re: How to do cleanup when system shutdown closes
the app?
Robin Dunn
robin at alldunn.com
Tue Jul 4 19:23:36 PDT 2006
Avery.Andrews at anu.edu.au wrote:
> This thread has been in abeyance for a bit, so I'll review and rephrase.
> I have an app which I want to save its data when the system shuts down,
> as well as when the app itself is explicitly shut down. It seems like
> processing the EVT_QUERY_END_SESSION ought to be the right thing to do,
> but, on the Windows platform, using Python 2.4.2 and Ansi wxpython 2.6.3.2
> (and various prior versions), this code doesn't produce any dialog window
> on system shutdown:
>
> class RunnerApp(wx.App):
> def OnInit(self):
> frame = RunnerFrame(None, "TreeRunner")
> self.SetTopWindow(frame)
> frame.Show(True)
> self.Bind(wx.EVT_QUERY_END_SESSION, self.Query)
> return True
>
> def Query(self, event):
> dlg = wx.MessageDialog(self, 'OK to Quit?',
> 'A Message Box',
> wx.YES_NO
> )
AS has already been mentioned you can't use the app as the parent of the
dialog. Either change that to None, or save a reference to the frame to
use.
> answer = dlg.ShowModal()
> dlg.Destroy()
> if answer!=wx.ID_YES:
> return 1
> return 0
Also, the return value of an event handler is ignored. The way to
signal that the session should not be ended is to call event.Veto().
>
> if __name__ == '__main__':
>
> app = RunnerApp(redirect=0)
> app.MainLoop()
>
> So is it possible that the EVT_QUERY_END_SESSION msg is simply not being
> processed in the Windows version of wxpython? Or an I making some mistake
> in using it.
As I think I said before, the code is in place and looks like it should
work fine, but I can't debug it to see what is really happening because
the debugger gets the WM_QUERYENDSESSION before the debugged app does,
and so I can't see what's really going on because it either stops the
shutdown or kills the app and exits.
Please enter a bug report about this with a category of "wxMSW Specific"
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list