Thanks Robin
1) About the app.MainLoop()
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?
No. I've seen it if you try to do some things before the
app is
created, but not if it is just that MainLoop is not being
called. One
thing to watch out for though is even if your app is just a
modal dialog
you still need to call MainLoop so it can properly cleanup
after the
dialog. Then it will exit immediately since there are no
more
top-level windows left.
I do not agree with you, if I'm considering the following
basic
application:
···
#-----------------------------------------------------------
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()
#------------------------------------------------------
With the "app.MainLoop()", it works fine. But if I remove
the
app.MainLoop() line, I got the following:
i) the main frame flashes on the screen (it appears and
desappears), this is
normal
ii) but I got the following message:
21:15:36: Debug: e:\projects\wx\src\msw\app.cpp(439):
'UnregisterClass(canvas)' failed with error 0x00000000
(l'op�ration s'est termin�e.).
- it is not a dialog window
- I do not try to do some things before the app is created
- The problem remains, if I put the two lines
app = MyApp()
app.MainLoop()
directly in the if __name__ == ... block
(win98, py2.2.3, wxpy 2.4.0.1)
2)
Should not the wx.App be cleaned up?
It is when the app object is deleted. Further cleanup is
done when the
wxPython.wx module is cleaned up by Python at shutdown.
Sorry for my english, cleanup was not the correct word.
I was asking, if it is not better to disconnect the OnInit()
from
the MyApp class instantiation I mean, forcing the programmer
to launch/bootstrap the application by a the statement like
OnInit
in the __init__ of MyApp.
class MyApp(wx.App):
def __init__(self):
wx.App.__init__(self)
r = self.OnInit() #Force here the start of the
application
def OnInit(self):
...
- Code is nicer, it looks like others wx classes.
- Possibility to put some code in the __init__ instead
of in the main() sub, like db initialisation
- You told, the bootstrap is an old stuff
Regards,
Jean-Michel Fauth, Switzerland