Page 69      All Pages  All Books
34              CHAPTER 2
Giving your wxPython program a solid foundation
The data members of the C++ classes are private—in most cases you must access the data of a wxPython class by using the access methods, you cannot use bare attribute names.
2.2.2 Understanding the application object lifecycle
The lifecycle of your wxPython application object begins when the application instance is created and ends just after the last application window is closed. This does not necessarily correspond to the beginning and ending of the Python script that surrounds your wxPython application. The script may choose to do some activity before creating the wxPython application, and may do fur­ther cleanup after the application MainLoop() exits. All wxPython activity, how­ever, must be performed during the life of the application object. As we’ve mentioned, this means that your main frame object cannot be created until after the wx.App object is created. (This is one reason why we recommend creat­ing the top-level frame in the OnInit() method—doing so guarantees that the application already exists.)
As figure 2.2 shows, creating the application object triggers the OnInit() method and allows new window objects to be created. After OnInit(), the script calls MainLoop(), signifying that wxPython events are now being handled. The application continues on its merry way, handling events until the windows are closed. After all top-level windows are closed, the MainLoop() function returns to the calling scope and the application object is destroyed. After that, the script can close any other connections or threads that might exist.

Page 69      All Pages  All Books