# PYME.contrib.listctrlMixins module¶

class PYME.contrib.listctrlMixins.CheckListCtrlMixin(check_image=None, uncheck_image=None, imgsz=(16, 16))

This is a mixin for ListCtrl which add a checkbox in the first column of each row. It is inspired by limodou’s CheckList.py(which can be got from his NewEdit) and improved:

• You can just use InsertStringItem() to insert new items;
• Once a checkbox is checked/unchecked, the corresponding item is not selected;
• You can use SetItemData() and GetItemData();
• Interfaces are changed to OnCheckItem(), IsChecked(), CheckItem().

You should not set a imagelist for the ListCtrl once this mixin is used.

Methods

 CheckItem(index[, check]) IsChecked(index) OnCheckItem(index, flag) ToggleItem(index)
CheckItem(index, check=True)
IsChecked(index)
OnCheckItem(index, flag)
ToggleItem(index)
class PYME.contrib.listctrlMixins.ColumnSorterMixin(numColumns)

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

 GetColumnSorter() Returns a callable object to be used for comparing column values when sorting. GetColumnWidths() Returns a list of column widths. GetSecondarySortValues(col, key1, key2) Returns a tuple of 2 values to use for secondary sort values when the items in the selected column match equal. GetSortImages() 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() Return a tuple containing the index of the column that was last sorted and the sort direction of that column. OnSortOrderChanged() Callback called after sort order has changed (whenever user clicked column header). SetColumnCount(newNumColumns) SortListItems([col, ascending]) Sort the list on demand.
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 view later.

GetSecondarySortValues(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()

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()

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()

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

SetColumnCount(newNumColumns)
SortListItems(col=-1, ascending=1)

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

class PYME.contrib.listctrlMixins.ListCtrlAutoWidthMixin

A mix-in class that automatically resizes the last column to take up the remaining width of the wx.ListCtrl.

This causes the wx.ListCtrl to automatically take up the full width of the list, without either a horizontal scroll bar (unless absolutely necessary) or empty space to the right of the last column.

NOTE: This only works for report-style lists.

WARNING: If you override the EVT_SIZE event in your wx.ListCtrl, make
sure you call event.Skip() to ensure that the mixin’s _OnResize method is called.

This mix-in class was written by Erik Westra <ewestra@wave.co.nz>

Methods

 resizeColumn(minWidth) resizeLastColumn(minWidth) Resize the last column appropriately. setResizeColumn(col) Specify which column that should be autosized.

Standard initialiser.

Methods

 resizeColumn(minWidth) resizeLastColumn(minWidth) Resize the last column appropriately. setResizeColumn(col) Specify which column that should be autosized.
resizeColumn(minWidth)
resizeLastColumn(minWidth)

Resize the last column appropriately.

If the list’s columns are too wide to fit within the window, we use a horizontal scrollbar. Otherwise, we expand the right-most column to take up the remaining free space in the list.

This method is called automatically when the wx.ListCtrl is resized; you can also call it yourself whenever you want the last column to be resized appropriately (eg, when adding, removing or resizing columns).

‘minWidth’ is the preferred minimum width for the last column.

setResizeColumn(col)

Specify which column that should be autosized. Pass either ‘LAST’ or the column number. Default is ‘LAST’.

class PYME.contrib.listctrlMixins.ListCtrlSelectionManagerMix

Mixin that defines a platform independent selection policy

As selection single and multi-select list return the item index or a list of item indexes respectively.

Methods

 OnLCSMDoPopup(event) OnLCSMRightDown(event) afterPopupMenu(menu) Override to implement dynamic menus (destroy) getPopupMenu() Override to implement dynamic menus (create) getSelection() setPopupMenu(menu) Must be set for default behaviour
OnLCSMDoPopup(event)
OnLCSMRightDown(event)
afterPopupMenu(menu)

Override to implement dynamic menus (destroy)

getPopupMenu()

Override to implement dynamic menus (create)

getSelection()
setPopupMenu(menu)

Must be set for default behaviour

class PYME.contrib.listctrlMixins.ListRowHighlighter(color=None, mode=2)

Editra Control Library: ListRowHighlighter Mixin class that handles automatic background highlighting of alternate rows in the a ListCtrl. The background of the rows are highlighted automatically as items are added or inserted in the control based on the mixins Mode and set Color. By default the Even rows will be highlighted with the systems highlight color.

Methods

 RefreshRows() Re-color all the rows SetHighlightColor(color) Set the color used to highlight the rows. SetHighlightMode(mode) Set the highlighting mode to either HIGHLIGHT_EVEN or to HIGHLIGHT_ODD.

Initialize the highlighter mixin @keyword color: Set a custom highlight color (default uses system color) @keyword mode: HIGHLIGHT_EVEN (default) or HIGHLIGHT_ODD

Methods

 RefreshRows() Re-color all the rows SetHighlightColor(color) Set the color used to highlight the rows. SetHighlightMode(mode) Set the highlighting mode to either HIGHLIGHT_EVEN or to HIGHLIGHT_ODD.
RefreshRows()

Re-color all the rows

SetHighlightColor(color)

Set the color used to highlight the rows. Call L{RefreshRows} after this if you wish to update all the rows highlight colors. @param color: wx.Color or None to set default

SetHighlightMode(mode)

Set the highlighting mode to either HIGHLIGHT_EVEN or to HIGHLIGHT_ODD. Call L{RefreshRows} afterwards to update the list state. @param mode: HIGHLIGHT_* mode value

class PYME.contrib.listctrlMixins.TextEditMixin

A mixin class that enables any text in any column of a multi-column listctrl to be edited by clicking on the given row and column. You close the text editor by hitting the ENTER key or clicking somewhere else on the listctrl. You switch to the next column by hiting TAB.

To use the mixin you have to include it in the class definition and call the __init__ function:

class TestListCtrl(wx.ListCtrl, TextEditMixin):
def __init__(self, parent, ID, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=0):
wx.ListCtrl.__init__(self, parent, ID, pos, size, style)
TextEditMixin.__init__(self)


Authors: Steve Zatz, Pim Van Heuven (pim@think-wize.com)

Methods

 CloseEditor([evt]) Close the editor and save the new value to the ListCtrl. OnChar(event) Catch the TAB, Shift-TAB, cursor DOWN/UP key code so we can open the editor at the next column (if any). OnItemSelected(evt) OnLeftDown([evt]) Examine the click and double click events to see if a row has been click on twice. OpenEditor(col, row) Opens an editor at the current position. makeColumnEditable(col) make_editor([col_style])
CloseEditor(evt=None)

Close the editor and save the new value to the ListCtrl.

OnChar(event)

Catch the TAB, Shift-TAB, cursor DOWN/UP key code so we can open the editor at the next column (if any).

OnItemSelected(evt)
OnLeftDown(evt=None)

Examine the click and double click events to see if a row has been click on twice. If so, determine the current row and columnn and open the editor.

OpenEditor(col, row)

Opens an editor at the current position.

editorBgColour = wx.Colour(255, 255, 175, 255)
editorFgColour = wx.Colour(0, 0, 0, 255)
makeColumnEditable(col)
make_editor(col_style=0)
PYME.contrib.listctrlMixins.cmp(x, y)
PYME.contrib.listctrlMixins.getListCtrlSelection(listctrl, state=4)

Returns list of item indexes of given state (selected by defaults)

PYME.contrib.listctrlMixins.selectBeforePopup(event)

Ensures the item the mouse is pointing at is selected before a popup.

Works with both single-select and multi-select lists.