[wxPython-users] wxTreeCtrl OnCompareItem

Josiah Carlson jcarlson at uci.edu
Sun Aug 6 10:57:48 PDT 2006


Galvin <mygalvin at yahoo.com> wrote:
> 
> class GeneralTreeCtrl(object):
>    def __init__(self, wxTreeCtrl):
>       self.tree = wxTreeCtrl
> 
>    def __getattr__(self, name):
>        return self.tree.__getattribute__(name)
> 
> 
> class TreeCtrl(GeneralTreeCtrl):
>    #inherit from GeneralTreeCtrl
>    def __init__(self, wxTreeCtrl):
>       GeneralTreeCtrl.TreeCtrl.__init__(self, wxTreeCtrl)
> 
> How do I override the OnCompareItems if my TreeCtrl classes are like above?
> TreeCtrl is inherited from GeneralTreeCtrl, but GeneralTreeCtrl doesn't inherit
> from wxTreeCtrl.
> 
> My classes are in such a away because I use GUI designer. After the layout
> stage, then only I wrap the wxTreeCtrl using my class, this allow me not to
> change the wxTreeCtrl attribues set in the designer.

According to my experience with wxPython, you shouldn't be able to add
either of the above as visual elements in any wxPython application. Why?
Simply beacuse neither TreeCtrl nor GeneralTreeCtrl subclass from
wx.Control.

If you want to use the output from some designer application, there are
other, better ways.  Say, for example, that the output of your GUI
designer was a class called TreeCtrl in a file called CustomTreeCtrl.py

In the file that you write, you can do the following...

import CustomTreeCtrl

class TreeCtrl(CustomTreeCtrl.TreeCtrl):
    def __init__(self, ...):
        CustomTreeCtrl.TreeCtrl.__init__(self, ...)
        ...
    ...


You can then override methods as necessary, add functionality as
necessary, etc.  If you ever need to call a method of the
CustomTreeCtrl.TreeCtrl class, you can do precisely as you did with the
__init__ call...

    CustomTreeCtrl.TreeCtrl.BaseMethod(self, ...)


 - Josiah





More information about the wxpython-users mailing list