Hi Jeff,
hello again, I can't seem to get this sorting function to work. my tree has
a root item and three children. I call treeCtrl.SortChildren(parentItem),
where parentItem is the root, and I get the following message:'C++ assertion "wxAssertFailure" failed in
..\..\src\msw\treectrl.cpp(2176): sorting tree without data
doesn't make sense'
I am sure this is some kind of Windows quirks. What the hell of a
message is it? It's *my* duty to decide what makes sense or not!
In any case, the message is misleading. It does make sense sorting
tree items, basically because you sort them in alphabetical order or
with other custom sorting routines that don't need to have the data
stored in the items.
Anyway, I am barking. To solve your problem, try to do something like this:
for indx, text in enumerate(myItemTexts):
newItem = theTreeControl.AppendItem(parentItem, text)
theTreeControl.SetPyData(newItem, indx)
Or something along these lines (warning: highly untested!).
I'm not sure what this means. Also, just to clarify since I'm kinda a
newbie, when you say to add the function 'OnCompareItems' to my treeCtrl
class, I am assuming this is the _control.py module and the class is:class TreeCtrl(_core.Control):
"""Proxy of C++ TreeCtrl class"""
No, don't do that!
I have assumed that you had subclassed wx.TreeCtrl in your class,
something like:
class MyTreeCtrl(wx.TreeCtrl):
def __init__(self, parent, id, pos, size, style):
wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
def OnCompareItems(self, item1, item2):
t1 = self.GetItemText(item1)
t2 = self.GetItemText(item2)
if t1 < t2: return -1
if t1 == t2: return 0
return 1
In that case, your OnCompareItems method is called when you sort your
items in the tree. Sorry for the confusion my post arose. Does it make
sense now?
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/
···
On 5/15/07, Jeff Peery wrote: