[wxPython-users] CustomTreeCtrl windows added via SetWindow aren't properly handled

Mike Rooney mxr at qvii.com
Tue Jul 17 09:51:07 PDT 2007


Andrea Gavana wrote:
> Hi Mike,
>
> On 7/11/07, Mike Rooney wrote:
>> I am using a CustomTreeCtrl, and I have noticed that if I use the
>> SetWindow method of a GenericTreeItem, the window isn't hidden if any of
>> the parents are collapsed. Is this a bug or do I just not understand why
>> this might be expected?
>
> Sorry for the late reply. Yes, it looks like a bug, I will investigate
> tomorrow and I will let you know. Actually, I believe your solution to
> add a simple method to CustomTreeCtrl is the best one, and I am going
> to implement it and send a patch to Robin. It shouldn't take that
> long, work permitting :-D
>
>

Great! I noticed DeleteWindow on a GenericTreeItem also has the same 
issue but in reverse. The item never gets /removed /from the tree's 
_itemWithWindow, so later it will crash when you remove the item if you 
had previously properly added the window (say via SetItemWindow, or 
passed it in initially on item creation). From 'Delete' in 
CustomTreeCtrl [~#3433]:

        # Remove the item with window
        if item in self._itemWithWindow:
            wnd = item.GetWindow()
            wnd.Hide()

If you previously used item.DeleteWindow, item.GetWindow will return 
None, and you will get an exception on the next line that NoneType has 
no attribute Hide. So I guess we also need a DeleteItemWindow in 
CustomTreeCtrl which removes the item from _itemWithWindow.

Once those are there, SetWindow and DeleteWindow on a GenericTreeItem 
should probably not be "public" anymore, right (have underscores 
appended to the method names)?

Though it seems a shame to lose these methods on the items themselves. 
One of the nicest things about going from a TreeCtrl to a CustomTreeCtrl 
for me was being able to call so many methods right on the tree items 
themselves. You can just pass them around as you please and perform many 
useful operations without worrying about also having the tree object 
available. Though, I don't see any particularly elegant way to 
accomplish this. Oh well!

PS - Is the below method how you implemented SetItemWindow? It seems to 
work well but I don't want to make any silly mistakes.

    def SetItemWindow(self, item, wnd):
        """Sets the window for the given item"""
       
        if wnd is not None:
            self._hasWindows = True
            if not item in self._itemWithWindow:
                self._itemWithWindow.append(item)
               
        item.SetWindow(wnd)

Thanks again,
Mike Rooney




More information about the wxpython-users mailing list