Welcome, guest | Sign In | My Account | Store | Cart

This recipe allows you to iterate over the children of an item in a wxTreeCtrl without having to fool around with GetFirstChild/GetNextChild/cookie boilerplate.

Python, 10 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def iterchildren(treectrl, node):
    cid, citem = treectrl.GetFirstChild(node)
    while cid.IsOk(): 
        yield cid
        cid, citem = treectrl.GetNextChild(node, citem)


# sample usage
for i in iterchildren(myTreeControl, someNode):
    print myTreeControl.GetItemText(i)

I wrote this generator to avoid the copying/pasting/editing of boilerplate code to iterate over the children of an item in a wxTreeCtrl. Since I haven't run across a similar example, I thought I'd share it here.

Created by Alan McIntyre on Sat, 23 Apr 2005 (PSF)
Python recipes (4591)
Alan McIntyre's recipes (2)

Required Modules

  • (none specified)

Other Information and Tasks