Dear wxpython-users,
I have a little questionnaire-like app that I use in an experimental
setting. Participants type in their choices, then when they are done I
would like to have a button able to restart it - i.e. to re-run the
whole python script.
What I did, and it worked in a simple setting, is to have a last
screen with a button bound to a method that first Destroy()s the frame
itself and then calls execfile('namefile.py'). This worked in a simple
trial setting, an app with an empty frame.
In a more complex settings, an app made up of different frames that
get called one after the other, it does not properly work.
Let's say we are at the end of Run #1. On clicking, the last frame is
destroyed, Run #2 starts, and Frame #1 is displayed. But when clicking
on to access frame #2, this is not there - wxpyton complains it cannot
access a deleted object.
It is as if the app did not really restart - in some ways it looks as
if I am always trapped in the mainloop.
Anyone knows of easier ways of 'restarting' the app from within?
Thanks!
Paolo
Why are you restarting it? Just save the information and rest all the widgets to their defaults. You can iterate over them using widgets = self.GetChildren() and then just clear them or whatever.
···
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Why not simply spawn/popen a new copy of the application with the
apropriate options set on the command line and exit the current copy of
the application? That would seem to do exactly what you need.
Gadget/Steve
···
On 21/11/2011 9:49 PM, Paolo Crosetto wrote:
Dear wxpython-users,
I have a little questionnaire-like app that I use in an experimental
setting. Participants type in their choices, then when they are done I
would like to have a button able to restart it - i.e. to re-run the
whole python script.
What I did, and it worked in a simple setting, is to have a last
screen with a button bound to a method that first Destroy()s the frame
itself and then calls execfile('namefile.py'). This worked in a simple
trial setting, an app with an empty frame.
In a more complex settings, an app made up of different frames that
get called one after the other, it does not properly work.
Let's say we are at the end of Run #1. On clicking, the last frame is
destroyed, Run #2 starts, and Frame #1 is displayed. But when clicking
on to access frame #2, this is not there - wxpyton complains it cannot
access a deleted object.
It is as if the app did not really restart - in some ways it looks as
if I am always trapped in the mainloop.
Anyone knows of easier ways of 'restarting' the app from within?
Thanks!
Paolo
Following some advice given, here is a crude example. See attached.
WizardApp.py (4.48 KB)
Thanks all for the answers.
Thanks Dev for the example, it is _very_ much appreciated. Since I
have lots of things to reset and not much time, though, I will keep
the nice suggestions for the next experiment-survey.
In the end I solved the problem sort of the Gadget/Steve way - by
opening a new instance of the application. It actually was much easier
than I thought once I decided to get out of python and to do it from
shell. I have a "while 1: do python nameapp.py done" little bash
script, and that ensures that when the app is closed, another one is
directly created; it serves my purpose an it's dead easy.
Thanks!