TreeListCtrl

I can't figure out how to get the first child in a treelist.

Googled and checked the wiki and the demo but don't see a sample for this.

i.e. want to use this:

tree.GetFirstChild(0)

But whatever I fee to GetFirstChild it complains that it wants a wxTreeItemId, but I can't figure out how to pass that to it (also the doc for it says: "wxTreemItemIds are not meant to be constructed explicitly by the user....".

Any hints would be very much appreciated.
Werner

werner wrote:

I can't figure out how to get the first child in a treelist.

Googled and checked the wiki and the demo but don't see a sample for this.

i.e. want to use this:

tree.GetFirstChild(0)

But whatever I fee to GetFirstChild it complains that it wants a
wxTreeItemId, but I can't figure out how to pass that to it (also the
doc for it says: "wxTreemItemIds are not meant to be constructed
explicitly by the user....".

Any hints would be very much appreciated.
Werner

When you call AddRoot/AppendItem/InsertItem/InsertItemBefore, it returns
a TreeItemId. Keep a reference to these (a list is nice, I find) and
then pass whichever ItemId you want to GetFirstChild

Hi,

2009/11/27 Steven Sproat:

werner wrote:

I can't figure out how to get the first child in a treelist.

Googled and checked the wiki and the demo but don't see a sample for this.

i.e. want to use this:

tree.GetFirstChild(0)

But whatever I fee to GetFirstChild it complains that it wants a
wxTreeItemId, but I can't figure out how to pass that to it (also the
doc for it says: "wxTreemItemIds are not meant to be constructed
explicitly by the user....".

Any hints would be very much appreciated.
Werner

When you call AddRoot/AppendItem/InsertItem/InsertItemBefore, it returns
a TreeItemId. Keep a reference to these (a list is nice, I find) and
then pass whichever ItemId you want to GetFirstChild

Don't do this unless you are using HyperTreeList.

"""
The wx.TreeItemId is a temporary opaque object that can *only* be used
for passing to/from treectl methods. It has no other utility, and due
to it's nature as a proxy to a C++ object you won't even get the same
Python instance for the same tree item the next time around.
"""

Instead, you should use the GetFirstChild/GetNextChild method of
treelistctrl, so if you want the very first child (of the root, I
suppose), just do this:

root = yourTreeList.GetRoot()
firstChild, cookie = yourTreeList.GetFirstChild(root)

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

Andrea,

...

root = yourTreeList.GetRoot()
firstChild, cookie = yourTreeList.GetFirstChild(root)

This put me on the right track.

Thanks
Werner

Following just for the archive if anyone else is running into this. I wanted to get to the first item where itemData[2] is not None (i.e. has an imageKey in my case).

            root = tree.GetRootItem()
            itemId, itemCookie = tree.GetFirstChild(root)
            if itemId.IsOk():
                itemData = tree.GetItemPyData(itemId)
            else:
                itemData = (None, None, None)

            while itemData[2] == None:
                itemId = tree.GetNext(itemId)
                if itemId.IsOk():
                    itemData = tree.GetItemPyData(itemId)
                else:
                    itemData = (None, None, None)
                    break

            if itemData[2]:
                tree.SelectItem(itemId, itemId, False)
                self.ShowImage(itemData[2])

Andrea Gavana wrote:

Hi,

2009/11/27 Steven Sproat:
  

werner wrote:
    

I can't figure out how to get the first child in a treelist.

Googled and checked the wiki and the demo but don't see a sample for this.

i.e. want to use this:

tree.GetFirstChild(0)

But whatever I fee to GetFirstChild it complains that it wants a
wxTreeItemId, but I can't figure out how to pass that to it (also the
doc for it says: "wxTreemItemIds are not meant to be constructed
explicitly by the user....".

Any hints would be very much appreciated.
Werner

When you call AddRoot/AppendItem/InsertItem/InsertItemBefore, it returns
a TreeItemId. Keep a reference to these (a list is nice, I find) and
then pass whichever ItemId you want to GetFirstChild
    
