Exit app code

Hi, I have an app that, on exit, will save settings about the app (x,y on
screen, height, width, some customized view information).

Right now, it works great if I close from the file menu, and do an
wxGetApp().ExitMainLoop().

My question is, how do I trap exiting in other ways (right click the X on
the right corner of the window, etc.). When I do this, the ExitMainLoop() is
never run and I get error messages.

Is there one specific routine that everything will call, no matter how the
app closes?

Thanks!

Tim

Tim Royal wrote:

Hi, I have an app that, on exit, will save settings about the app (x,y on
screen, height, width, some customized view information).

Right now, it works great if I close from the file menu, and do an
wxGetApp().ExitMainLoop().

My question is, how do I trap exiting in other ways (right click the X on
the right corner of the window, etc.). When I do this, the ExitMainLoop() is
never run and I get error messages.

What you want to do is to catch your frame's EVT_CLOSE. Your handler for it should save your settings & configuration, and then call frame.Destroy() to finish the process. This should work for every variety of (normal) application exit, because part of exiting the app will always be that your frame closes. (Note that this also means that you can exit gracefully by sending wxEVT_CLOSE to your frame.) I typically have an OnCloseWindow() method that is used as the handler for both EVT_CLOSE and the File->Exit menu item.

Jeff Shannon
Technician/Programmer
Credit International

In Monday, October 20, 2003, 6:54:15 PM, Tim wrote:

My question is, how do I trap exiting in other ways (right click
the X on the right corner of the window, etc.). When I do this,
the ExitMainLoop() is never run and I get error messages.

EVT_CLOSE(self, self.Do_this_before_closing)

...

def Do_this_before_closing(self):
    # Executes code below before closing - probably the same method
    # you are calling from the File>Exit menu.
    ...

HTH

-- Tacão