HyperTreeList and inheritance

Hi,

I'm trying to incorporate Andrea's HyperTreeList control in Task
Coach. However, Andrea implemented delegation of the methods in the
_methods list to the inner TreeListMainWindow as follows:

···

#----------------------------------------------------------------------------
# TreeListCtrl - the multicolumn tree control
#----------------------------------------------------------------------------

_methods = ["GetIndent", "SetIndent", "GetSpacing", "SetSpacing",
"GetImageList", "GetStateImageList",
            "GetButtonsImageList", ..., ...]

class HyperTreeList(wx.PyControl):
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize,
                 style=wx.TR_DEFAULT_STYLE,
validator=wx.DefaultValidator, name="HyperTreeList"):
        ...
        self._main_win = TreeListMainWindow(self, -1, wx.Point(0, 0),
size, main_style, validator)
        ...
        for method in _methods:
            setattr(self, method, getattr(self._main_win, method))

This makes it impossible for me to override the methods in _methods in
the normal way. I'm looking for a solution (besides not inheriting
from HyperTreeList at all). Would moving the for loop to the __new__
method of HyperTreeList be a solution? Or might there be another
solution?

Thanks, Frank

Frank Niessink wrote:

Hi,

I'm trying to incorporate Andrea's HyperTreeList control in Task
Coach. However, Andrea implemented delegation of the methods in the
_methods list to the inner TreeListMainWindow as follows:

#----------------------------------------------------------------------------
# TreeListCtrl - the multicolumn tree control
#----------------------------------------------------------------------------

_methods = ["GetIndent", "SetIndent", "GetSpacing", "SetSpacing",
"GetImageList", "GetStateImageList",
            "GetButtonsImageList", ..., ...]

class HyperTreeList(wx.PyControl):
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize,
                 style=wx.TR_DEFAULT_STYLE,
validator=wx.DefaultValidator, name="HyperTreeList"):
        ...
        self._main_win = TreeListMainWindow(self, -1, wx.Point(0, 0),
size, main_style, validator)
        ...
        for method in _methods:
            setattr(self, method, getattr(self._main_win, method))

This makes it impossible for me to override the methods in _methods in
the normal way. I'm looking for a solution (besides not inheriting
from HyperTreeList at all). Would moving the for loop to the __new__
method of HyperTreeList be a solution? Or might there be another
solution?

You could always do something similar in your derived class, reassigning the attributes to your methods.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

Frank Niessink wrote:

This makes it impossible for me to override the methods in _methods in
the normal way. I'm looking for a solution (besides not inheriting
from HyperTreeList at all). Would moving the for loop to the __new__
method of HyperTreeList be a solution? Or might there be another
solution?

You could always do something similar in your derived class, reassigning the
attributes to your methods.

Hmm, sounds awfully complicated. I just want to override a method
without jumping through hoops. One of the attractive aspects of
HyperTreeList is that its interface is similar to the other tree
controls and that advantage would get lost if I have to work around
this issue.

I was more looking for what could be changed in HyperTreeList that 1)
doesn't involve manually forwarding methods from HyperTreeList to
TreeListMainWindow but 2) does allow for overriding/extending those
forwarded methods.

Thanks, Frank

···

2008/11/10 Robin Dunn <robin@alldunn.com>:

Hi Frank,

Hi Robin,

Frank Niessink wrote:

This makes it impossible for me to override the methods in _methods in
the normal way. I'm looking for a solution (besides not inheriting
from HyperTreeList at all). Would moving the for loop to the __new__
method of HyperTreeList be a solution? Or might there be another
solution?

You could always do something similar in your derived class, reassigning the
attributes to your methods.

Hmm, sounds awfully complicated. I just want to override a method
without jumping through hoops. One of the attractive aspects of
HyperTreeList is that its interface is similar to the other tree
controls and that advantage would get lost if I have to work around
this issue.