Don't do this unless you are using HyperTreeList.

"""
The wx.TreeItemId is a temporary opaque object that can *only* be used
for passing to/from treectl methods. It has no other utility, and due
to it's nature as a proxy to a C++ object you won't even get the same
Python instance for the same tree item the next time around.
"""

Instead, you should use the GetFirstChild/GetNextChild method of
treelistctrl, so if you want the very first child (of the root, I
suppose), just do this:

root = yourTreeList.GetRoot()
firstChild, cookie = yourTreeList.GetFirstChild(root)

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

But what about when you want to insert an item into node, say, #6? How do you do that without a reference to its TreeItemId -- iterate over the whole tree, counting for the node you're looking for?

···

--
Steven Sproat, BSc
http://www.basicrpg.com/

Hi,

2009/11/27 Steven Sproat:

Andrea Gavana wrote:

Hi,

2009/11/27 Steven Sproat:

werner wrote:

I can't figure out how to get the first child in a treelist.

Googled and checked the wiki and the demo but don't see a sample for this.

i.e. want to use this:

tree.GetFirstChild(0)

But whatever I fee to GetFirstChild it complains that it wants a
wxTreeItemId, but I can't figure out how to pass that to it (also the
doc for it says: "wxTreemItemIds are not meant to be constructed
explicitly by the user....".

Any hints would be very much appreciated.
Werner

When you call AddRoot/AppendItem/InsertItem/InsertItemBefore, it returns
a TreeItemId. Keep a reference to these (a list is nice, I find) and
then pass whichever ItemId you want to GetFirstChild

Don't do this unless you are using HyperTreeList.

"""
The wx.TreeItemId is a temporary opaque object that can *only* be used
for passing to/from treectl methods. It has no other utility, and due
to it's nature as a proxy to a C++ object you won't even get the same
Python instance for the same tree item the next time around.
"""

Instead, you should use the GetFirstChild/GetNextChild method of
treelistctrl, so if you want the very first child (of the root, I
suppose), just do this:

root = yourTreeList.GetRoot()
firstChild, cookie = yourTreeList.GetFirstChild(root)

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/

But what about when you want to insert an item into node, say, #6? How
do you do that without a reference to its TreeItemId -- iterate over the
whole tree, counting for the node you're looking for?

This is one of the reason why I swapped all the instances of
wx.TreeCtrl with CustomTreeCtrl and TreeListCtrl with HyperTreeList in
my proprietary applications. There might be an easy way to do what you
ask, but if there is, I have long forgotten it.

CustomTreeCtrl and HyperTreeList might be slightly slower than their
C++ counterparts (mainly due to the fact that they are pure-Python and
Python is notoriously slower in function calls and for/while loops),
but using them the improvement in "programmability" is enormous and I
have never looked back since then. Moreover, my very first tests with
the first (unoptimized) version of CustomTreeCtrl revealed that it is
close to 5% slower than wx.TreeCtrl, and I usually don't bother about
these things in UI elements, only in heavy number crunching
procedures, but for those I always fall back to numpy (good), scipy
(less good) and Fortran via f2py (super good).

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

It should be okay to hold on to a wx.TreeItemId, as long as you don't try to use it after that node in the treectrl has been deleted or moved.

···

On 11/27/09 1:50 AM, Andrea Gavana wrote:

When you call AddRoot/AppendItem/InsertItem/InsertItemBefore, it returns
a TreeItemId. Keep a reference to these (a list is nice, I find) and
then pass whichever ItemId you want to GetFirstChild

Don't do this unless you are using HyperTreeList.

"""
The wx.TreeItemId is a temporary opaque object that can *only* be used
for passing to/from treectl methods. It has no other utility, and due
to it's nature as a proxy to a C++ object you won't even get the same
Python instance for the same tree item the next time around.
"""

--
Robin Dunn
Software Craftsman