Hi Daniel,
Hello,
What's up with the OnInit method? When do I need it? On the wiki I see
two different ways to start a wxPython program:
class MyApp(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Hello")
and
class MyApp(wx.App):
def OnInit(self):
What's the difference between these? Why are there two?
Daniel.
It's probably just inherited from the C++ stuff, but you'll note that
OnInit() only applies to wx.App classes. Here's what the wxPython in
Action book says:
<quote>
It’s called by the wxPython system when the application is started and
before the main event loop begins. This method takes no parameters and
returns a boolean value—if the return value is False, then the
application will exit immediately. In most cases, you’ll want to
hardwire True as the result of this method. Exiting might be the
proper way to handle certain error conditions, such as the absence of
a required resource. Because the OnInit() method exists, and is part
of the wxPython framework, any initialization needed for your custom
class is typically managed there, and not in the Python __init__
special method. If you decide that you need an __init__ method for
some reason, you must call the __init__ method of the parent class in
that method, as in the following.
wx.App.__init__(self)
Typically, you’ll create at least one frame object within the OnInit()
method, and you’ll also call the Show() method of that frame. You may
optionally specify that the frame is the top window for the
application by calling the method SetTopWindow(). The top window is
used as the default parent for dialogs that are created without a
parent—it’s essentially the main window of your program. We’ll discuss
the top-level window in section 2.5.
</quote>
Hopefully Manning and Dunn won't hunt me down now...
···
On Jan 14, 1:11 pm, Daniel Carrera <dcarr...@gmail.com> wrote:
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org
PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/