Persistance - AquaButton

Andrea,

I get the following exception when I use lib.agw.persist. I looked at the code and the doc to see what I need to do to define AB to the persist framework, but no luck so far.

Just last two lines of exception:
   File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persist_handlers.py", line 2556, in FindHandler
     raise Exception("Unsupported persistent handler (class=%s, name=%s)"%(klass, window.GetName()))
Exception: Unsupported persistent handler (class=<class 'twcbsrc.libui.button.Button'>, name=search)

I also can't find how I would register a new handler based on AbstractHandler to the persistance manager.

Werner

I think I am getting there, but not quit. I believe I need to do the
following until agw.lib.Aquabutton is updated.

class Button(AB.AquaButton, PM.PersistentObject):
    """A base button, which sets out standard back/foreground etc"""
    def __init__(self, **kwargs):
        super(Button, self).__init__(**kwargs)
        PM.PersistentObject.__init__(self, self,

persistenceHandler=AquaButtonHandler)

However I am still getting the following exception - even after having
deleted the corresponding file holding the persistance data.

  File "C:\devProjectsWv\twcbv4\twcbsrc\controllers\base.py", line
624, in Register
    self._persistMgr.RegisterAndRestore(child)
  File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persistencemanager.py", line 570, in RegisterAndRestore
    return self.Register(window) and self.Restore(window)
  File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persistencemanager.py", line 422, in Register
    self._persistentObjects[name] = PersistentObject(window,
persistenceHandler)
  File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persistencemanager.py", line 83, in __init__
    self._persistentHandler = FindHandler(self)
  File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persist_handlers.py", line 2556, in FindHandler
    raise Exception("Unsupported persistent handler (class=%s, name=
%s)"%(klass, window.GetName()))
Exception: Unsupported persistent handler (class=<class
'twcbsrc.libui.button.Button'>, name=search)

Werner

···

On Oct 12, 3:10 pm, werner <wbru...@free.fr> wrote:

Andrea,

I get the following exception when I use lib.agw.persist. I looked at
the code and the doc to see what I need to do to define AB to the
persist framework, but no luck so far.

Just last two lines of exception:
File
"C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persist_handlers.py",
line 2556, in FindHandler
raise Exception("Unsupported persistent handler (class=%s,
name=%s)"%(klass, window.GetName()))
Exception: Unsupported persistent handler (class=<class
'twcbsrc.libui.button.Button'>, name=search)

I also can't find how I would register a new handler based on
AbstractHandler to the persistance manager.

Werner

If I look at RegisterAndRestore (line 570 in PM) it calls self.Register(window) which means it then passes "None" to PersistentObject which then only looks in the internal defined handlers using FindHandler, so it never finds my custom handler.

Am I on the right track or .....?

Werner

···

On 10/12/2011 03:49 PM, werner wrote:

On Oct 12, 3:10 pm, werner<wbru...@free.fr> wrote:

Andrea,

I get the following exception when I use lib.agw.persist. I looked at
the code and the doc to see what I need to do to define AB to the
persist framework, but no luck so far.

Just last two lines of exception:
    File
"C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persist_handlers.py",
line 2556, in FindHandler
      raise Exception("Unsupported persistent handler (class=%s,
name=%s)"%(klass, window.GetName()))
Exception: Unsupported persistent handler (class=<class
'twcbsrc.libui.button.Button'>, name=search)

I also can't find how I would register a new handler based on
AbstractHandler to the persistance manager.

Werner

I think I am getting there, but not quit. I believe I need to do the
following until agw.lib.Aquabutton is updated.

class Button(AB.AquaButton, PM.PersistentObject):
     """A base button, which sets out standard back/foreground etc"""
     def __init__(self, **kwargs):
         super(Button, self).__init__(**kwargs)
         PM.PersistentObject.__init__(self, self,

persistenceHandler=AquaButtonHandler)

However I am still getting the following exception - even after having
deleted the corresponding file holding the persistance data.

   File "C:\devProjectsWv\twcbv4\twcbsrc\controllers\base.py", line
