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 #----------------------------------------------------------------------------
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'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 #----------------------------------------------------------------------------
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!
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.
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
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).
2008/11/11 Andrea Gavana <andrea.gavana@gmail.com>:
Sorry for the late reply, I have quite a lot of work in this period
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.
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 #----------------------------------------------------------------------------
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?
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 #----------------------------------------------------------------------------
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?
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).
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).
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).
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).