Phoenix Logo

phoenix_title wx.lib.mixins.listctrl.ColumnSorterMixin

A mixin class that handles sorting of a wx.ListCtrl in REPORT mode when the column header is clicked on.

There are a few requirments needed in order for this to work genericly:

  1. The combined class must have a GetListCtrl method that returns the wx.ListCtrl to be sorted, and the list control must exist at the time the wx.ColumnSorterMixin.__init__ method is called because it uses GetListCtrl.
  2. Items in the list control must have a unique data value set with list.SetItemData.
  3. The combined class must have an attribute named itemDataMap that is a dictionary mapping the data values to a sequence of objects representing the values in each column. These values are compared in the column sorter to determine sort order.

Interesting methods to override are GetColumnSorter, GetSecondarySortValues, and GetSortImages. See below for details.


class_hierarchy Class Hierarchy

Inheritance diagram for class ColumnSorterMixin:


method_summary Methods Summary

__init__  
GetColumnSorter Returns a callable object to be used for comparing column values when sorting.
GetColumnWidths Returns a list of column widths. Can be used to help restore the current
GetSecondarySortValues Returns a tuple of 2 values to use for secondary sort values when the
GetSortImages Returns a tuple of image list indexesthe indexes in the image list for an image to be put on the column
GetSortState Return a tuple containing the index of the column that was last sorted
OnSortOrderChanged Callback called after sort order has changed (whenever user
SetColumnCount  
SortListItems Sort the list on demand. Can also be used to set the sort column and order.

api Class API



class ColumnSorterMixin

A mixin class that handles sorting of a wx.ListCtrl in REPORT mode when the column header is clicked on.

There are a few requirments needed in order for this to work genericly:

  1. The combined class must have a GetListCtrl method that returns the wx.ListCtrl to be sorted, and the list control must exist at the time the wx.ColumnSorterMixin.__init__ method is called because it uses GetListCtrl.
  2. Items in the list control must have a unique data value set with list.SetItemData.
  3. The combined class must have an attribute named itemDataMap that is a dictionary mapping the data values to a sequence of objects representing the values in each column. These values are compared in the column sorter to determine sort order.

Interesting methods to override are GetColumnSorter, GetSecondarySortValues, and GetSortImages. See below for details.


Methods



__init__(self, numColumns)


GetColumnSorter(self)

Returns a callable object to be used for comparing column values when sorting.



GetColumnWidths(self)

Returns a list of column widths. Can be used to help restore the current view later.



GetSecondarySortValues(self, col, key1, key2)

Returns a tuple of 2 values to use for secondary sort values when the items in the selected column match equal. The default just returns the item data values.



GetSortImages(self)

Returns a tuple of image list indexesthe indexes in the image list for an image to be put on the column header when sorting in descending order.



GetSortState(self)

Return a tuple containing the index of the column that was last sorted and the sort direction of that column. Usage: col, ascending = self.GetSortState() # Make changes to list items... then resort self.SortListItems(col, ascending)



OnSortOrderChanged(self)

Callback called after sort order has changed (whenever user clicked column header).



SetColumnCount(self, newNumColumns)


SortListItems(self, col=-1, ascending=1)

Sort the list on demand. Can also be used to set the sort column and order.