Calling a GUI application from another

Hello,

I am creating a project with wxpython for gui. In one program, I am calling another program, which is executed correctly, but the first one freezes/crashes.

First program: Login.py

Second program: Register.py

Now, when login.py is running, and I call Register.py, Register.py is executed correctly. Now, I want the login window to remain alive, so I am not Destroy()ing it.

But as soon as the Register.py is closed (after successful registration), the Login.py gets freezed and I get the python.exe has stopped working message.

The code for login.py is as attached in loginScreen.py

the code for register is as attached in regi_wit_db.py

(Should I also attach other files as well? There are total 8 .py files used in my project)

I have a welcome screen before the login screen, but it has no problems so far.

Also, when I am calling another screen, mainscreen.py in the code, the login screen is supposed to get destroyed, but Destroy() doesn’t work in this case.

I searched on stackoverflow and some other groups, and I got the idea of using the Datadeck() and run() as in:

def run():

app = DataDeck(1)

app.SetAppName(“LoginScreen”)

app.MainLoop()

class DataDeck(wx.App):

def OnInit(self):

frame=LoginDialog(parent=None,id=-1)

frame.Show()

self.SetTopWindow(frame)

return True

if name == ‘main’:

app=DataDeck()

app.MainLoop()

This works when login is the first screen to be executed and the mainscreen.py is called and executed correctly. But if I call it from welcome.py, the program crashes on every event in mainscreen. No problem for the register screen though.

I thought that maybe the problem would be in how I am calling the different .py files, so I tried using execfile() but it has a completely different way of execution and I had to provide each variable explicitly for every function, even if they belonged to same class.

So I finally settled on import subprocess solution as in the attached files, which works, again, like above run() code: if a program A is run as first executing program, it works, but if the same program A is called from another program B, it crashes after another program C is called from this program A .

There is a similar problem for all my other gui screens as well. In one such screen, i can write data to database successfully, but the application crashes.(when that specific event is triggered)

The frustrating part is that the subprocess solution worked without error when i first tried it, but after 2 days (without even touching the code) the programs have begun crashing :frowning:

This problem also occurs on another machine too, btw.

Just in case, here are the specs of my machine

OS: Win 8

Python: 2.7

wxpython: 2.7

IDE: IDLE

I am also using some other connectors and libraries for the project, like xgoogle, wikipedia, MySQLdb

I understand that my limited knowledge of wxpython might be the cause, but please guide me where I am going wrong.

Thanks and regards,

Udgam Mehetre

regi_wit_db.py (6.61 KB)

loginScreen.py (2.9 KB)

Sorry,

I bit too much to figure out the chain of events in all this, but:

You can only have 1 instance of a wx.App in a process. And you can only initialize it once.

So I’m not entirely sure what you goals are here, but if you want “one program, [to call] another program”, then each program should be in a separate python process, and you can call one from the other with the subprocess module or some such. Which will require a bit of work on the inter-process communication if it’s less than trivial.

But from your names: “loginScreen”, for insance, I supet you don’t actually want more than one program. what you want is one program, but with various views on it – the liogin screen, maybe more than one “main frame” depending on what the user is doing. In which case, that’s not hard:

have one wx.App

have more than one top-level frame, dialog, etc.

at start-up, you can instantiate and Show()only the one you want (the login screen?), then when the user needs to do somethign else, a method in the App object can instantiate and show whichever other frame is needed, etc…

If you have a flow like:

show login screen

user logs in, and selects what they want to do

login screen goes away, and new taop-level frame pops up for user.

you may want to use wx.CallAfter() in the login screen to call a method on the App object that brings up the new frame, and destroys the login screen. The CallAfter will allow the destroy to happen AFTER the user is done with the login screen.

HTH,

-Chris

···

On Sat, Apr 26, 2014 at 9:07 AM, Udgam Mehetre uvmgr8@gmail.com wrote:

Hello,

