Overwritten TreeCtrl.OnCompareItems() not called when using Python3/wxPython4

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Overwritten TreeCtrl.OnCompareItems() not called when using Python3/wxPython4

Thomas Krull

Hi,


I have a wx.TreeCtrl structure where the user can sort the items by different criteria (date, name, id, descending, ascending, ...). This worked fine in Python 2, but Python 3 (with wxPython 4) refuses sorting. The method CTreeCtrl.OnCompareItems() is called in Python 2, but never in Python 3 (see attached file).


In the functools.cmp_to_key() documentation (https://docs.python.org/3/library/functools.html) I found a hint: Python 3 does not support comparison functions. Confusing: in the description of wx.TreeCtrl (wxPython 4) there is a comparison method OnCompareItems() (https://docs.wxpython.org/wx.TreeCtrl.html#wx.TreeCtrl.OnCompareItems). The description says, that together with this method I must use the RTTI macros DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS since the baseclass does not know that I overwrote OnCompareItems(). I found descriptions of how to use this macros in C++, but nothing for python.


Now I have no idea how I could make my program calling my OnCompareItems() method in Python3/wxPython 4 and I would like to avoid inventing my own SortChildren() method :-).


The attached compare_or_not.py contains a small sample programm which reflects the problem. It runs with Python 2 and Python 3 as well. The print( 'in CTreeCtrl.OnCompareItems()' ) in this code shows, that method OnCompareItems() is called (in py2) or not called (in py3).


Can anybody help?


Thanks in advande and best regards, Humbalan


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

compare_or_not.py (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Overwritten TreeCtrl.OnCompareItems() not called when using Python3/wxPython4

Scott Talbert
On Thu, 8 Mar 2018, Thomas Krull wrote:

> In the functools.cmp_to_key() documentation
> (https://docs.python.org/3/library/functools.html) I found a hint: Python 3
> does not support comparison functions. Confusing: in the description of
> wx.TreeCtrl (wxPython 4) there is a comparison method OnCompareItems()
> (https://docs.wxpython.org/wx.TreeCtrl.html#wx.TreeCtrl.OnCompareItems). The
> description says, that together with this method I must use the RTTI macros
> DECLARE_DYNAMIC_CLASS and IMPLEMENT_DYNAMIC_CLASS since the baseclass does
> not know that I overwrote OnCompareItems(). I found descriptions of how to
> use this macros in C++, but nothing for python.

That note about the RTTI macros was probably picked up automatically from
the C++ headers.  It probably shouldn't be in the wxPython documentation.

It looks like someone has already reported this problem, along with what
needs to be fixed, although it needs to be fixed in the etg scripts.  It's
not clear to me exactly how that should be done, either.

https://github.com/wxWidgets/Phoenix/issues/774

Scott

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Overwritten TreeCtrl.OnCompareItems() not called when using Python3/wxPython4

Thomas Krull
Thanks Scott, I saw the mentioned github issue already. It seems that a new release will not be available very soon. I tried already to sort with a self made SortChildren() but it is awfull slowly.

And you're right: if the RTTI macros are just for the C++ code, somebody should delete it from the Python documantation. I spent a lot of time to search for some tips how to use these macros to get my code running.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.