TreeCtrl GetNextSibling

Hello all,

I loop over items on a tree control using 'GetNextSibling', but when i check if there are more siblings i got an excepction:

h = Tree.GetNextSibling(h)
if h.IsOK() == False:
  
Error: AttributeError: 'TreeItemId' object has no attribute 'IsOK'

The GetNextSibling doc says:

  Returns an invalid tree item if there are no further siblings

but, where is defined de invalid tree item?
How can check if there are more sibligns?

Thanks.

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************

Hi Oswald,

Oswaldo Hernández wrote:

Hello all,

I loop over items on a tree control using 'GetNextSibling', but when i check if there are more siblings i got an excepction:

h = Tree.GetNextSibling(h)

You are checking to late if "h" is a o.k.

if h.IsOK() == False:
    Error: AttributeError: 'TreeItemId' object has no attribute 'IsOK'

What about something along these lines:
        (child, cookie) = tree.GetFirstChild(root)
        while child.IsOk():
            print child
            child = tree.GetNextSibling(child)

Werner

Werner F. Bruhin escribió:

Hi Oswald,

Oswaldo Hernández wrote:

Hello all,

I loop over items on a tree control using 'GetNextSibling', but when i check if there are more siblings i got an excepction:

h = Tree.GetNextSibling(h)

You are checking to late if "h" is a o.k.

if h.IsOK() == False:
    Error: AttributeError: 'TreeItemId' object has no attribute 'IsOK'

What about something along these lines:
       (child, cookie) = tree.GetFirstChild(root)
       while child.IsOk():
           print child
           child = tree.GetNextSibling(child)

Thanks for your reply Werner, but i have the same error:

h = Tree.GetFirstChild(item)[0]
while h.IsOK():
  ....
  h = Tree.GetNextSibling(h)

AttributeError: 'TreeItemId' object has no attribute 'IsOK'

I'm using python 2.5, wx 2.8.0.1 (msw-unicode)
Windows XP
  
???

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************

Hi Oswaldo,

Oswaldo Hernández wrote:

...
while h.IsOK():
    ....
    h = Tree.GetNextSibling(h)

AttributeError: 'TreeItemId' object has no attribute 'IsOK'

You got a case problem it should be:
while h.IsOk():

Werner

Werner F. Bruhin escribió:

Hi Oswaldo,

Oswaldo Hernández wrote:

...
while h.IsOK():
    ....
    h = Tree.GetNextSibling(h)

AttributeError: 'TreeItemId' object has no attribute 'IsOK'

You got a case problem it should be:
while h.IsOk():

Werner

Oops .... Sorry, i put an uppercase 'k'.

Now it's working fine. :slight_smile:

Thanks.

···

--
*****************************************
Oswaldo Hernández
oswaldo (@) soft-com (.) es
*****************************************

Oswaldo Hernández wrote:

Hello all,

I loop over items on a tree control using 'GetNextSibling', but when i check if there are more siblings i got an excepction:

h = Tree.GetNextSibling(h)
if h.IsOK() == False:
    Error: AttributeError: 'TreeItemId' object has no attribute 'IsOK'

It's IsOk with a lower case 'k'. The object also has a __nonzero__ method so you can just check like this:

  if not h:
    # do something

···

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