Multiple GUIs from a central one

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple GUIs from a central one

robert.pelson1
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

johnf
Take a look at the menu system for wxPython.  That is how it works.

On Fri, Nov 11, 2016 at 6:02 AM, <[hidden email]> 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

Matt Newville
In reply to this post by robert.pelson1
Robert,


On Fri, Nov 11, 2016 at 8:02 AM, <[hidden email]> 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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

robert.pelson1
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, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ZBHXIYmrAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">robert....@...> 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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

Tim Roberts
On Nov 12, 2016, at 8:54 AM, [hidden email] 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, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

robert.pelson1
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, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Zv3gOzUgAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">robert....@... 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, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Zv3gOzUgAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

Tim Roberts
[hidden email] 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, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple GUIs from a central one

robert.pelson1
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:
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="U63LjvKWAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">robert....@... 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, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="U63LjvKWAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ti...@...
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.