how to sort ListView by click on its column header?

I have an app with wx.ListView object on it, containing 4 columns.

I'd like to have the table sorted when a user clicks the column title.

    def OnListView1ListColClick(self, event):
        col = event.GetColumn()
        self.sort_results(col)

    def sort_results(self, col):

        ... ok, now what?

i found self.listView1.SortItems(self.sorttable),
but i can't find documentation on how to use it,
and how to apply it to a particular column.

Thanks!

Shoola wrote:

I have an app with wx.ListView object on it, containing 4 columns.

I'd like to have the table sorted when a user clicks the column title.

    def OnListView1ListColClick(self, event):
        col = event.GetColumn()
        self.sort_results(col)

    def sort_results(self, col):

        ... ok, now what?

i found self.listView1.SortItems(self.sorttable),
but i can't find documentation on how to use it,
and how to apply it to a particular column.

Take a look at the wx.lib.mixins.listctrl.ColumnSorterMixin class.

···

--
Robin Dunn
Software Craftsman

Thank you for replying.

1. The "requirement" looks intrusive, since I'm writing this GUI with
Boa Constructor,
and i'm not interested in breaking it's ability to read/write my code,
and not interested to write too much wxpython on my own (which what
Boa is for).

2. What does "listView1.SortItems()" for?
I couldn't find a pythonic explanation and/or example.

3. Is there a "Boa way" to do it? (i guess i need to ask them too)

···

On Jul 2, 7:24 pm, Robin Dunn <ro...@alldunn.com> wrote:

Shoola wrote:
> I have an app with wx.ListView object on it, containing 4 columns.

> I'd like to have the table sorted when a user clicks the column title.

> def OnListView1ListColClick(self, event):
> col = event.GetColumn()
> self.sort_results(col)

> def sort_results(self, col):

> ... ok, now what?

> i found self.listView1.SortItems(self.sorttable),
> but i can't find documentation on how to use it,
> and how to apply it to a particular column.

Take a look at the wx.lib.mixins.listctrl.ColumnSorterMixin class.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Hello,

2. What does "listView1.SortItems()" for?
I couldn't find a pythonic explanation and/or example.

ListView derives from ListCtrl: http://docs.wxwidgets.org/2.8.9/wx_wxlistview.html#wxlistview

SortItems is a method of ListCtrl: http://docs.wxwidgets.org/2.8.9/wx_wxlistctrl.html#wxlistctrlsortitems

You need to pass it a function that takes two list items and returns -1 if l1 < l2, 1 if l1 > l2, and 0 if l1 == l2.

i.e)
def mySort(a, b):
     if a < b:
         return -1
     elif a > b:
         return 1
     else:
         return 0

listView1.SortItems(mySort)

Also see the Style flags for this control in the above documentation.

Cody

···

On Jul 3, 2009, at 7:13 AM, Shoola wrote:

Shoola wrote:

Thank you for replying.

1. The "requirement" looks intrusive, since I'm writing this GUI with
Boa Constructor,
and i'm not interested in breaking it's ability to read/write my code,
and not interested to write too much wxpython on my own (which what
Boa is for).

Sorry, I should have written more in my response. I mentioned the ColumnSorterMixin not only as a class you could use if you wanted, but also as an example of how to do it if you decided that it did not fit your needs as-is.

···

--
Robin Dunn
Software Craftsman