How to do cleanup when system shutdown closes the app?

Avery.Andrews at anu.edu.au Avery.Andrews at anu.edu.au
Mon Jul 3 22:36:57 PDT 2006


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
                               )
        answer =  dlg.ShowModal()
        dlg.Destroy()
        if answer!=wx.ID_YES:
            return 1
        return 0

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.

 - Avery Andrews






More information about the wxpython-users mailing list