[wxPython] Reading Data from List Control

I have a list control with three columns. I would
like to be able to read the information on any given
column of the selected item. However, the GetItemText
method only accepts two parameters (self, and the Item
index). This only gives me the text of the first
column. How can one read the text of the other
columns? Will appreciate any help.

-Ruben

···

__________________________________________________
Do You Yahoo!?
Yahoo! Calendar - Get organized for the holidays!
http://calendar.yahoo.com/
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Ruben Marquez wrote:

I have a list control with three columns. I would
like to be able to read the information on any given
column of the selected item. However, the GetItemText
method only accepts two parameters (self, and the Item
index). This only gives me the text of the first
column. How can one read the text of the other
columns? Will appreciate any help.

I asked the same question about 2 weeks ago, and I didn't get a response. I was mainly interested in sorting the list based on which column was clicked. I had to maintain a seperate 2 dimensional list, sort it appropriately, and then place the data back into the listCtrl. It would be nice if the C++ wxListCtrl had a method to sort based on a column. It would also be very beneficial to be able to read any row/column data.

Brendan Simon.

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Ruben Marquez wrote:

> I have a list control with three columns. I would
> like to be able to read the information on any given
> column of the selected item. However, the GetItemText
> method only accepts two parameters (self, and the Item
> index). This only gives me the text of the first
> column. How can one read the text of the other
> columns? Will appreciate any help.

I asked the same question about 2 weeks ago, and I didn't get a
response. I was mainly interested in sorting the list based on which
column was clicked. I had to maintain a seperate 2 dimensional list,
sort it appropriately, and then place the data back into the listCtrl.
It would be nice if the C++ wxListCtrl had a method to sort based on a
column. It would also be very beneficial to be able to read any
row/column data.

I don't see it in the archives from before so the message must have gotten
lost. Try this:

    def wxListCtrl_GetColText(list, index, col):
        item = list.GetItem(index, col)
        return item.GetText()

The reason people usually keep a second set of data is for speed when
sorting. You don't need to sort the second set and reload the list, just
use it for doing the comparisons. This is because calling something like
the above in the comparison function requires *a lot* of function calls,
which are expensive in python, and more so when calling into C++ code from
python. See the demo for an example of doing column sorting.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Robin Dunn wrote:

Ruben Marquez wrote:

I have a list control with three columns. I would
like to be able to read the information on any given
column of the selected item. However, the GetItemText
method only accepts two parameters (self, and the Item
index). This only gives me the text of the first
column. How can one read the text of the other
columns? Will appreciate any help.

I asked the same question about 2 weeks ago, and I didn't get a
response. I was mainly interested in sorting the list based on which
column was clicked. I had to maintain a seperate 2 dimensional list,
sort it appropriately, and then place the data back into the listCtrl.
It would be nice if the C++ wxListCtrl had a method to sort based on a
column. It would also be very beneficial to be able to read any
row/column data.

I don't see it in the archives from before so the message must have gotten
lost.

It must be there somewhere, because Ruben had replied to my original post.

Try this:

    def wxListCtrl_GetColText(list, index, col):
        item = list.GetItem(index, col)
        return item.GetText()

The reason people usually keep a second set of data is for speed when
sorting. You don't need to sort the second set and reload the list, just
use it for doing the comparisons. This is because calling something like
the above in the comparison function requires *a lot* of function calls,
which are expensive in python, and more so when calling into C++ code from
python. See the demo for an example of doing column sorting.

OK, I understand why it is necessary to keep a seperate list.

You say it is not necessary to sort the second list and then reload the list. Are you implying that this would be slower than using the SortItems method and using the second list to do the comparisons (as in the demo) ? I am currently using the same method as the demo, except that the python list is dynamicly created. I was going to try the sort python list method and then reload the wxListCtrl but I'm not sure if it's worth it now.

I imagine the fastest way to do a sort columns would be to have it all done in the C++ widget, either as an extra parameter to SortItems or another method SortItemsByColumn.

Thanks,
Brendan Simon.

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

It must be there somewhere, because Ruben had replied to my original post.

I meant my response to your orginal question a couple weeks ago.

OK, I understand why it is necessary to keep a seperate list.

You say it is not necessary to sort the second list and then reload the
list. Are you implying that this would be slower than using the
SortItems method and using the second list to do the comparisons (as in
the demo) ?

