Why does wx.App.OnInit() exit the interpreter?

When my OnInit() returns False, the entire Python session is closed:

pmcnett@sol:~/projects/dabo/dabo/ui/uiwx$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> class MyApp(wx.App):
... def OnInit(self):
... return False
...
>>> app = MyApp()
OnInit returned false, exiting...
pmcnett@sol:~/projects/dabo/dabo/ui/uiwx$

Why? What if I wanted my code to recover from that?

···

--
Paul McNett
http://paulmcnett.com
http://dabodev.com

Paul McNett wrote:

When my OnInit() returns False, the entire Python session is closed:

That is odd.

pmcnett@sol:~/projects/dabo/dabo/ui/uiwx$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> class MyApp(wx.App):
... def OnInit(self):
... return False
...
>>> app = MyApp()
OnInit returned false, exiting...
pmcnett@sol:~/projects/dabo/dabo/ui/uiwx$

Why? What if I wanted my code to recover from that?

I'm guessing that recovering from that, at least by using anything wx, would be impossible, as wx has to be initialized correctly, once and only once. However, I can see how you might want to do something non gui.

However, you are writing the OnInit, so just make sure it always returns True.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (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

When my OnInit() returns False, the entire Python session is closed:

in C++ wx, when you return false from OnInit, it means your
application failed to initialize, and should exit. wxPython maintains
these semantics.

pmcnett@sol:~/projects/dabo/dabo/ui/uiwx$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> class MyApp(wx.App):
... def OnInit(self):
... return False
...
>>> app = MyApp()
OnInit returned false, exiting...
pmcnett@sol:~/projects/dabo/dabo/ui/uiwx$

Why? What if I wanted my code to recover from that?

As the other Chris said, you cannot recover from this in a meaningful
way - wx internals are in a "cleaned up" state and as far as I know
there is no support for re-initializing them in C++, much less exposed
in wxPython.

However, what you can do instead is override MainLoop and return false
from that, or even just not create any top level windows -
wx.App.MainLoop() will return immediately. You will still have an
initialized wx instance and you can attempt to recover and even call
MainLoop again.

···

On 11/29/05, Paul McNett <p@ulmcnett.com> wrote:

--
Paul McNett
http://paulmcnett.com
http://dabodev.com

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

Chris Mellon wrote:

As the other Chris said, you cannot recover from this in a meaningful
way - wx internals are in a "cleaned up" state and as far as I know
there is no support for re-initializing them in C++, much less exposed
in wxPython.

However, what you can do instead is override MainLoop and return false
from that, or even just not create any top level windows -
wx.App.MainLoop() will return immediately. You will still have an
initialized wx instance and you can attempt to recover and even call
MainLoop again.

Ok, thanks for the explanation! I guess I was just surprised at the time...

···

--
Paul McNett
http://paulmcnett.com
http://dabodev.com