[wxPython-users] Re: Re: Sorted List Control - how?
Werner F. Bruhin
werner.bruhin at free.fr
Tue Dec 12 04:09:53 PST 2006
Hi Donn,
Donn Ingle wrote:
>> A "callable object" doesn't have to be a class with a __call__ method.
>> It is anything that can be called, IOW, any foo for which foo(a,b) is
>> possible.
>>
> Robin,
> If all that ca get passed to foo is a and b - which are numbers assigned
> during a SetItemData call, how can one achieve an alphabetical sort?
>
> I mean - let's assume everything I put into the listctrl up-front gets the
> numbers 1 to 10 as the items go into it; later-on I want to add a new item.
> How do I know what number to give the new item such that it will sort into
> the listctrl?
> Let's say the new item should fit between 3 and 4 in the list. How do I know
> this?
>
> It seems like I have to keep a separate list, add the new item, sort the
> list and then go through it and re-number each item (perhaps each item is
> stored in a tuple) and then go through the listcontrol and re-number each
> item there (by a SetItemData) from my separate list and then call
> SortItems(foo). No?
>
> Feeling thick today ;)
> /d
>
>
To me it is magic and it took me some time to figure out the basics of it.
I suggest that you put some print statements into the method
__ColumnSorter in lib/mixins/listctrl.py and then run the demo.
You will see that item1 and item2 is the thing being sorted (text, int
etc) and the key1 and key2 is the unique value you put into ClientData.
Werner
More information about the wxpython-users
mailing list