624, in Register
     self._persistMgr.RegisterAndRestore(child)
   File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persistencemanager.py", line 570, in RegisterAndRestore
     return self.Register(window) and self.Restore(window)
   File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persistencemanager.py", line 422, in Register
     self._persistentObjects[name] = PersistentObject(window,
persistenceHandler)
   File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persistencemanager.py", line 83, in __init__
     self._persistentHandler = FindHandler(self)
   File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist
\persist_handlers.py", line 2556, in FindHandler
     raise Exception("Unsupported persistent handler (class=%s, name=
%s)"%(klass, window.GetName()))
Exception: Unsupported persistent handler (class=<class
'twcbsrc.libui.button.Button'>, name=search)

Hi Werner,

Andrea,

I get the following exception when I use lib.agw.persist. I looked at

the code and the doc to see what I need to do to define AB to the

persist framework, but no luck so far.

Just last two lines of exception:

File

“C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persist_handlers.py”,

line 2556, in FindHandler

  raise Exception("Unsupported persistent handler (class=%s,

name=%s)"%(klass, window.GetName()))

Exception: Unsupported persistent handler (class=<class

‘twcbsrc.libui.button.Button’>, name=search)

I also can’t find how I would register a new handler based on

AbstractHandler to the persistance manager.

Werner
I think I am getting there, but not quit. I believe I need to do the

following until agw.lib.Aquabutton is updated.

class Button(AB.AquaButton, PM.PersistentObject):

 """A base button, which sets out standard back/foreground etc"""

 def __init__(self, **kwargs):

     super(Button, self).__init__(**kwargs)

     PM.PersistentObject.__init__(self, self,

persistenceHandler=AquaButtonHandler)

However I am still getting the following exception - even after having

deleted the corresponding file holding the persistance data.

File “C:\devProjectsWv\twcbv4\twcbsrc\controllers\base.py”, line

624, in Register

 self._persistMgr.RegisterAndRestore(child)

File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

\persistencemanager.py", line 570, in RegisterAndRestore

 return self.Register(window) and self.Restore(window)

File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

\persistencemanager.py", line 422, in Register

 self._persistentObjects[name] = PersistentObject(window,

persistenceHandler)

File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

\persistencemanager.py", line 83, in init

 self._persistentHandler = FindHandler(self)

File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

\persist_handlers.py", line 2556, in FindHandler

 raise Exception("Unsupported persistent handler (class=%s, name=

%s)"%(klass, window.GetName()))

Exception: Unsupported persistent handler (class=<class

‘twcbsrc.libui.button.Button’>, name=search)

If I look at RegisterAndRestore (line 570 in PM) it calls self.Register(window) which means it then passes “None” to PersistentObject which then only looks in the internal defined handlers using FindHandler, so it never finds my custom handler.

Am I on the right track or …?

You are on the right track. When I implemented PersistentControls, I borrowed some stuff from the wxWidgets C++ implementation, but most of it came out of my coding. And you have spotted one (of many) bug in it. If you manage to create a patch, I will happily apply it on SVN.

Thank you!

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 12 October 2011 18:41, werner wrote:

On 10/12/2011 03:49 PM, werner wrote:

On Oct 12, 3:10 pm, wernerwbru...@free.fr wrote:

import wx

I might have a patch - still needs more testing.

Still have a few controls where I like to register a "NullHandler"

i.e. we don’t need to save any persistance data as the control can
just be placed by the parent/sizer. My AquaButton based control, my
ObjectListView as column order and size are handled differently and
data is loaded from database.

Do you see a problem if one would just subclass AbstractHandler and

only override GetKind?

Werner
···

On 10/12/2011 09:13 PM, Andrea Gavana wrote:

Hi Werner,

On 12 October 2011 18:41, werner wrote:

On 10/12/2011 03:49 PM, werner wrote:

On Oct 12, 3:10 pm, werner<wbru...@free.fr > > > > wrote:

Andrea,

              I get the following exception when I use

lib.agw.persist. I looked at

              the code and the doc to see what I need to do to

