Problem with wx.lib.agw.customtreectrl together with wx.lib.agw.persist

Hello,

I would like to be able to save a ‘customtreectrl’ state (ie items folded or not, checked or not…) when the user closes an application, in order to bring in back at the next launch. I tried to use the ‘persist’ module for this, but I encounter a problem when running the sample.py program (see attached file).

When using wxPython 2.8.12.1, I get the following error:
" self._persistMgr.Save(self._wxCustomTree)
File “C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\persist\persistencemanager.py”, line 468, in Save
self._persistentObjects[name].Save()
File “C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\persist\persistencemanager.py”, line 127, in Save
self._persistentHandler.Save()
File “C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\persist\persist_handlers.py”, line 924, in Save
scrollPos = scroll.GetScrollPos()
File “C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx_core.py”, line 10328, in GetScrollPos
return core.Window_GetScrollPos(*args, **kwargs)
TypeError: Required argument ‘orientation’ (pos 2) not found"

I read somewhere that this might be related to wxPython version, so I downloaded and installed the latest available, version ‘2.9.4.0’.
When running the sample, I do not get the ‘TypeError’ as above, but the tree state is not saved, nothing is remembered across successive application close/launch.

After digging a while in the ‘persist’ module code, I then tried to comment line #2509 in file persist_handlers.py (from wx ‘2.9.4.0’):
#(“AUIHandler”, (wx.Panel, )),

And now this works great! The tree state (item selection for example) is correctly saved.

It seem that the ‘persist’ module fails to correctly identify the ‘customtreectrl’ object, and thinks it is a simple wx.Panel instead…

Thanks for your help!
Jérôme

sample.py (3.5 KB)

Hi J�r�me,

Hello,

I would like to be able to save a 'customtreectrl' state (ie items folded or not, checked or not...) when the user closes an application, in order to bring in back at the next launch. I tried to use the 'persist' module for this, but I encounter a problem when running the sample.py program (see attached file).

When using wxPython 2.8.12.1, I get the following error:
" self._persistMgr.Save(self._wxCustomTree)
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\persist\persistencemanager.py", line 468, in Save
self._persistentObjects[name].Save()
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\persist\persistencemanager.py", line 127, in Save
self._persistentHandler.Save()
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\lib\agw\persist\persist_handlers.py", line 924, in Save
    scrollPos = scroll.GetScrollPos()
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 10328, in GetScrollPos
    return _core_.Window_GetScrollPos(*args, **kwargs)
TypeError: Required argument 'orientation' (pos 2) not found"

I read somewhere that this might be related to wxPython version, so I downloaded and installed the latest available, version '2.9.4.0'.
When running the sample, I do not get the 'TypeError' as above, but the tree state is not saved, nothing is remembered across successive application close/launch.

After digging a while in the 'persist' module code, I then tried to comment line #2509 in file persist_handlers.py (from wx '2.9.4.0'):
#("AUIHandler", (wx.Panel, )),

Not a very nice fix;-) , would probably break other stuff.

I don't use CustomTree but looking at persist_handlers (I use SVN version) I see that it should use the TreeCtrlHandler - line 2511.

Is that in your 2.9.4 version? If yes, can you create a small runnable sample (MakingSampleApps - wxPyWiki) which shows the problem.

And now this works great! The tree state (item selection for example) is correctly saved.

BTW, have you assigned a unique 'name' to all your panels etc above the CustomTreee?

Quote from doc:
* Set a unique name for the window using `SetName()`: this step is important as the
   name is used in the configuration file and so must be unique among all windows of
   the same class;

I fell into that whole a few times since I use persist in my stuff:-[ .

Werner

···

On 18/01/2013 15:28, jeromecoroyer wrote:

Hello Werner, thanks for your answer

Not a very nice fix;-) , would probably break other stuff.
Yes totally agree, purpose is only to give a hint on where to start investigation…

I don’t use CustomTree but looking at persist_handlers (I use SVN
version) I see that it should use the TreeCtrlHandler - line 2511.

Is that in your 2.9.4 version?
Yes I have TreeCtrlHandler - line 2511 (persist_handlers.py) it in my ‘2.9.4.0’ version

