[wxPython-users] TreeCtrl GetNextVisible
Saketh Bhamidipati
saketh.bhamidipati at gmail.com
Fri Sep 1 09:36:32 PDT 2006
On 9/1/06, Robin Dunn <robin at alldunn.com> wrote:
>
> Saketh Bhamidipati wrote:
> > A method of mine iterates through a TreeCtrl and writes data to an XML
> > file using ElementTree. In order to move the iterator forward, I use
> > GetNextVisible. When writing this method, I did not know that the node
> > actually has to be visible for GetNextVisible to return it. This is
> > causing problems for me now that I have many nodes in a TreeCtrl that
> > require a scrollbar.
> >
> > I still want to iterate through the TreeCtrl, but without the major
> > issue that all nodes must be visible for the iteration to work.
> >
>
> Use GetFirstChild/GetNextChild.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
> I got it to work with this code:
while current.IsOk():
new =3D None
if current =3D=3D self.tree.GetRootItem():
new =3D self.tree.GetFirstChild(current)
else:
new =3D self.tree.GetNextSibling(current)
current =3D new
if not current.IsOk(): break
# Start translating the data
new =3D SubElement(root, "node")
new.set("title", unicode(self.tree.GetItemText
(current)).encode('utf8'))
data =3D SubElement(new, "data")
datatext =3D unicode(self.tree.GetPyData(current)).encode('utf8=
')
if datatext =3D=3D 'None':
datatext =3D "" # Again, we don't want it to litera=
lly
write 'None'
data.text =3D datatext
tree =3D ElementTree(root)
tree.write(unicode(filename))
But I have a problem - if the user minimizes the root node, nothing but the
root node gets written. How can I fix this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200609=
01/ae88f1f1/attachment.htm
More information about the wxpython-users
mailing list