Nesting event loops or using a custom dialog

Hi all,

I've been messing with the issue all morning and I just cannot get it to
work. I have a main wxPython application that needs to open another
wxPython application. My main app is using wx.App and works great. I
started out the same way with the secondary app and it works great if I
run it by itself. If I call the second application like this:

# from a menu event handler:
from all_alerts import AllAlerts
app = AllAlerts(self.fName)
app.MainLoop()

The 2nd app loads and run fine, but when I close it, the buttons no longer
work on the original application. And if I close the original, it says
that pythonw.exe has encountered and error. I tried making the 2nd app
into a modal custom dialog, but the same thing happens. How do I return
the event loop back to the calling application?

Thanks a lot.

Mike Driscoll
Applications Specialist
MCIS - Technology Center

Hi Mike,

Hi all,

I've been messing with the issue all morning and I just cannot get it to
work. I have a main wxPython application that needs to open another
wxPython application. My main app is using wx.App and works great. I
started out the same way with the secondary app and it works great if I
run it by itself. If I call the second application like this:

# from a menu event handler:
from all_alerts import AllAlerts
app = AllAlerts(self.fName)
app.MainLoop()

The 2nd app loads and run fine, but when I close it, the buttons no longer
work on the original application. And if I close the original, it says
that pythonw.exe has encountered and error. I tried making the 2nd app
into a modal custom dialog, but the same thing happens. How do I return
the event loop back to the calling application?

Uhm, does it have to be another wx.App? I mean, the 2nd app will
surely be based on a wx.Frame (or wx.MiniFrame or wx.Dialog or
wx.MDI): having said that, you could do something like:

from TheSecondAppMainModule import TheSecondAppMainFrame

frame = TheSecondAppMainFrame(None, -1, ...)
frame.Show()

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On 6/13/07, Mike Driscoll wrote:

Mike Driscoll wrote:

Hi all,

I've been messing with the issue all morning and I just cannot get it to
work. I have a main wxPython application that needs to open another
wxPython application. My main app is using wx.App and works great. I
started out the same way with the secondary app and it works great if I
run it by itself. If I call the second application like this:

# from a menu event handler:
from all_alerts import AllAlerts
app = AllAlerts(self.fName)
app.MainLoop()

The 2nd app loads and run fine, but when I close it, the buttons no longer
work on the original application. And if I close the original, it says
that pythonw.exe has encountered and error. I tried making the 2nd app
into a modal custom dialog, but the same thing happens.

You can only have one wx.App active at a time in any process. When your 2nd one terminates it is assuming that the process is going to terminate soon and it cleans up and destroys a bunch of resources that wx needs to continue working.

If you really want to treat it as a separate application then you should spawn it in a new process. Otherwise just do as Andrea suggested and create the frame in the new app without using its app object.

···

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

> The 2nd app loads and run fine, but when I close it, the buttons no
> longer work on the original application. And if I close the
original,
> it says that pythonw.exe has encountered and error. I tried
making the
> 2nd app into a modal custom dialog, but the same thing
happens. How do
> I return the event loop back to the calling application?

Uhm, does it have to be another wx.App? I mean, the 2nd app
will surely be based on a wx.Frame (or wx.MiniFrame or wx.Dialog or
wx.MDI): having said that, you could do something like:

from TheSecondAppMainModule import TheSecondAppMainFrame

frame = TheSecondAppMainFrame(None, -1, ...)
frame.Show()

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Thanks for the response. I tried it with wx.Dialog, but couldn't make it
work. For some reason wx.Frame does though. I must have had a parameter in
there wrong before.

Thanks again,

Mike