[snip]
Thanks, Kevin. Very useful information as always!
We you say "roll your own" I assume you mean the logic necessary to
capture each control in my particular UI.
But if we all have this need, it seems like something generic could be
provided. At a high level, I'm thinking of mix-in Python methods added
to classes like wxWindow[Ptr?] that save and load their state and pass
the message to what they contain. Something like the following
Python/pseudo code:
mix-ins to wxWindow:
def saveStateDict(self):
dict = {}
self.saveState(dict)
for child in self.saveStateChildren():
dict[child.saveStateIdentifier()] = child.saveStateDict()
return dict
def saveState(self, dict):
""" Subclasses must override if any state needs to be preserved
between UI sessions. """
pass
def saveStateIdentifier(self):
return self.GetID()
def saveStateChildren(self):
""" Subclasses can override to customize what children get their
state saved. """
return self.GetChildren()
Example for wxFrame:
def saveState(self, dict):
SuperClass.saveState(self, dict)
dict['size'] = self.size
dict['pos'] = self.position
You can imagine the corresponding readState() methods and more specifics
for things like splitters, notebooks, etc. This kind of thing is what I
was looking for in the first place.
The dict could be stored as-is in any file, or we could even write a
util to push a dict into wxConfig as groups and entries.
Does this make sense? Has anyone done this already?
···
On Friday 04 April 2003 03:01 pm, Kevin Altis wrote:
> From: Vaclav Slavik [mailto:vaclav.slavik@matfyz.cz]
>
> Chuck Esterbrook wrote:
> > Is there a recommended approach and/or library calls for this
> > purpose?
>
> You have to get the state manually and save it using wxConfig
> class.
Or just roll your own loadConfig, saveConfig based on ConfigParser or
equivelant in Python. PythonCard does this for a variety of the
samples and tools.
The only tricky part was keeping track of the last window position
and size prior to a minimize (iconize) since that will screw up the
numbers you get back from wxWindows if you try and just read them on
program exit when you do a saveConfig. So, you bind the iconize
event, save the state prior to the minimize and then read the
restored position and size back if required when you're ready to save
state.
--
Chuck
http://ChuckEsterbrook.com