Idle thread (Polling) python GUI and saving program state

MRAB python at mrabarnett.plus.com
Tue Mar 4 14:19:54 CET 2014


On 2014-03-04 02:41, Rolando wrote:> On Monday, March 3, 2014 6:06:22 PM 
UTC-8, MRAB wrote:
 >> On 2014-03-04 01:33, Rolando wrote:
 >>  > I have a GUI with a bunch of cells which is my "View" in the MVC
 >>  > design. The user enters some information in the view and I pass
 >>  > this on to the model so that using the information entered by
 >>  > the user it(model) can do some processing.
 >>  >
 >>  > I have coded up my model as a state machine. Wherein, once a
 >>  > function is complete it switches to the next state and so on.
 >>  >
 >>  > I want to know how do I save the program state between restarts.
 >>  > Basically, I'm trying to handle a scenario wherein if someone
 >>  > closes the program. The next time someone starts it up, it
 >>  > should start from where it left off (both the view and model)
 >>  >
 >> When the user closes the window (you don't say what you're using for
 >> the GUI, but there should be a way of detecting when window closes),
 >> save the necessary info to a file using, say, the 'json' module. You
 >> can then reload the info from the file when the program is
 >< restarted.
 >>
 >>  > Also, I want to setup a poll method where once in a while I can
 >>  > poll each cell to know the state it is in. How do I do this? I
 >>  > don't want my GUI to hang when I'm doing anything. It will be
 >>  > great if someone could help. Thanks!
 >>  >
 >> Can the model run continuously? If so, you should run it in its own
 >> (background) thread and the GUI in the main thread and communicate
 >> with the model's thread via, say, a queue (for that use the 'queue'
 >> module).
 >
 > I'm using wxPython for my GUI. I have tried running the model thread 
in the background. But how will I save the state if the whole model is 
running on a thread? When the program is restarted I want the program to 
continue from the same state where it left off for each cell. I was 
thinking of having an idle thread that calls a poll method which polls 
all the cells and checks what each one is doing. But, I don't know how 
to do that. I'm confused.
 >
Please read this:

https://wiki.python.org/moin/GoogleGroupsPython

because Gmail is formatting your email badly, making it harder to read.


When the front-end wants to quit, it tells the back-end and then waits
for it to terminate before itself quitting.

When the back-end receives the message that it should quit, it saves
its state and terminates.

When the front-end starts up again, it starts the back-end.

When the back-end starts, it load the state and runs.




More information about the Python-list mailing list