How does your application start?

A common issue!

The OnInit method calls the super classes init method!

···

On 4/20/07, 7stud <bbxx789_05ss@yahoo.com > wrote:

Say you have this code:


import wx

class MyApp(wx.App
):

def OnInit(self):
    frame = wx.Frame(None)
    frame.Show()
    return True

app = MyApp()
app.MainLoop()

If you define an init() method and then inside the method you

relay self to wx.App’s init() method, for instance:

wx.App__init__(self)

then it seems likely that inside wx.App.init() there will be a call
to self.OnInit() to start your app.

However, if you don’t define an init() method, how does

wx.App.init() start your app? How does it
get a reference to your app?

Thanks.


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org


http://www.goldwatches.com/watches.asp?Brand=39
http://www.wazoozle.com

James Matthews <nytrokiss <at> gmail.com> writes:

A common issue!The OnInit method calls the super classes __init__ method!

Huh? Here's my OnInit() method:

def OnInit(self):
        frame = wx.Frame(None)
        frame.Show()
        return True

I don't see a call to the super class's __init__ method anywhere.

James Matthews wrote:

A common issue!

The OnInit method calls the super classes __init__ method!

Almost.

This isn't a wx specific issue:

When an object is initialized by Python, it's __init__ method is called. The way all attributes are resolved is to first look in the class for in, and if there isn't one there, it looks in the superclasses for it. So, if you don't define an __init__ in your subclass, the superclass' __init__ is called.

That's why you generally need to explicitly call the superclass' __init__ when you write your own __init__ -- you're overriding the superclass' __init__, so it won't get called if you don't call it.

In the the case of wx.App, I'm pretty sure OnInit() is called in wx.App.__init__.

clear as mud?

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov