[wx-dev] wxSimpleApp or IMPLEMENT_SIMPLE_APP?

Robin Dunn robin at alldunn.com
Wed Jun 25 17:03:58 PDT 2008


Vadim Zeitlin wrote:

>  The only problem that I see is that it's not totally clear where should
> the GUI initialization (e.g. connecting to X server) be done: wxInitializer
> shouldn't do it because it can be used in non-GUI applications too so we'd
> either have to invent some new wxGUIInitializer or maybe create a local
> wxApp, e.g.
> 
> 	wxApp app;
> 	if ( !app.Initialize() ) // here the GUI initialization is done
> 		return -1;
> 
> 	(new MyFrame)->Show();
> 
> 	return app.MainLoop();
> 

This is essentially how wxPython apps are structured.  I also support 
deriving from wx.App and implementing OnInit, but it hasn't been 
required to do that for several releases now.  For example:

	def main():
		app = wx.App()
		frm = MyFrame(None)
		frm.Show()
		app.MainLoop()

The GUI initialization is done in the wx.App constructor, and up until 
that point nothing heavyweight has been done with wx or the native UI. 
Before this change that would happen when the core module was imported, 
which caused problems for Python tools using module introspection, or 
just wanting to check the version number for example, as they would need 
to have access to the X-Server to be able to do it.  Another nice 
benefit of this change is that whichever thread is active when the 
wx.App is created is the one that is considered the main thread by wx, 
so this plays well with python apps that want to do something else with 
the real main thread.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



More information about the wx-dev mailing list