Hello all,
I'm new to wxpython programming, and i don't understand why my callback
function don't work !
···
##############################################################
def OnColonneClick(self, event): # wxGlade: MyFrame1.<event_handler>
# self.col = event.m_col
self.list_ctrl_1.SortItems(self.ColumnSorter)
event.Skip()
def ColumnSorter(self, key1, key2):
item1 = self.list_ctrl_1.GetItem(key1, 0).GetText()
item2 = self.list_ctrl_1.GetItem(key2, 0).GetText() #avant 0 était
self.col
#print key1, key2
if item1 < item2: return -1
else: return 1
##############################################################
It seems that key1 and key2 never change during the procedure ...
is it necessary to stock the listctrl data in a separate list to let
work the callback function on a fixed list ??
I search on google but i don't find something realy clear...
If you have a good link : tutorial, samples,... about that subject ....
Thanck you very much in advance,
Geoffroy Culot
def OnColonneClick(self, event): # wxGlade: MyFrame1.<event_handler>
# self.col = event.m_col
self.list_ctrl_1.SortItems(self.ColumnSorter)
event.Skip()
def ColumnSorter(self, key1, key2):
In fact, key1 and key2 that are passed to your ColumnSorter() callback
function are not indexes of items being compared.
key1 is client data of 1st item, key2 is client data of 2nd item. You assign
client data to items by yourself using ListCtrl::SetItemData.
Unfortunately ListCtrl does not have SetPyData, so you can only assign numbers
to items.
Simple solution for sorting may look like this:
You assign different numbers to items. Then you create mapping (dictionary)
with keys equal these numbers and values of items' text.
For example you create dict 'labels' with content like this: {0:"item1",
1:"item2", 2:"item3"}
Then you write ColumnSorter(self, key1, key2):
if labels[key1] > labels[key2]:
... and so on
A bit complicated, but that's the way it works 
Also you can checkout ColumnSorterMixin. It is something to automate sorting
by columns a little bit.
Hello Piotr,
Thank you very much for your answer !
Now, I have a better view of the problem. I will try in this way.
Friendly,
Geoffroy Culot