[wxPython] wxTreeCtrl question

hi, i am writing an app where a treeCtrl may sometimes need to be destroyed and recreated (with minimal changes). that’s fine, but what if i want to be real clever and have the re-created treeCtrl appear with the last-selected item expanded?

i have tried this with something like:

def onReload(self, event):
‘reload all the xmldata’
xmlData = self.getXMLData(reload=1)
if self.parentsTreeFrame and self.parentsTreeFrame.IsShown():
selection = self.parentsTreeFrame.tree.GetSelection()
data = self.parentsTreeFrame.tree.GetPyData(selection)
#print self.parentsTreeFrame.tree.GetPyData(selection).GetId()
id = wxTreeItemData(data).GetId()
#print selection, data, id

self.onCloseParentTreeWindow()
self.showParentsTreeFrame(event=None, reload=0)
if selection:
self.parentsTreeFrame.tree.EnsureVisible(id)

to attempt to get this to work, i had to associate wxTreeItemData objects with each node in the tree. something like:

localNode = tree.AppendItem(parentNode, encodedName, 1, -1, wxTreeItemData(u.getID()))

anway, that does not seem to work. i guess the wxTreeItem pointer changes when i reconstruct the tree, so trying to select by recreating that from an old wxTreeItemData object doesn’t seem to work. is there another way of doing this? am i way off course here?

thanks,

andrew

Can't you avoid destroying and recreating the tree,
instead just modifying the items you need to change?
I realize that it's probably easier to rebuild it
from scratch than to traverse it and see where we need
to add or remove nodes, but I think this is the way
to go.

···

At 13:40 2002-09-20 -0700, Andrew Yinger wrote:

hi, i am writing an app where a treeCtrl may sometimes need to be destroyed and recreated (with minimal changes). that's fine, but what if i want to be real clever and have the re-created treeCtrl appear with the last-selected item expanded?

--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

i wish it was that easy -- i have reparse the xml and recreate the tree from
scratch. unfortunately, there is no way around this -- the xml parsing is
extremely flexible and allows for a complete redefinition of the tree.

···

----- Original Message -----
From: "Magnus Lycka" <magnus@thinkware.se>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, September 20, 2002 2:18 PM
Subject: Re: [wxPython] wxTreeCtrl question

At 13:40 2002-09-20 -0700, Andrew Yinger wrote:
>hi, i am writing an app where a treeCtrl may sometimes need to be
>destroyed and recreated (with minimal changes). that's fine, but what if
>i want to be real clever and have the re-created treeCtrl appear with the
>last-selected item expanded?

Can't you avoid destroying and recreating the tree,
instead just modifying the items you need to change?
I realize that it's probably easier to rebuild it
from scratch than to traverse it and see where we need
to add or remove nodes, but I think this is the way
to go.

--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

Ok, this worked with 2.3.2, but fails with 2.3.3.
Windows 2000 and Python 2.2.1.

I'm in the middle of a wxGrid, and press PageUp.

I then get:
...dynarray.h(468): assert "uiIndex < m_nCount" failed,
followed by unknown s/w exception in python.exe :frowning:

I synchronize grids, and for that reason I use
custom scrollbars events, but I don't know if
that matters. (Perhaps. The demo seems to work.)

Anyway, on idle I call "self.GetGridCursorRow()"
and it will happily return "-9".

I think it's when I do grid.GetCellValue() from
row -9 that I get the assert error.

I can easily avoid that by setting my stored
row number attribute to max(self.GetGridCursorRow(),0)
but it's still wrong...

My cursor disappears, and after pressing down-arrow
a few times it will reappear in row 0...

:frowning:

···

--
Magnus Lyckå, Thinkware AB
Älvans väg 99, SE-907 50 UMEÅ
tel: 070-582 80 65, fax: 070-612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se

Magnus Lycka wrote:

Ok, this worked with 2.3.2, but fails with 2.3.3.
Windows 2000 and Python 2.2.1.

I'm in the middle of a wxGrid, and press PageUp.

I then get:
...dynarray.h(468): assert "uiIndex < m_nCount" failed,
followed by unknown s/w exception in python.exe :frowning:

Earlier today I made a fix for what is probably a different manifestation of this same problem. <sigh> Looks like I'll be doing a 2.3.3.2 sooner than I expected...

···

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