Is there en event when the app is about to close?

Hi folks,

I'm looking at improving iPython integration with wxPython. My goal is to be able to run my wxPython app from the iPython command line, and run it over an over again. Recently, iPython has made some improvements to how this can be done (see trunk). It does require a bit of special code at startup, but it works nicely for me so far.

However, there is this problem, from the iPython examples:

"""
This example can only be run once in a given IPython session because when the frame is closed, wx goes through its shutdown sequence, killing further attempts. I am sure someone who knows wx can fix this issue.

Furthermore, once this example is run, the Wx event loop is mostly dead, so even other new uses of Wx may not work correctly. If you know how to better handle this, please contact the ipython developers and let us know.
"""

What I'm thinking is that if there is an event you can bind in your app object when wx is about to shut down, and veto that event, then the main code could be run again, and it would just have to check if an ap had already been created.

Ideally, the apps OnInit would get re-run too -- I'd have to think about that first.

But first, I need to know if there is an event that I can catch and veto -- essentially letting the app stay running once all the Windows are closed.

If anyone's got any other ideas about how to make this work, I'm all ears.

-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

According to wxPython in Action, starting on page 232, you probably
want EVT_CLOSE. That's what I usually use to catch wx's closing cycle.
There is also EVT_END_SESSION which should get fired when the system
is trying to shut down, but it might be worth a try as well.

···

On Mar 25, 3:32 pm, Christopher Barker <Chris.Bar...@noaa.gov> wrote:

Hi folks,

I'm looking at improving iPython integration with wxPython. My goal is
to be able to run my wxPython app from the iPython command line, and run
it over an over again. Recently, iPython has made some improvements to
how this can be done (see trunk). It does require a bit of special code
at startup, but it works nicely for me so far.

However, there is this problem, from the iPython examples:

"""
This example can only be run once in a given IPython session because
when the frame is closed, wx goes through its shutdown sequence, killing
further attempts. I am sure someone who knows wx can fix this issue.

Furthermore, once this example is run, the Wx event loop is mostly dead,
so even other new uses of Wx may not work correctly. If you know how to
better handle this, please contact the ipython developers and let us know.
"""

What I'm thinking is that if there is an event you can bind in your app
object when wx is about to shut down, and veto that event, then the main
code could be run again, and it would just have to check if an ap had
already been created.

Ideally, the apps OnInit would get re-run too -- I'd have to think about
that first.

But first, I need to know if there is an event that I can catch and veto
-- essentially letting the app stay running once all the Windows are closed.

If anyone's got any other ideas about how to make this work, I'm all ears.

-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.Bar...@noaa.gov

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

If you call theApp.SetExitOnFrameDelete(False) then the MainLoop will not exit when all the top-level windows are closed. For the rest of it you can probably inject (monkey-patch) some code into the wx.App class that makes it act like a singleton and instead of creating a 2nd instance it just recalls the OnInit method. The trick will be to figure out how to handle the case where an app created after the first one is not the same class.

···

On 3/25/10 1:32 PM, Christopher Barker wrote:

Hi folks,

I'm looking at improving iPython integration with wxPython. My goal is
to be able to run my wxPython app from the iPython command line, and run
it over an over again. Recently, iPython has made some improvements to
how this can be done (see trunk). It does require a bit of special code
at startup, but it works nicely for me so far.

However, there is this problem, from the iPython examples:

"""
This example can only be run once in a given IPython session because
when the frame is closed, wx goes through its shutdown sequence, killing
further attempts. I am sure someone who knows wx can fix this issue.

Furthermore, once this example is run, the Wx event loop is mostly dead,
so even other new uses of Wx may not work correctly. If you know how to
better handle this, please contact the ipython developers and let us know.
"""

What I'm thinking is that if there is an event you can bind in your app
object when wx is about to shut down, and veto that event, then the main
code could be run again, and it would just have to check if an ap had
already been created.

Ideally, the apps OnInit would get re-run too -- I'd have to think about
that first.

But first, I need to know if there is an event that I can catch and veto
-- essentially letting the app stay running once all the Windows are
closed.

If anyone's got any other ideas about how to make this work, I'm all ears.

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

If you call theApp.SetExitOnFrameDelete(False) then the MainLoop will not exit when all the top-level windows are closed.

I had just discovered that right before I read this note -- thanks.

For the rest of it you can probably inject (monkey-patch) some code into the wx.App class that makes it act like a singleton and instead of creating a 2nd instance it just recalls the OnInit method.

right -- I think that's what the current iPython code does, but it's not working right for me at this point.

The trick will be to figure out how to handle the case where an app created after the first one is not the same class.

yeah, I'm wondering about that -- tough the common case is the same app being re-started repeatedly.

I hope I'll get a chance to dig into the code and try to get this to work -- if so, I'll probably have another question or two.

-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