If yes, can you create a small runnable
sample (http://wiki.wxpython.org/MakingSampleApps) which shows the problem.
Yes I uploaded it in my original post (see attached file sample.py)

BTW, have you assigned a unique ‘name’ to all your panels etc above the
CustomTreee?

Yes I did that too, see line #54 in my sample.py file

Thanks for your help

Jérôme

Hi J�r�me,

Didn't see/notice the attachement, will have a look at it over the weekend and see if I can help.

Werner

Hi J�r�me and Andrea;-) ,

Moved "AUIHandler" to the bottom of the list and then CTC worked, but it messed up at least one of my dialogs using AUI - no big surprise. So, I moved it to just after "RadioButtonHandler" and then CTC and one of my AUI dialogs are working fine.

Needs more testing and/or the insight of Andrea what the right hierarchy of "HANDLERS" list should be.

Werner

Hi Werner, and Andrea

sample.py (3.5 KB)

···

Le samedi 19 janvier 2013 08:49:08 UTC+1, werner a écrit :

Hi J�r�me and Andrea;-) ,

Moved “AUIHandler” to the bottom of the list and then CTC worked, but it
messed up at least one of my dialogs using AUI - no big surprise. So, I
moved it to just after “RadioButtonHandler” and then CTC and one of my
AUI dialogs are working fine.

Needs more testing and/or the insight of Andrea what the right hierarchy
of “HANDLERS” list should be.

Werner

Thanks for this testing on your side, I will wait for Andrea thoughts about this issue and possible fix.

In the meantime I will quick-fix the Handler order just as you did to make it work with the CustomTreeCtrl.

I attach the ‘sample.py’ file.

Jerome

Hi,

Hi Werner, and Andrea

Hi J�r�me and Andrea;-) ,

Moved "AUIHandler" to the bottom of the list and then CTC worked, but it
messed up at least one of my dialogs using AUI - no big surprise. So, I
moved it to just after "RadioButtonHandler" and then CTC and one of my
AUI dialogs are working fine.

Needs more testing and/or the insight of Andrea what the right hierarchy
of "HANDLERS" list should be.

Werner

Thanks for this testing on your side, I will wait for Andrea thoughts about
this issue and possible fix.
In the meantime I will quick-fix the Handler order just as you did to make
it work with the CustomTreeCtrl.
I attach the 'sample.py' file.

I have done some quick testing and it appears that the right hierarchy
of the HANDLERS list should have the AUIHandler just after the
CollapsiblePaneHandler, as most of the previous classes (i.e.,
wx.VListBox, wx.ScrolledWindow, FlatMenuBar and, of course,
CustomTreeCtrl) are all subclasses of wx.Panel, i.e.:

issubclass(widget, wx.Panel)

returns True for them. I'll try and fix it when I get back home tonight.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

···

On 21 January 2013 10:14, jeromecoroyer wrote:

Le samedi 19 janvier 2013 08:49:08 UTC+1, werner a écrit :

Hi Andrea,

...

I have done some quick testing and it appears that the right hierarchy
of the HANDLERS list should have the AUIHandler just after the
CollapsiblePaneHandler, as most of the previous classes (i.e.,
wx.VListBox, wx.ScrolledWindow, FlatMenuBar and, of course,
CustomTreeCtrl) are all subclasses of wx.Panel, i.e.:

issubclass(widget, wx.Panel)

returns True for them. I'll try and fix it when I get back home tonight.

Did a quick test and changing the HANDLERS list as you suggest above works for my stuff.

Werner

···

On 22/01/2013 13:55, Andrea Gavana wrote:

Hi Andrea,

Thanks for your answer, I appreciate. It is also a pleasure to contribute to wxPython :slight_smile:

I wait for your fix then, keep me posted.

Regards

Jerome

Hi,

Hi Andrea,

Thanks for your answer, I appreciate. It is also a pleasure to contribute to
wxPython :slight_smile:
I wait for your fix then, keep me posted.

The fix should now be in SVN, please let me know if you encounter other issues.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

···

On 22 January 2013 14:27, jeromecoroyer wrote:

Hi Andrea,

Just downloaded the latest ‘persist’ files from SVN: it works now great with CustomTreeCtrl !

Thanks

Jérôme