Save states for restarts of wxPython GUI

I’m designing a GUI application using wxPython and a sample version looks like:

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?


Have a look at wx.lib.agw.persist, check out the wxPython demo
“PersistentControls”.
Werner

···

On 11/03/2014 02:47, acm wrote:

      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?

Werner,

Thank you for the reply. I’m still confused as to how to save the state of the model.

···

On Tuesday, March 11, 2014 12:36:12 AM UTC-7, werner wrote:

On 11/03/2014 02:47, acm wrote:

...
      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

Hi,

···

On 11/03/2014 19:05, acm wrote:

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