I'm just guessing, but for a large list (a few thousands of items) I think
yes, it would be slower to reload. You have to delete all the items, and
then add them all. That's a lot of memory allocations/deletions going on
behind the scenes, plus there are delete item events being fired (even if
you don't catch them,) etc.

I am currently using the same method as the demo, except
that the python list is dynamicly created. I was going to try the sort
python list method and then reload the wxListCtrl but I'm not sure if
it's worth it now.

If you have time, try it and let us know.

I imagine the fastest way to do a sort columns would be to have it all
done in the C++ widget, either as an extra parameter to SortItems or
another method SortItemsByColumn.

That assumes you want to sort things the same way every time for every list,
but I guess for most cases it would be alright... I'll add it to my list.
It may not make it into the actual C++ class, but maybe in the wxPython
wrapper code (the C++ half)

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Robin Dunn wrote:

You say it is not necessary to sort the second list and then reload the
list. Are you implying that this would be slower than using the
SortItems method and using the second list to do the comparisons (as in
the demo) ?

I'm just guessing, but for a large list (a few thousands of items) I think
yes, it would be slower to reload. You have to delete all the items, and
then add them all. That's a lot of memory allocations/deletions going on
behind the scenes, plus there are delete item events being fired (even if
you don't catch them,) etc.

That makes sense.

I am currently using the same method as the demo, except
that the python list is dynamicly created. I was going to try the sort
python list method and then reload the wxListCtrl but I'm not sure if
it's worth it now.

If you have time, try it and let us know.

I certainly will (if I have time). It's a lower priority for me at the moment as there are other features of wxCvs that need attention (like making the cvs stuff go).

I imagine the fastest way to do a sort columns would be to have it all
done in the C++ widget, either as an extra parameter to SortItems or
another method SortItemsByColumn.

That assumes you want to sort things the same way every time for every list,
but I guess for most cases it would be alright... I'll add it to my list.
It may not make it into the actual C++ class, but maybe in the wxPython
wrapper code (the C++ half)

Successive clicks on the column label should do forward/reverse sorts.
Maybe another parameter to specify the direction. The default would be to do the opposite of what was last chosen.

Brendan Simon.

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

From reading the docs if you call DeleteAllItems() then delete events
aren't fired for each delete. I suspect that wxwindows also uses a slightly
more efficient memory deletion method when this method is called.

···

On Wed, Nov 15, 2000 at 06:22:44PM -0800, Robin Dunn wrote:

I'm just guessing, but for a large list (a few thousands of items) I think
yes, it would be slower to reload. You have to delete all the items, and
then add them all. That's a lot of memory allocations/deletions going on
behind the scenes, plus there are delete item events being fired (even if
you don't catch them,) etc.

--
------------------------------------------------------------------

Suchandra S. Thapa
s-thapa@uchicago.edu

------------------------------------------------------------------
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

> I'm just guessing, but for a large list (a few thousands of items) I

think

> yes, it would be slower to reload. You have to delete all the items,

and

> then add them all. That's a lot of memory allocations/deletions going

on

> behind the scenes, plus there are delete item events being fired (even

if

> you don't catch them,) etc.

    From reading the docs if you call DeleteAllItems() then delete events
aren't fired for each delete. I suspect that wxwindows also uses a

slightly

more efficient memory deletion method when this method is called.

You're right. I forgot it had been changed to not send events in that case.

···

On Wed, Nov 15, 2000 at 06:22:44PM -0800, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Brendan J Simon wrote:

Successive clicks on the column label should do forward/reverse sorts.
Maybe another parameter to specify the direction. The default would be
to do the opposite of what was last chosen.

This is getting to be pretty standard stuff in GUIs, but I think what
Robin was referring to is that you would need to define how to sort a
given type of entry: you would want to sort a string that contained a
date by date, not alphabetically, for instance. There would be many
cases where you would have to specify how to sort a given item.

Perhaps a comparison function could be passed in like the Python
list.sort(cmpfunction) method. Of course, this would slow things down a
lot, so there may be no point.

-Chris

···

--
Christopher Barker,
Ph.D.
cbarker@jps.net --- --- ---
http://www.jps.net/cbarker -----@@ -----@@ -----@@
                                   ------@@@ ------@@@ ------@@@
Water Resources Engineering ------ @ ------ @ ------ @
Coastal and Fluvial Hydrodynamics ------- --------- --------
------------------------------------------------------------------------
------------------------------------------------------------------------
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Perhaps a comparison function could be passed in like the Python
list.sort(cmpfunction) method. Of course, this would slow things down a
lot, so there may be no point.

You can already do it this way, see the demo.

I think what would be usefull is an easy way to do just a "normal"
alphabetic sort, forward or reverse, without having to specify a comparrison
callback. This might cover 90% of the cases where column sorting is needed.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

What if the app could have a subclass of the widget that defined operator < for that type? Then there wouldn't need to be a callback function. Being a subclass, it would still be a widget so the developer wouldn't have to deal with the display stuff. Then make the default operator perform the lexical ordering of the string as Robin suggested.

-D

···

On Thu, 16 Nov 2000 13:20:04 Robin Dunn wrote:
> >
> > Perhaps a comparison function could be passed in like the Python
> > list.sort(cmpfunction) method. Of course, this would slow things down a
> > lot, so there may be no point.
> >
>
> You can already do it this way, see the demo.
>
> I think what would be usefull is an easy way to do just a "normal"
> alphabetic sort, forward or reverse, without having to specify a comparrison
> callback. This might cover 90% of the cases where column sorting is needed.
>
> --
> Robin Dunn
> Software Craftsman
> robin@AllDunn.com
> http://wxPython.org Java give you jitters?
> http://wxPROs.com Relax with wxPython!
>
>
> _______________________________________________
> wxPython-users mailing list
> wxPython-users@lists.sourceforge.net
> http://lists.sourceforge.net/mailman/listinfo/wxpython-users
>

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

What if the app could have a subclass of the widget that defined operator

< for that type? Then there wouldn't need to be a callback function. Being
a subclass, it would still be a widget so the developer wouldn't have to
deal with the display stuff. Then make the default operator perform the
lexical ordering of the string as Robin suggested.

[ can you set your mailer to wrap lines at a decent margin? ]

It would still have to be implemented as a callback from C++ --> Python,
essentially the same as the SortItems(compareFunc) is already done. It
doesn't buy you anything to make it an operator other than adding a bit of
magic. Also, what if you want to sort different columns differently?

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com
http://wxPython.org Java give you jitters?
http://wxPROs.com Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Robin Dunn wrote:

I think what would be usefull is an easy way to do just a "normal"
alphabetic sort, forward or reverse, without having to specify a comparrison
callback. This might cover 90% of the cases where column sorting is needed.

Yes, this would be very welcome. There could still be the existing method of
supplying a custom sorter for the remaing 10%.

Brendan Simon.

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users