define AB to the

              persist framework, but no luck so far.



              Just last two lines of exception:

                 File

              "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist\persist_handlers.py",

              line 2556, in FindHandler

                   raise Exception("Unsupported persistent handler

(class=%s,

              name=%s)"%(klass, window.GetName()))

              Exception: Unsupported persistent handler

(class=<class

              'twcbsrc.libui.button.Button'>, name=search)



              I also can't find how I would register a new handler

based on

              AbstractHandler to the persistance manager.



              Werner
            I think I am getting there, but not quit.  I believe I

need to do the

            following until agw.lib.Aquabutton is updated.



            class Button(AB.AquaButton, PM.PersistentObject):

                """A base button, which sets out standard

back/foreground etc"“”

                def __init__(self, **kwargs):

                    super(Button, self).__init__(**kwargs)

                    PM.PersistentObject.__init__(self, self,



            persistenceHandler=AquaButtonHandler)



            However I am still getting the following exception -

even after having

            deleted the corresponding file holding the persistance

data.

              File "C:\devProjectsWv\twcbv4\twcbsrc\controllers\base.py",

line

            624, in Register

                self._persistMgr.RegisterAndRestore(child)

              File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

            \persistencemanager.py", line 570, in RegisterAndRestore

                return self.Register(window) and

self.Restore(window)

              File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

            \persistencemanager.py", line 422, in Register

                self._persistentObjects[name] =

PersistentObject(window,

            persistenceHandler)

              File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

            \persistencemanager.py", line 83, in __init__

                self._persistentHandler = FindHandler(self)

              File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\lib\agw\persist

            \persist_handlers.py", line 2556, in FindHandler

                raise Exception("Unsupported persistent handler

(class=%s, name=

            %s)"%(klass, window.GetName()))

            Exception: Unsupported persistent handler

(class=<class

            'twcbsrc.libui.button.Button'>, name=search)
      If I look at RegisterAndRestore (line 570 in PM) it calls

self.Register(window) which means it then passes “None” to
PersistentObject which then only looks in the internal defined
handlers using FindHandler, so it never finds my custom
handler.

      Am I on the right track or .....?
    You are on the right track. When I implemented

PersistentControls, I borrowed some stuff from the wxWidgets C++
implementation, but most of it came out of my coding. And you
have spotted one (of many) bug in it. If you manage to create a
patch, I will happily apply it on SVN.

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)

Hi Werner,

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).

Thank you for the patch. At first sight, it seems good to me but I’ll review it a bit better this evening when I get back home (I have no SVN stuff here at work). Don’t worry, there is no need for a helmet :wink:

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)

Yes, this is a good suggestion. I’ll try and adapt your modified “Register” method to recursively traverse the hierarchy specified by “topwindow”, although I am not clear why we should specify both “topwindow” and “children”. Is it not enough to do:

topwindow.GetChildren()

To recursively traverse the window hierarchy? Maybe I have missed something from your explanation…

Thank you for the patch, it is sooooo much appreciated!

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 14 October 2011 15:40, werner wrote:

import wx

Hi Andrea,

···

:wink:

      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)

      Yes, this is a good suggestion. I'll try and adapt your

modified “Register” method to recursively traverse the
hierarchy specified by “topwindow”, although I am not clear
why we should specify both “topwindow” and “children”. Is it
not enough to do:

topwindow.GetChildren()

      To recursively traverse the window hierarchy? Maybe I have

missed something from your explanation…

Thank you for the patch, it is sooooo much appreciated!

Hi Andrea,

Just noted that my agw.aui.Notebook is not "persisted", how do I give it a different name then "AuiNotebook" or what do I do so it is excluded by the code in Register.

Werner

Hi Werner,

Hi Andrea,

Just noted that my agw.aui.Notebook is not “persisted”, how do I give it a different name then “AuiNotebook” or what do I do so it is excluded by the code in Register.

My apologies, I forgot to include the “name” parameter into the AuiNotebook constructor. I have fixed it in SVN. However, I believe you van always call SetName on a window to change its name (although if you are using the SVN version of AGW it should not be necessary anymore).

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 14 October 2011 20:18, werner wrote:

import wx

Hi Werner,

Hi Andrea,

Hi Werner,

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).

      Thank you for the patch. At first sight, it seems good to

me but I’ll review it a bit better this evening when I get
back home (I have no SVN stuff here at work). Don’t worry,
there is no need for a helmet :wink:

Great, it was a bit uncomfortable
:wink:

      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)

      Yes, this is a good suggestion. I'll try and adapt your

modified “Register” method to recursively traverse the
hierarchy specified by “topwindow”, although I am not clear
why we should specify both “topwindow” and “children”. Is it
not enough to do:

topwindow.GetChildren()

      To recursively traverse the window hierarchy? Maybe I have

missed something from your explanation…

I assumed it would again be called recursively, so on initial call

“children=None” and when it calls itself it would be filling
“children”, which would allow the handling of the menubar and maybe
later on the toolbar etc on the initial call.

Thank you for the patch, it is sooooo much appreciated!

You are very welcome!

I have applied your patch in SVN, and also implemented the RegisterAndRestoreAll method. Hopefully I have understood correctly what you meant, but please feel free to correct me if I have missed the point.

Thank you again.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 14 October 2011 17:45, werner wrote:

On 10/14/2011 04:13 PM, Andrea Gavana wrote:

On 14 October 2011 15:40, werner wrote:

import wx

Good morning Andrea,

Hi Werner,
I have applied your patch in SVN, and also implemented the RegisterAndRestoreAll method. Hopefully I have understood correctly what you meant, but please feel free to correct me if I have missed the point.

RegisterAndRestoreAll didn't quit work for me, attached a patch which works. Put the "children" param back in because I can't figure out have "window" could initially be just a window and then be a list. I guess one could check if window is a list but I think I prefer having it separate as it makes it easier to understand what the intent is (at least for me;-) .

Werner

persist2.patch (1.99 KB)

···

On 10/14/2011 09:06 PM, Andrea Gavana wrote:

Hi Werner,

Good morning Andrea,

Hi Werner,

I have applied your patch in SVN, and also implemented the RegisterAndRestoreAll method. Hopefully I have understood correctly what you meant, but please feel free to correct me if I have missed the point.

RegisterAndRestoreAll didn’t quit work for me, attached a patch which works. Put the “children” param back in because I can’t figure out have “window” could initially be just a window and then be a list. I guess one could check if window is a list but I think I prefer having it separate as it makes it easier to understand what the intent is (at least for me;-) .

Thank you for the patch, I appreciate it a lot. Changes to PersistentControls with your patch have been merged in SVN.

Thank you!

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 15 October 2011 11:47, werner wrote:

On 10/14/2011 09:06 PM, Andrea Gavana wrote:

import wx

Hi Andrea,

Hi Werner,

Good morning Andrea,

Hi Werner,

          I have applied your patch in SVN, and also implemented the

RegisterAndRestoreAll method. Hopefully I have understood
correctly what you meant, but please feel free to correct
me if I have missed the point.

      RegisterAndRestoreAll didn't quit work for me, attached a

patch which works. Put the “children” param back in because I
can’t figure out have “window” could initially be just a
window and then be a list. I guess one could check if window
is a list but I think I prefer having it separate as it makes
it easier to understand what the intent is (at least for me;-)
.

    Thank you for the patch, I appreciate it a lot. Changes to

PersistentControls with your patch have been merged in SVN.

Thanks for merging this.

Do you have any better idea for the "BAD_DEFAULT_NAMES" constant, it

would be nice that it would get all the name strings from all
controls in wx and I think there should also be a public way of
adding default names to this.

I use the masked controls a lot, so would like to see them added,

but doing code similar to the following is a pain to maintain.

BAD_DEFAULT_NAMES = []

for name in dir(wx):

    if "NameStr" in name:

        BAD_DEFAULT_NAMES.append(eval("wx.%s"%name))

BAD_DEFAULT_NAMES.append("widget")

BAD_DEFAULT_NAMES.append("wxSpinButton")

BAD_DEFAULT_NAMES.append("auiFloating")

BAD_DEFAULT_NAMES.append("AuiTabCtrl")

BAD_DEFAULT_NAMES.append("maskedTextCtrl")

BAD_DEFAULT_NAMES.append("numctrl")

BAD_DEFAULT_NAMES.append("IpAddrCtrl")

BAD_DEFAULT_NAMES.append("masked.num")

BAD_DEFAULT_NAMES.append("time")

Isn't there a way to just get the controls out of the "wx" and add

their default name?

Werner
···

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

Hi Andrea,

I have to go reset all my controls data as the data which was shown from the persistence restore is not relevant during the next session.

Is there any way of only saving/restoring layout information or would you accept a patch which would tell the PM not to do any setvalue/changevalue type calls?

Werner

Hi Werner,

Hi Andrea,

Hi Werner,

Good morning Andrea,

Hi Werner,

          I have applied your patch in SVN, and also implemented the

RegisterAndRestoreAll method. Hopefully I have understood
correctly what you meant, but please feel free to correct
me if I have missed the point.

      RegisterAndRestoreAll didn't quit work for me, attached a

patch which works. Put the “children” param back in because I
can’t figure out have “window” could initially be just a
window and then be a list. I guess one could check if window
is a list but I think I prefer having it separate as it makes
it easier to understand what the intent is (at least for me;-)
.

    Thank you for the patch, I appreciate it a lot. Changes to

PersistentControls with your patch have been merged in SVN.

Thanks for merging this.

Do you have any better idea for the "BAD_DEFAULT_NAMES" constant, it

would be nice that it would get all the name strings from all
controls in wx and I think there should also be a public way of
adding default names to this.

I use the masked controls a lot, so would like to see them added,

but doing code similar to the following is a pain to maintain.

BAD_DEFAULT_NAMES = []

for name in dir(wx):

    if "NameStr" in name:

        BAD_DEFAULT_NAMES.append(eval("wx.%s"%name))

BAD_DEFAULT_NAMES.append("widget")

BAD_DEFAULT_NAMES.append("wxSpinButton")

BAD_DEFAULT_NAMES.append("auiFloating")

BAD_DEFAULT_NAMES.append("AuiTabCtrl")

BAD_DEFAULT_NAMES.append("maskedTextCtrl")

BAD_DEFAULT_NAMES.append("numctrl")

BAD_DEFAULT_NAMES.append("IpAddrCtrl")

BAD_DEFAULT_NAMES.append("masked.num")

BAD_DEFAULT_NAMES.append("time")



Isn't there a way to just get the controls out of the "wx" and add

their default name?

I am not sure it is easily doable… you can get the class names out of the wx namespace, but for the widgets default names that’s another story :frowning: . The only thing I can think of now is raw and brute force source code parsing for wx.lib and all its sub-folders (as the wxWidgets SWIGged controls have a more or less standard naming convention), maybe using a regex. However, this may drastically increase the initial import time of the persist library. There might be better way, but it’s late and I am a bit short of ideas… I am open to all suggestions, of course.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 17 October 2011 20:05, werner wrote:

On 10/16/2011 07:02 PM, Andrea Gavana wrote:

On 15 October 2011 11:47, werner wrote:

        On 10/14/2011 09:06 PM, Andrea Gavana wrote:

import wx

Hi Werner,

Hi Andrea,

I have to go reset all my controls data as the data which was shown from the persistence restore is not relevant during the next session.

Is there any way of only saving/restoring layout information or would you accept a patch which would tell the PM not to do any setvalue/changevalue type calls?

There is currently no way to do what you are asking, but I will gladly accept a patch implementing this feature. It’s a very good idea, as not always you need all the data restored.

Andrea.

“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/

import PyQt4.QtGui

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named PyQt4.QtGui

import pygtk

Traceback (most recent call last):

File “”, line 1, in

ImportError: No module named pygtk

···

On 17 October 2011 20:32, werner wrote:

import wx

Hi Werner,

Hi Andrea,

Hi Werner,

Good morning Andrea,

Hi Werner,

                    I have applied your patch in SVN, and also

implemented the RegisterAndRestoreAll method.
Hopefully I have understood correctly what you
meant, but please feel free to correct me if I
have missed the point.

                RegisterAndRestoreAll didn't quit work for me,

attached a patch which works. Put the “children”
param back in because I can’t figure out have
“window” could initially be just a window and then
be a list. I guess one could check if window is a
list but I think I prefer having it separate as it
makes it easier to understand what the intent is (at
least for me;-) .

              Thank you for the patch, I appreciate it a lot.

Changes to PersistentControls with your patch have
been merged in SVN.

Thanks for merging this.

        Do you have any better idea for the "BAD_DEFAULT_NAMES"

constant, it would be nice that it would get all the name
strings from all controls in wx and I think there should
also be a public way of adding default names to this.

        I use the masked controls a lot, so would like to see them

added, but doing code similar to the following is a pain to
maintain.

        BAD_DEFAULT_NAMES = []

        for name in dir(wx):

            if "NameStr" in name:

                BAD_DEFAULT_NAMES.append(eval("wx.%s"%name))

        BAD_DEFAULT_NAMES.append("widget")

        BAD_DEFAULT_NAMES.append("wxSpinButton")

        BAD_DEFAULT_NAMES.append("auiFloating")

        BAD_DEFAULT_NAMES.append("AuiTabCtrl")

        BAD_DEFAULT_NAMES.append("maskedTextCtrl")

        BAD_DEFAULT_NAMES.append("numctrl")

        BAD_DEFAULT_NAMES.append("IpAddrCtrl")

        BAD_DEFAULT_NAMES.append("masked.num")

        BAD_DEFAULT_NAMES.append("time")



        Isn't there a way to just get the controls out of the "wx"

and add their default name?

      I am not sure it is easily doable... you can get the class

names out of the wx namespace, but for the widgets default
names that’s another story :frowning: . The only thing I can think of
now is raw and brute force source code parsing for wx.lib and
all its sub-folders (as the wxWidgets SWIGged controls have a
more or less standard naming convention), maybe using a regex.
However, this may drastically increase the initial import time
of the persist library.

Might not be that good.

      There might be better way, but it's late and I am a bit

short of ideas… I am open to all suggestions, of course.

What about just a public way to update "BAD_DEFAULT_NAMES"?  Not

perfect but might be a workable compromise, at least until a better
way is found.

Werner
···

On 10/17/2011 09:35 PM, Andrea Gavana wrote:

On 17 October 2011 20:05, werner wrote:

          On 10/16/2011 07:02 PM, Andrea Gavana wrote:
              On 15 October 2011 11:47, > > > werner wrote:
                  On 10/14/2011 09:06 PM, Andrea Gavana wrote:

Will try and come up with something, but will take a few days as I
have some other stuff going on.

Werner
···

On 10/17/2011 09:38 PM, Andrea Gavana wrote:

Hi Werner,

On 17 October 2011 20:32, werner wrote:

Hi Andrea,

      I have to go reset all my controls data as the data which was

shown from the persistence restore is not relevant during the
next session.

      Is there any way of only saving/restoring layout information

or would you accept a patch which would tell the PM not to do
any setvalue/changevalue type calls?

      There is currently no way to do what you are asking, but I

will gladly accept a patch implementing this feature. It’s a
very good idea, as not always you need all the data restored.

Hi Andrea,

Hi Werner,

Hi Andrea,

        I have to go reset all my controls data as the data which

was shown from the persistence restore is not relevant
during the next session.

        Is there any way of only saving/restoring layout information

or would you accept a patch which would tell the PM not to
do any setvalue/changevalue type calls?

        There is currently no way to do what you are asking, but

I will gladly accept a patch implementing this feature. It’s
a very good idea, as not always you need all the data
restored.

  Will try and come up with something, but will take a few days as I

have some other stuff going on.

Started to look into this in more detail.  On first look I thought I

could just handle this in PM.SaveValue and PM.RestoreValue but when
looking at the defined handlers in persist_handler.py I see that a
lot (if not all) just use “Restore” and don’t use RestoreValue and
the same for save.

Before changing all of this I like to be sure that this would be

o.k. with you.

I.e.

In PersistenceManager

- SaveAndUnregister would call both Save and SaveValue

- RegisterAndRestore would call both Restore and RestoreValue

- SaveValue and RestoreValue would check a new variable (which

defaults to do save/restore value) to see if they should do the
save/restore

In persist_handlers:

- change all handlers which do a SetValue/ChangeValue or similar to

have them use/override SaveValue/RestoreValue instead of
Save/Restore

Werner
···

On 10/17/2011 11:13 PM, werner wrote:

On 10/17/2011 09:38 PM, Andrea Gavana wrote:

On 17 October 2011 20:32, werner wrote: