Managing a normal shutdown

During the shutdown process, wxPython takes care of deleting all its windows and freeing their resources. You have one hook into the exit process to perform your own cleanup. If defined, the OnExit() method of your wx.App subclass is called after the last window closes but before wxPython's internal cleanup. You can use this method to clean up any non-wxPython resources you've created (a database connection, for example). Even if the application is closed with wx.Exit(), the OnExit() method is still triggered.

If for some reason you want the application to continue after the last window closes, you can change the default behavior using the wx.App method SetExitOn-FrameDelete(flag). If the flag parameter is set to False, the program will continue to run even after the last window closes. This means that the wx.App instance will continue to live, and the event loop will continue to process events. You could, for example, then create all new top-level windows. The application will remain alive until the global function wx.Exit() is explicitly called.

A further subtlety is that wxPython will not trigger the shutdown process before the main loop is even entered. Specifically, if you open a dialog in your OnInit() method, you can close it without fear that wxPython will interpret that as closing your last top-level window and shut itself down.

Was this article helpful?

0 0

Post a comment