From c480c4578cffc980dde3309de91e673ea57f4e10 Mon Sep 17 00:00:00 2001 From: Andrea Gavana Date: Mon, 17 Dec 2012 20:16:04 +0000 Subject: [PATCH] `PersistentControls` on wxPython Phoenix: apply correctly Werner's patch and update the docstrings with the example provided by mattip. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73198 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wx/lib/agw/__init__.py | 2 +- wx/lib/agw/persist/__init__.py | 34 +++++++++++++++--------- wx/lib/agw/persist/persistencemanager.py | 4 +-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/wx/lib/agw/__init__.py b/wx/lib/agw/__init__.py index daf2b4c5..283e57bc 100644 --- a/wx/lib/agw/__init__.py +++ b/wx/lib/agw/__init__.py @@ -120,7 +120,7 @@ andrea.gavana@maerskoil.com AGW version: 0.9.7 -Last updated: 03 December 2012, 21.00 GMT +Last updated: 17 December 2012, 21.00 GMT """ diff --git a/wx/lib/agw/persist/__init__.py b/wx/lib/agw/persist/__init__.py index 07d77695..c348ab12 100644 --- a/wx/lib/agw/persist/__init__.py +++ b/wx/lib/agw/persist/__init__.py @@ -98,28 +98,36 @@ Usage Example of using a notebook control which automatically remembers the last open page:: - - import wx + import wx, os import wx.lib.agw.persist as PM class MyFrame(wx.Frame): def __init__(self, parent): - wx.Frame.__init(self, parent, -1, "Persistent Controls Demo") + wx.Frame.__init__(self, parent, -1, "Persistent Controls Demo") - book = wx.Notebook(self, wx.ID_ANY) + self.book = wx.Notebook(self, wx.ID_ANY) # Very important step!! - book.SetName("MyBook") # Do not use the default name!! - - book.AddPage(wx.Panel(book), "Hello") - book.AddPage(wx.Panel(book), "World") - - if not PM.PersistenceManager.RegisterAndRestore(book): - # Nothing was restored, so choose the default page ourselves - book.SetSelection(0) + self.book.SetName("MyBook") # Do not use the default name!! + self.book.AddPage(wx.Panel(self.book), "Hello") + self.book.AddPage(wx.Panel(self.book), "World") + self.Bind(wx.EVT_CLOSE, self.OnClose) + + self._persistMgr = PM.PersistenceManager.Get() + + _configFile = os.path.join(os.getcwd(), self.book.GetName()) + self._persistMgr.SetPersistenceFile(_configFile) + + if not self._persistMgr.RegisterAndRestoreAll(self.book): + # Nothing was restored, so choose the default page ourselves + self.book.SetSelection(0) + + def OnClose(self, event): + self._persistMgr.SaveAndUnregister(self.book) + event.Skip() # our normal wxApp-derived class, as usual @@ -171,7 +179,7 @@ License And Version `PersistentObjects` library is distributed under the wxPython license. -Latest revision: Andrea Gavana @ 25 Apr 2012, 11.00 GMT +Latest revision: Andrea Gavana @ 17 Dec 2012, 21.00 GMT Version 0.4. """ diff --git a/wx/lib/agw/persist/persistencemanager.py b/wx/lib/agw/persist/persistencemanager.py index 6c58d87e..941e0f5f 100644 --- a/wx/lib/agw/persist/persistencemanager.py +++ b/wx/lib/agw/persist/persistencemanager.py @@ -10,7 +10,7 @@ # Python Code By: # # Andrea Gavana, @ 16 Nov 2009 -# Latest Revision: 03 Dec 2012, 21.00 GMT +# Latest Revision: 17 Dec 2012, 21.00 GMT # # For All Kind Of Problems, Requests Of Enhancements And Bug Reports, Please # Write To Me At: @@ -623,8 +623,6 @@ class PersistenceManager(object): :param `children`: list of children of the input `window`, on first call it is equal to ``None``. """ - self._hasRestored = False - if children is None: if HasCtrlHandler(window): # Control has persist support