I am creating a project with wxpython for gui. In one program, I am calling another program, which is executed correctly, but the first one freezes/crashes.

First program: Login.py

Second program: Register.py

Now, when login.py is running, and I call Register.py, Register.py is executed correctly. Now, I want the login window to remain alive, so I am not Destroy()ing it.

But as soon as the Register.py is closed (after successful registration), the Login.py gets freezed and I get the python.exe has stopped working message.

The code for login.py is as attached in loginScreen.py

the code for register is as attached in regi_wit_db.py

(Should I also attach other files as well? There are total 8 .py files used in my project)

I have a welcome screen before the login screen, but it has no problems so far.

Also, when I am calling another screen, mainscreen.py in the code, the login screen is supposed to get destroyed, but Destroy() doesn’t work in this case.

I searched on stackoverflow and some other groups, and I got the idea of using the Datadeck() and run() as in:

def run():

app = DataDeck(1)

app.SetAppName(“LoginScreen”)

app.MainLoop()

class DataDeck(wx.App):

def OnInit(self):

frame=LoginDialog(parent=None,id=-1)

frame.Show()

self.SetTopWindow(frame)

return True

if name == ‘main’:

app=DataDeck()

app.MainLoop()

This works when login is the first screen to be executed and the mainscreen.py is called and executed correctly. But if I call it from welcome.py, the program crashes on every event in mainscreen. No problem for the register screen though.

I thought that maybe the problem would be in how I am calling the different .py files, so I tried using execfile() but it has a completely different way of execution and I had to provide each variable explicitly for every function, even if they belonged to same class.

So I finally settled on import subprocess solution as in the attached files, which works, again, like above run() code: if a program A is run as first executing program, it works, but if the same program A is called from another program B, it crashes after another program C is called from this program A .

There is a similar problem for all my other gui screens as well. In one such screen, i can write data to database successfully, but the application crashes.(when that specific event is triggered)

The frustrating part is that the subprocess solution worked without error when i first tried it, but after 2 days (without even touching the code) the programs have begun crashing :frowning:

This problem also occurs on another machine too, btw.

Just in case, here are the specs of my machine

OS: Win 8

Python: 2.7

wxpython: 2.7

IDE: IDLE

I am also using some other connectors and libraries for the project, like xgoogle, wikipedia, MySQLdb

I understand that my limited knowledge of wxpython might be the cause, but please guide me where I am going wrong.

Thanks and regards,

Udgam Mehetre

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.

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

Thanks for the response!

I have only one class per python program, so every file implements one frame/dialog window. So, when user clicks on login or logs in, the login frame must close and next frame should open. To do this, I am calling the next screen from login screen from a button event in login screen. This ‘calling’ part however is the problem.

I didnt want to complicate the program for later debugging, so I wrote every class in a new program.

From your suggestion, should i instead have multiple frames in one program itself?

Thanks again,

Udgam Mehetre

···

On 28 April 2014 01:17, Chris Barker chris.barker@noaa.gov wrote:

Sorry,

I bit too much to figure out the chain of events in all this, but:

You can only have 1 instance of a wx.App in a process. And you can only initialize it once.

So I’m not entirely sure what you goals are here, but if you want “one program, [to call] another program”, then each program should be in a separate python process, and you can call one from the other with the subprocess module or some such. Which will require a bit of work on the inter-process communication if it’s less than trivial.

But from your names: “loginScreen”, for insance, I supet you don’t actually want more than one program. what you want is one program, but with various views on it – the liogin screen, maybe more than one “main frame” depending on what the user is doing. In which case, that’s not hard:

have one wx.App

have more than one top-level frame, dialog, etc.

at start-up, you can instantiate and Show()only the one you want (the login screen?), then when the user needs to do somethign else, a method in the App object can instantiate and show whichever other frame is needed, etc…

If you have a flow like:

show login screen

user logs in, and selects what they want to do

login screen goes away, and new taop-level frame pops up for user.

