Hi,
I (re)read the Patrick's manual, and the following point
happens to my mind.
It's related to the wx.App class and the lauching of an
application.
A 'normal' wxPython application looks like this:
···
#-----------------------------------------------------------
import wx
#-----------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self, ...):
wx.Frame.__init__(self, ...)
...
#-----------------------------------------------------------
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(...)
frame.Show(True)
self.SetTopWindow(frame)
return True
#-----------------------------------------------------------
def main():
app = MyApp()
app.MainLoop()
#-----------------------------------------------------------
if __name__ == "__main__" :
main()
#------------------------------------------------------
The sub OnInit is automatically called, when an instance of
MyApp is created (before the app.MainLoop() statement)
Now my question:
Why should/may I not define the MyApp class with code like
this.
class MyApp(wx.App):
def __init__(self):
wx.App.__init__(self)
r = self.OnInit()
def OnInit(self):
...
The above code is working, but it lauches (logically) the
app twice.
It presents the advantage of beeing more 'pythonic'.
It looks like other wxPython classes.
In 'normal' code, I also noticed, that when creating a
instance like app = MyApp() but without app.MainLoop()
python/wxPython crashes. I mean a real crash, not the fact
that the main frame is not desplayed. Is this a normal
behaviour?
What exactly launches an application? Class instanciation
or MainLoop()
Should not the wx.App be cleaned up?
Sorry for such stupid questions!
Jean-Michel Fauth, Switzerland