I was more looking for what could be changed in HyperTreeList that 1)
doesn't involve manually forwarding methods from HyperTreeList to
TreeListMainWindow but 2) does allow for overriding/extending those
forwarded methods.

Sorry for the late reply, I have quite a lot of work in this period :frowning:
I can't really think of an elegant solution right now: the only
possibility I can imagine (and I do not know if this is possible), is
to check whether the inheriting class (i.e., the super class you use
to subclass HyperTreeList) is overloading some of the methods, and
exclude them from the _methods list during __init__. I am not sure it
will work, and I don't know how to do it, but it may be a possible
solution...

I am open to suggestions, as always. HyperTreeList now lives in
wxPython SVN in the AGW package, so support from my part is guaranteed
(:-D).

Andrea.

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

···

On Mon, Nov 10, 2008 at 8:11 PM, Frank Niessink wrote:

2008/11/10 Robin Dunn <robin@alldunn.com>:

Hi Andrea,

···

2008/11/11 Andrea Gavana <andrea.gavana@gmail.com>:

Sorry for the late reply, I have quite a lot of work in this period :frowning:
I can't really think of an elegant solution right now: the only
possibility I can imagine (and I do not know if this is possible), is
to check whether the inheriting class (i.e., the super class you use
to subclass HyperTreeList) is overloading some of the methods, and
exclude them from the _methods list during __init__. I am not sure it
will work, and I don't know how to do it, but it may be a possible
solution...

I think the best solution is not to create the delegation methods in
__init__ but
rather during class construction. I'll try to create a patch.

Thanks, Frank

I have been trying to create a patch for HyperTreeList that would
allow for overriding methods but I haven't been succesful. I thought
that some metaclass trickery would help, but alas, I'm not smart
enough. The only option I see is to simply spell out the delegated
methods in _methods. Or am I missing something?

Thanks, Frank

···

2008/11/8 Frank Niessink <frank@niessink.com>:

Hi,

I'm trying to incorporate Andrea's HyperTreeList control in Task
Coach. However, Andrea implemented delegation of the methods in the
_methods list to the inner TreeListMainWindow as follows:

#----------------------------------------------------------------------------
# TreeListCtrl - the multicolumn tree control
#----------------------------------------------------------------------------

_methods = ["GetIndent", "SetIndent", "GetSpacing", "SetSpacing",
"GetImageList", "GetStateImageList",
"GetButtonsImageList", ..., ...]

class HyperTreeList(wx.PyControl):
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.TR_DEFAULT_STYLE,
validator=wx.DefaultValidator, name="HyperTreeList"):
...
self._main_win = TreeListMainWindow(self, -1, wx.Point(0, 0),
size, main_style, validator)
...
for method in _methods:
setattr(self, method, getattr(self._main_win, method))

This makes it impossible for me to override the methods in _methods in
the normal way. I'm looking for a solution (besides not inheriting
from HyperTreeList at all). Would moving the for loop to the __new__
method of HyperTreeList be a solution? Or might there be another
solution?

Can't you do something like

class HyperTreeList(wx.PyControl):
     def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
               ....

for method in _methods:
     setattr( HyperTreeList, method, lambda self, *args, **keys: getattr(self._main_win, method)( self, *args, **keys ) )

Then the methods are part of the HyperTreeList class instead of a HyperTreeList instance and you should be able to inherit from them, no?

-Matthias

···

Am 20.04.2009, 22:08 Uhr, schrieb Frank Niessink <frank@niessink.com>:

2008/11/8 Frank Niessink <frank@niessink.com>:

Hi,

I'm trying to incorporate Andrea's HyperTreeList control in Task
Coach. However, Andrea implemented delegation of the methods in the
_methods list to the inner TreeListMainWindow as follows:

#----------------------------------------------------------------------------
# TreeListCtrl - the multicolumn tree control
#----------------------------------------------------------------------------