you may want to use wx.CallAfter() in the login screen to call a method on the App object that brings up the new frame, and destroys the login screen. The CallAfter will allow the destroy to happen AFTER the user is done with the login screen.

HTH,

-Chris

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/wb1CWVh34D4/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


Udgam Mehetre

" *Imagination is the only weapon in the war against reality.*"

On Sat, Apr 26, 2014 at 9:07 AM, Udgam Mehetre uvmgr8@gmail.com wrote:

Hello,

I am creating a project with wxpython for gui. In one program, I am calling another program, which is executed correctly, but the first one freezes/crashes.

First program: Login.py

Second program: Register.py

Now, when login.py is running, and I call Register.py, Register.py is executed correctly. Now, I want the login window to remain alive, so I am not Destroy()ing it.

But as soon as the Register.py is closed (after successful registration), the Login.py gets freezed and I get the python.exe has stopped working message.

The code for login.py is as attached in loginScreen.py

the code for register is as attached in regi_wit_db.py

(Should I also attach other files as well? There are total 8 .py files used in my project)

I have a welcome screen before the login screen, but it has no problems so far.

Also, when I am calling another screen, mainscreen.py in the code, the login screen is supposed to get destroyed, but Destroy() doesn’t work in this case.

I searched on stackoverflow and some other groups, and I got the idea of using the Datadeck() and run() as in:

def run():

app = DataDeck(1)

app.SetAppName(“LoginScreen”)

app.MainLoop()

class DataDeck(wx.App):

def OnInit(self):

frame=LoginDialog(parent=None,id=-1)

frame.Show()

self.SetTopWindow(frame)

return True

if name == ‘main’:

app=DataDeck()

app.MainLoop()

This works when login is the first screen to be executed and the mainscreen.py is called and executed correctly. But if I call it from welcome.py, the program crashes on every event in mainscreen. No problem for the register screen though.

I thought that maybe the problem would be in how I am calling the different .py files, so I tried using execfile() but it has a completely different way of execution and I had to provide each variable explicitly for every function, even if they belonged to same class.

So I finally settled on import subprocess solution as in the attached files, which works, again, like above run() code: if a program A is run as first executing program, it works, but if the same program A is called from another program B, it crashes after another program C is called from this program A .

There is a similar problem for all my other gui screens as well. In one such screen, i can write data to database successfully, but the application crashes.(when that specific event is triggered)

The frustrating part is that the subprocess solution worked without error when i first tried it, but after 2 days (without even touching the code) the programs have begun crashing :frowning:

This problem also occurs on another machine too, btw.

Just in case, here are the specs of my machine

OS: Win 8

Python: 2.7

wxpython: 2.7

IDE: IDLE

I am also using some other connectors and libraries for the project, like xgoogle, wikipedia, MySQLdb

I understand that my limited knowledge of wxpython might be the cause, but please guide me where I am going wrong.

Thanks and regards,

Udgam Mehetre

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 wxpython-users+unsubscribe@googlegroups.com.

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

Hi,

Thanks for the response!

I have only one class per python program, so every file implements one frame/dialog window.

That is very good.

So, when user clicks on login or logs in, the login frame must close and next frame should open. To do this, I am calling the next screen from login screen from a button event in login screen. This 'calling' part however is the problem.

Within your 'main application', maybe your login you would 'import theotherframe' and then show it.

I didnt want to complicate the program for later debugging, so I wrote every class in a new program.

You mean every class in a new file/module?

From your suggestion, should i instead have multiple frames in one program itself?

I don't think that is what Chris meant, it would be more along the line of:

- mainapp.py
- login.py
- mainframe.py
- anotherframe.py

In mainapp.py you load the wx.App and show e.g. the login dialog when user logs in successfully you show the mainframe when he/she is done with it you can show the anotherframe and so on.

I hope this helps and doesn't add to the confusion:-) .

Werner

···

On 4/28/2014 10:38, uvmgr8 wrote:

