Andrea,
Here is a patch for persist stuff.
- added a method "persist_handler.HasCtrlHandler" to be able to figure out if a control supports the persist stuff - see below for more.
- changed method "persist_handler.FindHandler" to deal with custom handler
- changed text.SetValue to text.ChangeValue in TextCtrlHandler to prevent EVT_TEXT event being sent
- changed the ScrolledWindowHandler as I got the exception below on it.
- Adapted "Register" method from your demo to my use, see below (this is called from a base controller who only knows about a view and has no clue what controls might be in the view).
Shouldn't this be a method "RegisterAndRestoreAll" and be provided with the persist framework?
Suggested signature would be:
def RegisterAndRestoreAll(self, persistmgr, topwindow=self, children=None)
I will put my helmet on in a little while - please comment on all this.
Werner
My version of "Register":
def Register(self, children=None):
"""Register recursively all children
:param children: if None register 'self' and then use GetChildren()
:type children: list
"""
if children is None:
self._persistMgr.RegisterAndRestore(self.view)
if hasattr(self.view, 'GetMenuBar'):
self._persistMgr.RegisterAndRestore(self.GetMenuBar())
children = self.view.GetChildren()
for child in children:
name = child.GetName()
logging.debug("Register: name: %s" % name)
if name not in PM.BAD_DEFAULT_NAMES and "widget" not in name and \
"wxSpinButton" not in name and "auiFloating" not in name and \
"AuiTabCtrl" not in name and "AuiNotebook" not in name:
if PM.HasCtrlHandler(child):
# control has persist support
self._persistMgr.RegisterAndRestore(child)
if child.GetChildren():
self.Register(child.GetChildren())
ScrolledWindow Exception:
File "C:\devProjectsWv\twcbv4\twcbsrc\controllers\base.py", line 489, in OnClose
self._persistMgr.SaveAndUnregister()
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persistencemanager.py", line 557, in SaveAndUnregister
self.SaveAndUnregister(obj.GetWindow())
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persistencemanager.py", line 561, in SaveAndUnregister
self.Save(window)
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persistencemanager.py", line 470, in Save
self._persistentObjects[name].Save()
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persistencemanager.py", line 129, in Save
self._persistentHandler.Save()
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persist_handlers.py", line 926, in Save
scrollPos = scroll.GetScrollPos(wx.HORIZONTAL)
File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\_core.py", line 11217, in GetScrollPos
return _core_.Window_GetScrollPos(*args, **kwargs)
TypeError: Required argument 'orientation' (pos 2) not found
persist.patch (4.51 KB)