Endless recursion trying to check all elements of TreeCtrl

I have a TreeCtrl in which more than one item can be assigned the same object as PyData. When the object is updated, I want to update all the items in the tree that have this object as their PyData.

I thought the following code would solve the problem pretty neatly, but for some reason the boolean test (current! = Self.GetFirstVisibleItem ()) always returns true leading to infinite recursion. Can someone explain why?

def RefreshNodes(self, obj, current=None):
    print "Entered refresh"
    current = current or self.GetFirstVisibleItem()
    if current.IsOk():
        print self.GetPyData(current).name
        if self.GetPyData(current) == obj:
            self.RefreshNode(current)
        current = self.GetNextVisible(current)
        if current != self.GetFirstVisibleItem():
            self.RefreshNodes(obj, current)

      

Edit: The above is obviously part of a wx.TreeCtrl based class

0


a source to share


3 answers


I just realized the problem: if the current is not valid, the boolean value is False.



Hence current current = current or self.GetFirstVisibleItem () ends up returning to the first item before current.IsOk () is called ...

0


a source


How will the first item be the first?

This appears to be a tautology. The next is never the first.

    current = self.GetNextVisible(current)

    current != self.GetFirstVisibleItem()

      



It doesn't look like the next one will wrap around to the beginning. It looks like the next one should return an invalid element (IsOk - False) at the end.

See http://wxpython.org/onlinedocs.php for information on this .

+3


a source


There is current != self.GetFirstVisibleItem()

no value for false. See comments below

def RefreshNodes(self, obj, current=None):
    print "Entered refresh"
    current = current or self.GetFirstVisibleItem()
    if current.IsOk():
        print self.GetPyData(current).name
        if self.GetPyData(current) == obj:
            self.RefreshNode(current)

        #current = next visible item
        current = self.GetNextVisible(current)

        #current can't equal the first visible item because
        # it was just set to the next visible item, which 
        # logically cannot be first
        if current != self.GetFirstVisibleItem():   
            self.RefreshNodes(obj, current)

      

+1


a source







All Articles