Expanding a TreeCtrl with hidden root?

Hello list,

I need a TreeCtrl to be completely expanded, always. After creating
and populating the TreeCtrl, I called OnExpandAll:
http://wiki.wxpython.org/index.cgi/expand_20all_20wxTreeCtrl_20items

But the line below (on the 'traverse' method) raises an error (3 arguments
were passed instead of 2):
   firstchild, cookie = self.tree.GetFirstChild(traverseroot, cookie)

However, this works fine (when the control is created without a
wx.TR_HIDE_ROOT style):
   firstchild, cookie = self.tree.GetFirstChild(traverseroot)

But if the control is created with a wx.TR_HIDE_ROOT style,
another error is raised saying that I'm not able to expand a hidden
root.

So my questions are: why GetFirstChild works without the cookie
argument and how should I expand all items on a TreeCtrl created with a
wx.TR_HIDE_ROOT style?

[Python 2.3.3, wxPython 2.5.1.5, Win XP]

Thanks in advance,

-- tacao

E. A. Tacao wrote:

So my questions are: why GetFirstChild works without the cookie
argument

This is in the current MigrationGuide, but unfortunately I didn't think to put it in there until I was reminded about it after the release :frowning:

"""
wx.TreeCtrl.GetFirstChild no longer needs to be passed the cookie
variable as the 2nd parameter. It still returns it though, for use
with GetNextChild.
"""

This was one of the "ugly hacks" that I cleaned up in the move to 2.5. Previously in 2.3 and 2.4 I had tried to make the cookie parameter optional because there is really no need for it as an input parameter in GetFirstChild, but it woudl sometimes cause crashes if it wasn't passed. So I rewrote things so it wouldn't be needed at all.

and how should I expand all items on a TreeCtrl created with a
wx.TR_HIDE_ROOT style?

The native Windows tree control won't let you do anything with the root item if it is hidden, except add children. What you should probably do instead is keep track of the top level nodes yourself and then iterate over each of them when doing the expanding.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!