|
|
|
|
@@ -10,7 +10,7 @@
|
|
|
|
|
# Python Code By:
|
|
|
|
|
#
|
|
|
|
|
# Andrea Gavana, @ 16 Nov 2009
|
|
|
|
|
# Latest Revision: 27 Dec 2012, 21.00 GMT
|
|
|
|
|
# Latest Revision: 17 Feb 2013, 21.00 GMT
|
|
|
|
|
#
|
|
|
|
|
# For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please
|
|
|
|
|
# Write To Me At:
|
|
|
|
|
@@ -56,7 +56,7 @@ class PersistentObject(object):
|
|
|
|
|
support for your common classes, see :ref:`persistent-windows` in the
|
|
|
|
|
`__init__.py` file.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, window, persistenceHandler=None):
|
|
|
|
|
"""
|
|
|
|
|
Default class constructor.
|
|
|
|
|
@@ -83,7 +83,7 @@ class PersistentObject(object):
|
|
|
|
|
self._persistentHandler = persistenceHandler(self)
|
|
|
|
|
else:
|
|
|
|
|
self._persistentHandler = FindHandler(self)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._name in BAD_DEFAULT_NAMES:
|
|
|
|
|
warnings.warn("Window names should not be defaulted! (class=%s, name=%s)"%(window.__class__, window.GetName()))
|
|
|
|
|
|
|
|
|
|
@@ -92,7 +92,7 @@ class PersistentObject(object):
|
|
|
|
|
"""
|
|
|
|
|
Returns the string uniquely identifying the window we're associated with
|
|
|
|
|
among all the other objects of the same type.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:note: This method is used together with :meth:`~PersistentObject.GetKind` to construct the unique
|
|
|
|
|
full name of the object in e.g. a configuration file.
|
|
|
|
|
"""
|
|
|
|
|
@@ -115,26 +115,26 @@ class PersistentObject(object):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return self._persistentHandler.GetKind()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Save(self):
|
|
|
|
|
"""
|
|
|
|
|
Saves the corresponding window settings.
|
|
|
|
|
Saves the corresponding window settings.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
This method shouldn't be used directly as it doesn't respect the
|
|
|
|
|
global :meth:`PersistenceManager.DisableSaving() <PersistenceManager.DisableSaving>` settings, use :class:`PersistenceManager`
|
|
|
|
|
methods with the same name instead.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
self._persistentHandler.Save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Restore(self):
|
|
|
|
|
"""
|
|
|
|
|
Restores the corresponding window settings.
|
|
|
|
|
Restores the corresponding window settings.
|
|
|
|
|
|
|
|
|
|
:note: This method shouldn't be used directly as it doesn't respect the
|
|
|
|
|
global :meth:`PersistenceManager.DisableRestoring() <PersistenceManager.DisableRestoring>` settings, use :class:`PersistenceManager`
|
|
|
|
|
@@ -147,13 +147,13 @@ class PersistentObject(object):
|
|
|
|
|
def SaveValue(self, name, value):
|
|
|
|
|
"""
|
|
|
|
|
Save the specified value using the given name.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param `name`: the name of the value in the configuration file;
|
|
|
|
|
:param `value`: the value to save.
|
|
|
|
|
|
|
|
|
|
:returns: ``True`` if the value was saved or ``False`` if an error occurred.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return PersistenceManager.Get().SaveValue(self, name, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -161,20 +161,20 @@ class PersistentObject(object):
|
|
|
|
|
"""
|
|
|
|
|
Save the specified value using the given name, should be used only for
|
|
|
|
|
controls data value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param `name`: the name of the value in the configuration file;
|
|
|
|
|
:param `value`: the value to save.
|
|
|
|
|
|
|
|
|
|
:returns: ``True`` if the value was saved or ``False`` if an error occurred.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return PersistenceManager.Get().SaveCtrlValue(self, name, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def RestoreValue(self, name):
|
|
|
|
|
"""
|
|
|
|
|
Restore the value saved by :meth:`~PersistentObject.SaveValue`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param `name`: the same name as was used by :meth:`~PersistentObject.SaveValue`.
|
|
|
|
|
|
|
|
|
|
:returns: ``True`` if the value was successfully read or ``False`` if
|
|
|
|
|
@@ -188,7 +188,7 @@ class PersistentObject(object):
|
|
|
|
|
"""
|
|
|
|
|
Restore the value saved by :meth:`~PersistentObject.SaveCtrlValue`, should be used only for
|
|
|
|
|
controls data value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param `name`: the same name as was used by :meth:`~PersistentObject.SaveCtrlValue`.
|
|
|
|
|
|
|
|
|
|
:returns: ``True`` if the value was successfully read or ``False`` if
|
|
|
|
|
@@ -213,7 +213,7 @@ class PersistenceManager(object):
|
|
|
|
|
This is a singleton class and its unique instance can be retrieved using
|
|
|
|
|
:meth:`PersistenceManager.Get() <PersistenceManager.Get>` method.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
"""
|
|
|
|
|
Default class constructor.
|
|
|
|
|
@@ -224,7 +224,7 @@ class PersistenceManager(object):
|
|
|
|
|
methods in this class.
|
|
|
|
|
|
|
|
|
|
Interesting attributes you can set for this class are:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- `configFile`: the persistent configuration file for :class:`PersistenceManager`,
|
|
|
|
|
a custom file name to which :class:`FileConfig` will access to store and
|
|
|
|
|
retrieve UI settings;
|
|
|
|
|
@@ -243,11 +243,11 @@ class PersistenceManager(object):
|
|
|
|
|
``PM_PERSIST_CONTROL_VALUE`` If set, control values will be persisted. This is handy for e.g. applications using a database, where the data (control value) is persisted in the database and persisting it with PM again would only cause confusion.
|
|
|
|
|
``PM_DEFAULT_STYLE`` Same as ``PM_SAVE_RESTORE_AUI_PERSPECTIVES``
|
|
|
|
|
======================================== ==================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:note: UI settings are stored as dictionaries key <=> tuple: the tuple value
|
|
|
|
|
contains two items. The first is the value *type* (i.e., float, int, bool etc...)
|
|
|
|
|
while the second is the actual key value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
object.__init__(self)
|
|
|
|
|
@@ -257,43 +257,43 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
# Specifies custom key in the wx.Config object to use
|
|
|
|
|
self._configKey = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Specifies whether a custom config handler exists, so that we will not use
|
|
|
|
|
# wx.FileConfig (i.e., ConfigObj, ConfigParser etc...)
|
|
|
|
|
self._customConfigHandler = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Specifies the PersistenceManager style
|
|
|
|
|
self._style = PM_DEFAULT_STYLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set these values to True if we should restore/save the settings (it doesn't
|
|
|
|
|
# make much sense to use this class when both of them are False but setting
|
|
|
|
|
# one of them to False may make sense in some situations)
|
|
|
|
|
self._doSave = True
|
|
|
|
|
self._doRestore = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Flag set to True when PersistenceManager has restored any window
|
|
|
|
|
self._hasRestored = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# map with the registered objects as keys and associated
|
|
|
|
|
# PersistentObjects as values
|
|
|
|
|
# PersistentObjects as values
|
|
|
|
|
self._persistentObjects = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Get(self):
|
|
|
|
|
""" Accessor to the unique persistence manager object. """
|
|
|
|
|
|
|
|
|
|
if not hasattr(self, "_instance"):
|
|
|
|
|
if not hasattr(self, "_instance"):
|
|
|
|
|
self._instance = PersistenceManager()
|
|
|
|
|
|
|
|
|
|
return self._instance
|
|
|
|
|
|
|
|
|
|
Get = classmethod(Get)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Free(self):
|
|
|
|
|
""" Destructor for the unique persistence manager object. """
|
|
|
|
|
|
|
|
|
|
if hasattr(self, "_instance"):
|
|
|
|
|
if hasattr(self, "_instance"):
|
|
|
|
|
del self._instance
|
|
|
|
|
|
|
|
|
|
Free = classmethod(Free)
|
|
|
|
|
@@ -305,8 +305,8 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
:see: :meth:`~PersistenceManager.SetManagerStyle` for a list of possible styles.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return self._style
|
|
|
|
|
|
|
|
|
|
return self._style
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def SetManagerStyle(self, style):
|
|
|
|
|
@@ -321,13 +321,13 @@ class PersistenceManager(object):
|
|
|
|
|
``PM_SAVE_RESTORE_AUI_PERSPECTIVES`` If a toplevel window has an AUI manager associated, the manager will save and restore its AUI perspective
|
|
|
|
|
``PM_SAVE_RESTORE_TREE_LIST_SELECTIONS`` If set, the manager will save items selections in list and tree controls
|
|
|
|
|
``PM_PERSIST_CONTROL_VALUE`` If set, control values will be persisted. This is handy for e.g. applications using a database, where the data (control value) is persisted in the database and persisting it with PM again would only cause confusion.
|
|
|
|
|
``PM_DEFAULT_STYLE`` Same as ``PM_SAVE_RESTORE_AUI_PERSPECTIVES``.
|
|
|
|
|
``PM_DEFAULT_STYLE`` Same as ``PM_SAVE_RESTORE_AUI_PERSPECTIVES``.
|
|
|
|
|
======================================== ==================================
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
self._style = style
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def SetPersistenceKey(self, key):
|
|
|
|
|
"""
|
|
|
|
|
Sets the persistent key name inside the configuration file for :class:`PersistenceManager`.
|
|
|
|
|
@@ -335,11 +335,11 @@ class PersistenceManager(object):
|
|
|
|
|
:param `key`: a short meaningful name for your unique preferences key.
|
|
|
|
|
|
|
|
|
|
:note: Calling this method has no influence if you are using your own
|
|
|
|
|
custom configuration handler (i.e., by using ConfigObj/ConfigParser/cPickle etc...).
|
|
|
|
|
custom configuration handler (i.e., by using ConfigObj/ConfigParser/cPickle etc...).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
self._configKey = key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetPersistenceKey(self):
|
|
|
|
|
"""
|
|
|
|
|
@@ -364,7 +364,7 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
self._configFile = fileName
|
|
|
|
|
self._persistentObjects = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetPersistenceFile(self):
|
|
|
|
|
"""
|
|
|
|
|
@@ -380,7 +380,7 @@ class PersistenceManager(object):
|
|
|
|
|
else:
|
|
|
|
|
persistenceDir = self.GetPersistenceDirectory()
|
|
|
|
|
fileName = "Persistence_Options"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileName = os.path.join(persistenceDir, fileName)
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(persistenceDir):
|
|
|
|
|
@@ -404,14 +404,14 @@ class PersistenceManager(object):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
self._customConfigHandler = handler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetConfigurationHandler(self):
|
|
|
|
|
"""
|
|
|
|
|
Returns the persistent configuration handler for :class:`PersistenceManager`.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return self._customConfigHandler
|
|
|
|
|
return self._customConfigHandler
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetPersistenceDirectory(self):
|
|
|
|
|
@@ -422,7 +422,7 @@ class PersistenceManager(object):
|
|
|
|
|
custom configuration handler (i.e., by using ConfigObj/ConfigParser/cPickle etc...)
|
|
|
|
|
or if you have specified a custom configuration file to use with :class:`FileConfig`.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sp = wx.StandardPaths.Get()
|
|
|
|
|
return sp.GetUserDataDir()
|
|
|
|
|
|
|
|
|
|
@@ -434,10 +434,12 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
:param `window`: an instance of :class:`Window`.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
if window.GetName() in self._persistentObjects:
|
|
|
|
|
return window
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if window:
|
|
|
|
|
# protect for PyDeadObjectError
|
|
|
|
|
if window.GetName() in self._persistentObjects:
|
|
|
|
|
return window
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Register(self, window, persistenceHandler=None):
|
|
|
|
|
"""
|
|
|
|
|
@@ -452,15 +454,15 @@ class PersistenceManager(object):
|
|
|
|
|
Note that registering the object doesn't do anything except allowing to call
|
|
|
|
|
:meth:`~PersistenceManager.Restore` for it later. If you want to register the object and restore its
|
|
|
|
|
properties, use :meth:`~PersistenceManager.RegisterAndRestore`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
The manager takes ownership of the :class:`PersistentObject` and will delete it when
|
|
|
|
|
it is unregistered.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.Find(window):
|
|
|
|
|
raise Exception("Object (class=%s, name=%s) is already registered"%(window.__class__, window.GetName()))
|
|
|
|
|
|
|
|
|
|
@@ -468,7 +470,7 @@ class PersistenceManager(object):
|
|
|
|
|
self._persistentObjects[name] = PersistentObject(window, persistenceHandler)
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Unregister(self, window):
|
|
|
|
|
"""
|
|
|
|
|
@@ -482,10 +484,10 @@ class PersistenceManager(object):
|
|
|
|
|
when the window is destroyed so you only need to call this function explicitly if you
|
|
|
|
|
are using custom persistent objects or if you want to prevent the object properties
|
|
|
|
|
from being saved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:note: This deletes the associated :class:`PersistentObject`.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not self.Find(window):
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@@ -493,17 +495,17 @@ class PersistenceManager(object):
|
|
|
|
|
self._persistentObjects.pop(name)
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Save(self, window):
|
|
|
|
|
"""
|
|
|
|
|
Saves the state of an object.
|
|
|
|
|
|
|
|
|
|
:param `window`: an instance of :class:`Window`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:note: This methods does nothing if :meth:`~PersistenceManager.DisableSaving` was called.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not self._doSave:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@@ -512,10 +514,10 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
name = window.GetName()
|
|
|
|
|
self._persistentObjects[name].Save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Restore(self, window):
|
|
|
|
|
"""
|
|
|
|
|
Restores the state of an object.
|
|
|
|
|
@@ -536,7 +538,7 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
name = window.GetName()
|
|
|
|
|
return self._persistentObjects[name].Restore()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def DisableSaving(self):
|
|
|
|
|
"""
|
|
|
|
|
@@ -547,7 +549,7 @@ class PersistenceManager(object):
|
|
|
|
|
system which shouldn't be modified in any way and so configuration file
|
|
|
|
|
(or Windows registry) shouldn't be written to.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._doSave = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -558,7 +560,7 @@ class PersistenceManager(object):
|
|
|
|
|
:note: By default, restoring properties in :meth:`~PersistenceManager.Restore` is enabled but this
|
|
|
|
|
function allows to disable it. This is mostly useful for testing.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._doRestore = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -569,9 +571,9 @@ class PersistenceManager(object):
|
|
|
|
|
:note: By default, saving properties in :meth:`~PersistenceManager.Save` is enabled but the program
|
|
|
|
|
may wish to disable if, for example, it detects that it is running on a
|
|
|
|
|
system which shouldn't be modified in any way and so configuration file
|
|
|
|
|
(or Windows registry) shouldn't be written to.
|
|
|
|
|
(or Windows registry) shouldn't be written to.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._doSave = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -582,7 +584,7 @@ class PersistenceManager(object):
|
|
|
|
|
:note: By default, restoring properties in :meth:`~PersistenceManager.Restore` is enabled but this
|
|
|
|
|
function allows to disable it. This is mostly useful for testing.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._doRestore = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -610,7 +612,7 @@ class PersistenceManager(object):
|
|
|
|
|
|
|
|
|
|
:param `window`: an instance of :class:`Window`.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self.Register(window) and self.Restore(window)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -622,12 +624,12 @@ class PersistenceManager(object):
|
|
|
|
|
:param `window`: an instance of :class:`Window`;
|
|
|
|
|
:param `children`: list of children of the input `window`, on first call it is equal to ``None``.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if children is None:
|
|
|
|
|
if HasCtrlHandler(window):
|
|
|
|
|
# Control has persist support
|
|
|
|
|
self._hasRestored = self.RegisterAndRestore(window)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
children = window.GetChildren()
|
|
|
|
|
|
|
|
|
|
for child in children:
|
|
|
|
|
@@ -639,7 +641,7 @@ class PersistenceManager(object):
|
|
|
|
|
self._hasRestored = self.RegisterAndRestore(child)
|
|
|
|
|
|
|
|
|
|
self.RegisterAndRestoreAll(window, child.GetChildren())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return self._hasRestored
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -654,7 +656,7 @@ class PersistenceManager(object):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return self._hasRestored
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetKey(self, obj, keyName):
|
|
|
|
|
"""
|
|
|
|
|
@@ -664,12 +666,12 @@ class PersistenceManager(object):
|
|
|
|
|
:param `keyName`: a string specifying the key name.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
key = (self._configKey is None and ["Persistence_Options"] or [self._configKey])[0]
|
|
|
|
|
|
|
|
|
|
key = (self._configKey is None and ["Persistence_Options"] or [self._configKey])[0]
|
|
|
|
|
|
|
|
|
|
key += CONFIG_PATH_SEPARATOR + obj.GetKind()
|
|
|
|
|
key += CONFIG_PATH_SEPARATOR + obj.GetName()
|
|
|
|
|
key += CONFIG_PATH_SEPARATOR + keyName
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return key
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -696,8 +698,8 @@ class PersistenceManager(object):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return self.DoSaveValue(obj, keyName, value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def DoSaveValue(self, obj, keyName, value):
|
|
|
|
|
"""
|
|
|
|
|
Method used by the persistent objects to save the data.
|
|
|
|
|
@@ -712,7 +714,7 @@ class PersistenceManager(object):
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
kind = repr(value.__class__).split("'")[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._customConfigHandler is not None:
|
|
|
|
|
result = self._customConfigHandler.SaveValue(self.GetKey(obj, keyName), repr((kind, str(value))))
|
|
|
|
|
else:
|
|
|
|
|
@@ -720,8 +722,8 @@ class PersistenceManager(object):
|
|
|
|
|
result = config.Write(self.GetKey(obj, keyName), repr((kind, str(value))))
|
|
|
|
|
config.Flush()
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def RestoreCtrlValue(self, obj, keyName):
|
|
|
|
|
"""
|
|
|
|
|
@@ -730,7 +732,7 @@ class PersistenceManager(object):
|
|
|
|
|
:param `obj`: an instance of :class:`PersistentObject`;
|
|
|
|
|
:param `keyName`: a string specifying the key name.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self._style & PM_PERSIST_CONTROL_VALUE:
|
|
|
|
|
return self.DoRestoreValue(obj, keyName)
|
|
|
|
|
|
|
|
|
|
@@ -749,7 +751,7 @@ class PersistenceManager(object):
|
|
|
|
|
def DoRestoreValue(self, obj, keyName):
|
|
|
|
|
"""
|
|
|
|
|
Method used by the persistent objects to restore the data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
By default this method simply use :class:`FileConfig` but this behaviour may be
|
|
|
|
|
overridden by passing a custom config handler in the PersistenceManager
|
|
|
|
|
constructor.
|
|
|
|
|
@@ -772,14 +774,14 @@ class PersistenceManager(object):
|
|
|
|
|
y, m, d = result.split("-")
|
|
|
|
|
result = datetime.date(int(y), int(m), int(d))
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return eval(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def AddBadDefaultName(self, name):
|
|
|
|
|
"""
|
|
|
|
|
Adds a name to the ``BAD_DEFAULT_NAMES`` constant.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
:param `name`: a string specifying the control's default name.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|