Discussion:
Save states for restarts of wxPython GUI
acm
2014-03-11 01:47:34 UTC
Permalink
I'm designing a GUI application using wxPython and a sample version looks
like:

[image: Inline image 1]

*Note: A cell in my case is a collection of the cellnumber (the integer on
top left), variable 1 and variable 2*

I have designed this with MVC in mind. I have coded up the model as a state
machine. The user enters the cellnumber and the variable 1. This is passed
on to the model via an idle thread and that kicks off the state machine
which does the processing and returns the result.

*The following is a snippet of the model:*

class Infoaboutcell(): #This has all the information about each cell like
(cell number, variable 1 , variable 2 etc)
def __init__(self, cellNumber):
self.cellNo = cellNumber
self.variable1 = ""
....
def poll()
statemachine[state](cellnumber, variable1) #statemachine is a
dictionary with a state to function mapping and the functions are

#independent (do not belong to any
class)

class Model(): #this creates a list of all the cells
listofcells = []
for i in some range:
listofcells.append(infoaboutcell(i))

def function1(cellnumber, variable1):...
def function2(cellnumber, variable1): ...

*In the controller I have the following:*

class controller(Thread):
def __init__(self):
Thread.__init__(self)
self.start()

def run(self):
for i in Model.listofcells:
i.poll()

My question is how do I save the state and recover. For example, some
processes take a long time to get over and if accidentally someone closes
the app, when someone turns the app back up again, I want to start from
where I left off. In the sense, the state machine should resume the state
and the display should also go back to what it was before the exit and
continue from there. I tried checking the return value of the function and
based on that I pickled the class model (class Model()).

Can someone let me know how to do this? How do I save program state and
restore?
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Werner
2014-03-11 07:36:12 UTC
Permalink
On 11/03/2014 02:47, acm wrote:

...
Post by acm
My question is how do I save the state and recover. For example, some
processes take a long time to get over and if accidentally someone
closes the app, when someone turns the app back up again, I want to
start from where I left off. In the sense, the state machine should
resume the state and the display should also go back to what it was
before the exit and continue from there. I tried checking the return
value of the function and based on that I pickled the class model
(class Model()).
Can someone let me know how to do this? How do I save program state
and restore?
Have a look at wx.lib.agw.persist, check out the wxPython demo
"PersistentControls".

Werner
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
acm
2014-03-11 18:05:34 UTC
Permalink
Werner,

Thank you for the reply. I'm still confused as to how to save the state of
the model.
Post by acm
...
My question is how do I save the state and recover. For example, some
processes take a long time to get over and if accidentally someone closes
the app, when someone turns the app back up again, I want to start from
where I left off. In the sense, the state machine should resume the state
and the display should also go back to what it was before the exit and
continue from there. I tried checking the return value of the function and
based on that I pickled the class model (class Model()).
Can someone let me know how to do this? How do I save program state and
restore?
Have a look at wx.lib.agw.persist, check out the wxPython demo
"PersistentControls".
Werner
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Werner
2014-03-12 07:43:36 UTC
Permalink
Hi,
Post by acm
Werner,
Thank you for the reply. I'm still confused as to how to save the
state of the model.
Hhm, my model stuff is coming out of a database, so that is one why.

If you don't work with a database then maybe Python's pickle might be an
option, haven't used it much myself.

http://docs.python.org/2/library/pickle.html

Werner
--
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxPython-dev+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...