In mainapp.py you load the wx.App and show e.g. the login dialog when user logs in successfully you show the mainframe when he/she is done with it you can show the anotherframe and so on.
Aha! Thats a good one!

So I should just start the mainapp.py, and the flow of execution will execute other files

But a plain import statement would be enough?

I used something like this:

login.py> def toMain(self,event):

                      import mainscreen

                      mainscreen.run()

mainscreen.py>

def run():

app = DataDeck(1)

app.SetAppName(“LoginScreen”)

app.MainLoop()

class DataDeck(wx.App):

def OnInit(self):

frame=LoginDialog(parent=None,id=-1)

frame.Show()

self.SetTopWindow(frame)

return True

if name == ‘main’:

app=DataDeck()

app.MainLoop()

It works, but sometimes I get a ‘python.exe has stopped working’ message and program crashes. That’s why, I thought there must be a better way to do this

I had not tried the solution you said, so I’ll check it out

Thanks,

Udgam Mehetre

···

On 28 April 2014 14:20, Werner wernerfbd@gmx.ch wrote:

Hi,

On 4/28/2014 10:38, uvmgr8 wrote:

Thanks for the response!

I have only one class per python program, so every file implements one frame/dialog window.

That is very good.

So, when user clicks on login or logs in, the login frame must close and next frame should open. To do this, I am calling the next screen from login screen from a button event in login screen. This ‘calling’ part however is the problem.

Within your ‘main application’, maybe your login you would ‘import theotherframe’ and then show it.

I didnt want to complicate the program for later debugging, so I wrote every class in a new program.

You mean every class in a new file/module?

From your suggestion, should i instead have multiple frames in one program itself?

I don’t think that is what Chris meant, it would be more along the line of:

  • mainapp.py

  • login.py

  • mainframe.py

  • anotherframe.py

In mainapp.py you load the wx.App and show e.g. the login dialog when user logs in successfully you show the mainframe when he/she is done with it you can show the anotherframe and so on.

I hope this helps and doesn’t add to the confusion:-) .

Werner

You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.

To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/wb1CWVh34D4/unsubscribe.

To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


Udgam Mehetre

" *Imagination is the only weapon in the war against reality.*"

Hi,

>>In mainapp.py you load the wx.App and show e.g. the login dialog when user logs in successfully you show the mainframe when he/she is done with it you can show the anotherframe and so on.
Aha! Thats a good one!

So I should just start the mainapp.py, and the flow of execution will execute other files
But a plain import statement would be enough?

Yes.

I used something like this:

login.py> def toMain(self,event):
import mainscreen
mainscreen.run()

but mainscreen.run should not create an app as I assume login.py has already done that, it should just do what is needed to show it.

Maybe have a look at a sample application Mike and I did sometimes ago - MediaLocker - https://bitbucket.org/driscollis/medialocker

In there runapp.py is the 'mainapp' and it creates the wx.App (which is in the module BaseApp), then the mainFrame is in mediaLocker.MediaLocker which in turn calls different dialogs (they could be frames or other top level windows).

Werner

···

On 4/28/2014 11:31, uvmgr8 wrote:

So I should just start the mainapp.py, and the flow of execution will
execute other files
But a plain import statement would be enough?

Yes.

                                      mainscreen.run()

but mainscreen.run should not create an app as I assume login.py has
already done that, it should just do what is needed to show it.

yup - I think there is some confusion in terminology here (and what a
python module is):

A "program" is a single process -- in this case, a single python process.
You can only have one wx.App in a single program.

A "module" is a single python (*.py) file, which, when imported, becomes a
module object (namespace).

A python program consists of a python module (with __name__ == "__main__")
That begins execution. This module can import any number of other python
modules (recursively).

A wxPython program contains a SINGLE wx.App object -- usually initialized
in the main python file, but in any case, wx.App should only be called in
one place in _all_ the modules your program uses.

A wxPython program can have more than one top level window (Frames and
Dialogs), your app can create and destroy and show and hide these as the
app requires.