_methods = ["GetIndent", "SetIndent", "GetSpacing", "SetSpacing",
"GetImageList", "GetStateImageList",
"GetButtonsImageList", ..., ...]

class HyperTreeList(wx.PyControl):
def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
size=wx.DefaultSize,
style=wx.TR_DEFAULT_STYLE,
validator=wx.DefaultValidator, name="HyperTreeList"):
...
self._main_win = TreeListMainWindow(self, -1, wx.Point(0, 0),
size, main_style, validator)
...
for method in _methods:
setattr(self, method, getattr(self._main_win, method))

This makes it impossible for me to override the methods in _methods in
the normal way. I'm looking for a solution (besides not inheriting
from HyperTreeList at all). Would moving the for loop to the __new__
method of HyperTreeList be a solution? Or might there be another
solution?

I have been trying to create a patch for HyperTreeList that would
allow for overriding methods but I haven't been succesful. I thought
that some metaclass trickery would help, but alas, I'm not smart
enough. The only option I see is to simply spell out the delegated
methods in _methods. Or am I missing something?

Hi Matthias,

hypertreelist.patch.txt (641 Bytes)

···

2009/4/20 Nitro <nitro@dr-code.org>:

Can't you do something like

for method in _methods:
setattr( HyperTreeList, method, lambda self, *args, **keys:
getattr(self._main_win, method)( self, *args, **keys ) )

Then the methods are part of the HyperTreeList class instead of a
HyperTreeList instance and you should be able to inherit from them, no?

Thanks. This worked almost, but it was enough to get a working
solution, see attached diff.

Andrea, is the attached diff sufficient or do you need a real patch?

Cheers, Frank

Hi Andrea,

···

2009/4/22 Frank Niessink <frank@niessink.com>:

Andrea, is the attached diff sufficient or do you need a real patch?

Here's a context diff that also contains a new InsertColumn method. I
renamed the existing InsertColumn to InsertColumnInfo to be more
consistent with AddColumn/AddColumnInfo (and to be more consistent
with TreeListCtrl).

Cheers, Frank

And this time with attachment.

Cheers, Frank

hypertreelist.patch.txt (2.15 KB)

···

2009/4/22 Frank Niessink <frank@niessink.com>:

Hi Andrea,

2009/4/22 Frank Niessink <frank@niessink.com>:

Andrea, is the attached diff sufficient or do you need a real patch?

Here's a context diff that also contains a new InsertColumn method. I
renamed the existing InsertColumn to InsertColumnInfo to be more
consistent with AddColumn/AddColumnInfo (and to be more consistent
with TreeListCtrl).

And now without the typo (sorry for being sloppy).

Cheers, Frank

hypertreelist.patch.txt (2.15 KB)

···

2009/4/22 Frank Niessink <frank@niessink.com>:

2009/4/22 Frank Niessink <frank@niessink.com>:

Hi Andrea,

2009/4/22 Frank Niessink <frank@niessink.com>:

Andrea, is the attached diff sufficient or do you need a real patch?

Here's a context diff that also contains a new InsertColumn method. I
renamed the existing InsertColumn to InsertColumnInfo to be more
consistent with AddColumn/AddColumnInfo (and to be more consistent
with TreeListCtrl).

And this time with attachment.

Hi Frank & All,

···

On Wed, Apr 22, 2009 at 10:26 PM, Frank Niessink wrote:

2009/4/22 Frank Niessink <frank@niessink.com>:

2009/4/22 Frank Niessink <frank@niessink.com>:

Hi Andrea,

2009/4/22 Frank Niessink <frank@niessink.com>:

Andrea, is the attached diff sufficient or do you need a real patch?

Here's a context diff that also contains a new InsertColumn method. I
renamed the existing InsertColumn to InsertColumnInfo to be more
consistent with AddColumn/AddColumnInfo (and to be more consistent
with TreeListCtrl).

And this time with attachment.

And now without the typo (sorry for being sloppy).

I have applied the patch in SVN, thank you!

Andrea.

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