[wxPython-users] Saving information from the GUI to a file

Andrea Gavana andrea.gavana at gmail.com
Tue Apr 3 04:17:26 PDT 2007


Hi,

On 4/3/07, jupan ghe wrote:
> I tried to used pickle to save the state of the objets but most of the time
> complained about not beeing possible to pickle the c++ objects.

No, you can't pickle wxPython controls or whatever is also loosely
linked to them. The approach you could take is the same I used for my
database GUI: separate the GUI from the model, i.e., adopt the MVC/MVP
approach, so that the Model doesn't know anything about the GUI (and
doesn't store pointers to the GUI widgets). Doing this, noting that my
models are quite big, I just do:

Model => cPickle => zlib.compress => b64encode => store in database

to reload a model, I just do the inverse procedure. The only thing you
should provide is a mechanism that "translates" from the model to the
GUI, but this is not a very complex task.

> I will try to look at SQLite and Firebird.

If you decide to look at databases, my suggestion is to use
SQLAlchemy, that has some kind of high-level communication (and very
good Python OO interface) to the most common databases (sqlite,
firebird, Oracle and so on). I use it together with sqlite (that comes
with Python 2.5) and it's working extremely well.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/




More information about the wxpython-users mailing list