For good code management, it is a good idea to keep separate parts of your
program in separate modules -- one module per frame, for instance, and
separate modules for the program logic.

In your example, I'm pretty sure you want one program, i.e. one wx.App,
with multiple top level frames that are shown and hidden as needed (or
maybe created and shown when needed)

for test purposes, you could put wx.App creation code in a "if __name__ ==
"__main__" clause in each module that creates a frame, but that code should
not be run when the module is imported.

Maybe have a look at a sample application Mike and I did sometimes ago -
MediaLocker - https://bitbucket.org/driscollis/medialocker

indeed, and example will probably make this all more clear.

-Chris

···

On Mon, Apr 28, 2014 at 2:43 AM, Werner <wernerfbd@gmx.ch> wrote:

--

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

I see in regi_wit_db.py in run() you create a new wx.App() instance and in loginScreen.py within it’s global namespace you create a newe wx.App() instance.

There are many ways to rework this.

A. have a launcher.py that is the only place that creates a wx.App and import all your frames there and show them.

B or in each Python module file use the If name == “main”:

app = wx.GetApp()

if app is None: app = MyApp() and go from there

For purity; I’d keep the app.MainLoop() in one place. However there is this:

if app is not None and not app.IsMainLoopRunning(): app.MainLoop()

Like others have said if you put the splashscreen, login and mainapp in separate sub-processes you have to code all that Inter-process Communication between the login and mainapp.

Side note. In loginScreen.py there seems some potential for you app to “block” within validate() method. If your user base is small no biggy. But if your userbase is public internet you have the potential for bots to fill your database with lots of user records. Could generate a lot of db lookups over and over.

One of your requirements stumps me. Why does the login screen need to remain visible?

Also: in loginScreen.py tomainScreen() method you have event.Skip() Where is that method getting event? You probably don’t need that there for a non-event handler. usually you see event.Skip with in a method like def OnButtonClick(self, event): event.Skip() when you want to pass that to the wxwidget’s parent.

···

On Mon, Apr 28, 2014 at 2:32 PM, Chris Barker chris.barker@noaa.gov wrote:


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.

On Mon, Apr 28, 2014 at 2:43 AM, Werner wernerfbd@gmx.ch wrote:

        So I should just start the

mainapp.py, and the flow of execution will execute other
files

        But a plain import statement

would be enough?

Yes.

                                  mainscreen.run()
  but mainscreen.run should not create

an app as I assume login.py has already done that, it should just
do what is needed to show it.

yup - I think there is some confusion in terminology here (and what a python module is):

A “program” is a single process – in this case, a single python process. You can only have one wx.App in a single program.

A “module” is a single python (*.py) file, which, when imported, becomes a module object (namespace).

A python program consists of a python module (with name == “main”) That begins execution. This module can import any number of other python modules (recursively).

A wxPython program contains a SINGLE wx.App object – usually initialized in the main python file, but in any case, wx.App should only be called in one place in all the modules your program uses.

A wxPython program can have more than one top level window (Frames and Dialogs), your app can create and destroy and show and hide these as the app requires.

For good code management, it is a good idea to keep separate parts of your program in separate modules – one module per frame, for instance, and separate modules for the program logic.

In your example, I’m pretty sure you want one program, i.e. one wx.App, with multiple top level frames that are shown and hidden as needed (or maybe created and shown when needed)

for test purposes, you could put wx.App creation code in a "if name == “main” clause in each module that creates a frame, but that code should not be run when the module is imported.

  Maybe have a look at a sample application Mike and I did sometimes

ago - MediaLocker - https://bitbucket.org/driscollis/medialocker

indeed, and example will probably make this all more clear.

-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

BTW if you have several top level frames (multiple frames with None as
parent) and you hide all but one; then CLOSE the only visible top level
frame without showing any other frame will make your app appear to hang.
app.MainLoop() will not automatically stop while there are any top level
frames still "created", even if all of them are hidden (ie.
frame.Show(False))