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
a source to share
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 .
a source to share
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)
a source to share