Hi all,
let’s me explain my scenario.
I have multiple standalone applications, each with its own mainloop and, if I run them separately, it’s all ok.
I would like to create a “central window” (in a new file), with a button for each application, in order to run the selected code in a separate window.
If I do this by executing something like os.system(“python app1/app1.py”) it works well, but I don’t like this way (it isn’t so elegant).
I would like to import each app as a module and then run run it from its “internal” function.
Anyway I know it is not possible to have multiple mainloops in one running script.
If I do this, in fact, I get the app window, but then all is freezed (and I think it’s “normal”, since it isn’t the right way to do this).
Do you have any tips about that?
Thanks.
Robert
Take a look at the menu system for wxPython. That is how it works.
···
On Fri, Nov 11, 2016 at 6:02 AM, robert.pelson1@gmail.com wrote:
Hi all,
let’s me explain my scenario.
I have multiple standalone applications, each with its own mainloop and, if I run them separately, it’s all ok.
I would like to create a “central window” (in a new file), with a button for each application, in order to run the selected code in a separate window.
If I do this by executing something like os.system(“python app1/app1.py”) it works well, but I don’t like this way (it isn’t so elegant).
I would like to import each app as a module and then run run it from its “internal” function.
Anyway I know it is not possible to have multiple mainloops in one running script.
If I do this, in fact, I get the app window, but then all is freezed (and I think it’s “normal”, since it isn’t the right way to do this).
Do you have any tips about that?
Thanks.
Robert
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for replying!
I did as you suggested:
I get the window but then it’s all freezed.
It looks like the events are not “transmitted back”.
Here there is my code:
import wx
class InitialMenu(wx.Dialog):
def init(self, parent, id, title):
wx.Dialog.init(self, parent, id, title, size=(300, 200))
self.colour = wx.Colour(0, 0, 0)
sorter_btn = wx.Button(self, 1, 'App1', (115, 25))
sorter_btn.Bind(wx.EVT_BUTTON, self.onApp1Button)
viewer_btn = wx.Button(self, 2, 'App2', (115, 80))
viewer_btn.Bind(wx.EVT_BUTTON, self.onApp2Button)
self.Centre()
self.ShowModal()
self.Destroy()
def onApp1Button(self, event):
print("Starting App1!")
import app1
app1_frame = app1.createFrame(None, -1, "App1", size=(500, 500)) # it is a 'class createFrame(wx.Frame)'
app1_frame.Show()
def onApp2Button(self, event):
""" For now just print a message"""
print("Starting App2!")
app = wx.App(False)
InitialMenu(None, -1, ‘Select app’)
app.MainLoop()
``
Any idea?
Thanks again!
Robert
···
Il giorno venerdì 11 novembre 2016 17:33:33 UTC+1, Matt Newville ha scritto:
Robert,
On Fri, Nov 11, 2016 at 8:02 AM, robert....@gmail.com wrote:
Hi all,
let’s me explain my scenario.
I have multiple standalone applications, each with its own mainloop and, if I run them separately, it’s all ok.
I would like to create a “central window” (in a new file), with a button for each application, in order to run the selected code in a separate window.
If I do this by executing something like os.system(“python app1/app1.py”) it works well, but I don’t like this way (it isn’t so elegant).
I would like to import each app as a module and then run run it from its “internal” function.
Anyway I know it is not possible to have multiple mainloops in one running script.
If I do this, in fact, I get the app window, but then all is freezed (and I think it’s “normal”, since it isn’t the right way to do this).
Do you have any tips about that?
Thanks.
Robert
The way I handle this is to use a single wx.App (your “central window”), but then create and show instances of wx.Frames that correspond to the daughter apps. That is, if the wx.App for each of your applications is simply creating and showing a wx.Frame instance, then your single global application ought to be able to create and show instances of those wx.Frames when needed too, without making a separate wx.App.
There can sometimes be slightly tricky things to handle, such as what “EVT_CLOSE” is meant to do, but I find that having wx.Frames that can be created and destroyed independently is better anyway.
I don’t know if that approach would work for you,
–Matt Newville
Yes. Do you understand why? You are creating a modal dialog box. Your call to self.ShowModal() will not return until the dialog closes, so by the time you get around to calling app.MainLoop, the main window is gone. Without the main loop, there's nobody who can process the messages for the other frame.
You either need to make this a modeless dialog, or use a wx.Frame for the main program.
···
On Nov 12, 2016, at 8:54 AM, robert.pelson1@gmail.com wrote:
Thanks for replying!
I did as you suggested:
I get the window but then it's all freezed.
It looks like the events are not "transmitted back".
—
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Thanks!
Yes, now the “main widnow” is a frame and it works.
I have just a litte problem:
when I close the app1 window, also the “main window” is closed.
The app1 window is not a main window’s child (at least I didn’nt set) so, as far as I know, the close event should not be propagated until the main window.
Am I wrong?
Thanks a lot!
Robert
···
Il giorno domenica 13 novembre 2016 05:11:36 UTC+1, Tim Roberts ha scritto:
On Nov 12, 2016, at 8:54 AM, robert....@gmail.com wrote:
Thanks for replying!
I did as you suggested:
I get the window but then it’s all freezed.
It looks like the events are not “transmitted back”.
Yes. Do you understand why? You are creating a modal dialog box. Your call to self.ShowModal() will not return until the dialog closes, so by the time you get around to calling app.MainLoop, the main window is gone. Without the main loop, there’s nobody who can process the messages for the other frame.
You either need to make this a modeless dialog, or use a wx.Frame for the main program.
—
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
You haven't shown us the code in "app1", but as I understand it, this
was it's own application. Remember that "import" will essentially
execute the whole file. Are you creating yet another instance of wx.App
and starting another main loop? If you don't have that stuff inside an
'if __name__=="__main__" ' statement, that could be the issue.
···
robert.pelson1@gmail.com wrote:
Yes, now the "main widnow" is a frame and it works.
I have just a litte problem:
when I close the app1 window, also the "main window" is closed.
The app1 window is not a main window's child (at least I didn'nt set)
so, as far as I know, the close event should not be propagated until
the main window.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Thanks for the tips!
I fixed the problem 
Basically I didn’t manage the EVT_CLOSE…I did it and it works now!
I have some other little points, but in case I’ll open a separate discussion on that.
Thank you very much!
Robert
···
Il giorno lunedì 14 novembre 2016 17:27:32 UTC+1, Tim Roberts ha scritto:
robert....@gmail.com wrote:
Yes, now the “main widnow” is a frame and it works.
I have just a litte problem:
when I close the app1 window, also the “main window” is closed.
The app1 window is not a main window’s child (at least I didn’nt set)
so, as far as I know, the close event should not be propagated until
the main window.
You haven’t shown us the code in “app1”, but as I understand it, this
was it’s own application. Remember that “import” will essentially
execute the whole file. Are you creating yet another instance of wx.App
and starting another main loop? If you don’t have that stuff inside an
'if name==“main” ’ statement, that could be the issue.
–
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.