fsleyes_widgets.widgetgrid

This module provides the WidgetGrid class, which can display a tabular grid of arbitrary widgets.

class fsleyes_widgets.widgetgrid.WidgetGrid(parent, style=None)[source]

Bases: ScrolledWindow

A scrollable panel which displays a tabular grid of widgets. A WidgetGrid looks something like this:

The most important methods are:

GetGridSize

Returns the current grid size as a tuple containing (rows, cols).

SetGridSize

Set the size of the widdget grid.

Refresh

Redraws the contents of this WidgetGrid.

DeleteRow

Removes the specified row from the grid, destroying all widgets on that row.

InsertRow

Inserts a new row into the WidgetGrid at the specified row index.

SetColours

Set the colours used in this WidgetGrid.

SetWidget

Adds the given widget to the grid.

SetText

Convenience method which creates a wx.StaticText widget with the given text, and passes it to the SetWidget() method.

ClearGrid

Removes and destroys all widgets from the grid, and sets the grid size to (0, 0).

Labels

ShowRowLabels

Shows/hides the grid row labels.

ShowColLabels

Shows/hides the grid column labels.

SetRowLabel

Sets a label for the specified row.

SetColLabel

Sets a label for the specified column.

Selections

GetSelection

Returns the currently selected item, as a tuple of (row, col) indices.

SetSelection

Select the given item.

Styles

The WidgetGrid supports the following styles:

wx.HSCROLL

Use a horizontal scrollbar.

wx.VSCROLL

Use a vertical scrollbar.

WG_SELECTABLE_CELLS

Individual cells are selectable.

WG_SELECTABLE_ROWS

Rows are selectable.

WG_SELECTABLE_COLUMN

Columns are selectable.

WG_KEY_NAVIGATION

The keyboard can be used for navigation.

WG_DRAGGABLE_COLUMNS

Columns can be dragged to re-order them (see also the ReorderColumns() method)

The *_SELECTABLE_* styles are mutualliy exclusive; their precedence is equivalent to their order in the above table. By default, the arrow keys are used for keyboard navigation, but these are customisable via the SetNavKeys() method.

Events

The following events may be emitted by a WidgetGrid:

Create a WidgetGrid.

Parameters:
property rowLabels

Returns the wx.StaticText objects used for the row labels.

property colLabels

Returns the wx.StaticText objects used for the column labels.

property widgets

Returns a list of lists, containing all widgets in the grid.

Refresh()[source]

Redraws the contents of this WidgetGrid. This method must be called after the contents of the grid are changed.

Disable()[source]

Disables this WidgetGrid.

Enable(enable=True)[source]

Enables/disable this WidgetGrid, and recursively does the same to all of its children.

Hide()[source]

Hides this WidgetGrid.

Show(show=True)[source]

Shows/hides this WidgetGrid, and recursively does the same to all of its children.

SetEvtHandlerEnabled(enable=True)[source]

Enables/disables events on this WidgetGrid, and recursively does the same to all of its children.

SetColours(**kwargs)[source]

Set the colours used in this WidgetGrid. The Refresh() method must be called afterwards for this method to take effect.

Parameters:
  • border – The cell border colour.

  • label – Background colour for row and column labels.

  • odd – Background colour for cells on odd rows.

  • even – Background colour for cells on even rows.

  • selected – Background colour for selected cells.

  • drag – Background colour for columns being dragged.

SetNavKeys(**kwargs)[source]

Set the keys used for keyboard navigation (if the WG_KEY_NAVIGATION style is enabled). Setting an argument to None will disable navigation in that direction.

Parameters:
  • up – Key to use for up navigation.

  • down – Key to use for down navigation.

  • left – Key to use for left navigation.

  • right – Key to use for right navigation.

SetDragLimit(limit)[source]

Set the index of the highest column that can be dragged. Only columns before this limit can be dragged, and they can only be dropped onto a location before the limit. Only relevant if WG_DRAGGABLE_COLUMNS is enabled.

GetGridSize()[source]

Returns the current grid size as a tuple containing (rows, cols).

SetGridSize(nrows, ncols, growCols=None)[source]

Set the size of the widdget grid. The Refresh() method must be called afterwards for this method to take effect.

Parameters:
  • nrows – Number of rows

  • ncols – Number of columns

  • growCols – A sequence specifying which columns should be stretched to fit.

GetRow(widget)[source]

Returns the index of the row in which the given widget is located, or -1 if it is not in the WidgetGrid.

GetColumn(widget)[source]

Returns the index of the column in which the given widget is located, or -1 if it is not in the WidgetGrid.

DeleteRow(row)[source]

Removes the specified row from the grid, destroying all widgets on that row. This method does not need to be followed by a call to Refresh(), but a call to Layout may be required.

Note

Make sure you reparent any widgets that you do not want destroyed before calling this method.

InsertRow(row)[source]

Inserts a new row into the WidgetGrid at the specified row index. This method must be followed by a call to Refresh().

ClearGrid()[source]

Removes and destroys all widgets from the grid, and sets the grid size to (0, 0). The Refresh() method must be called afterwards for this method to take effect.

SetText(row, col, text)[source]

Convenience method which creates a wx.StaticText widget with the given text, and passes it to the SetWidget() method.

If there is already a wx.StaticText widget at the given row/col, it is re-used, and its label simply updated.

Parameters:
  • row – Row index.

  • col – Column index.

  • text – Text to display.

GetWidget(row, col)[source]

Returns the widget located at the specified row/column.

SetWidget(row, col, widget)[source]

Adds the given widget to the grid. The Refresh() method must be called afterwards for this method to take effect.

The parent of the widget is changed to this WidgetGrid.

Note

The provided widget may alternately be a wx.Sizer. However, nested sizers, i.e. sizers which contain other sizers, are not supported.

Parameters:
  • row – Row index.

  • col – Column index.

  • widget – The widget or sizer to add to the grid.

Raises an IndexError if the specified grid location (row, col) is invalid.

GetSelection()[source]

Returns the currently selected item, as a tuple of (row, col) indices. If an entire row has been selected, the col index will be -1, and vice-versa. If nothing is selected, None is returned.

SetSelection(row, col)[source]

Select the given item. A ValueError is raised if the selection is invalid.

Parameters:
  • row – Row index of item to select. Pass in -1 to select a whole column.

  • col – Column index of item to select. Pass in -1 to select a whole row.

Returns:

True if the selected item was changed, False otherwise.

ShowRowLabels(show=True)[source]

Shows/hides the grid row labels. The Refresh() method must be called afterwards for this method to take effect.

ShowColLabels(show=True)[source]

Shows/hides the grid column labels. The Refresh() method must be called afterwards for this method to take effect.

SetRowLabel(row, label)[source]

Sets a label for the specified row.

Raises an IndexError if the row is invalid.

SetColLabel(col, label)[source]

Sets a label for the specified column.

Raises an IndexError if the column is invalid.

SetRowLabels(labels)[source]

Sets the label for every row.

SetColLabels(labels)[source]

Sets the label for every column.

GetRowLabel(row)[source]

Return the label of the specified row.

GetColLabel(col)[source]

Return the label of the specified column.

GetRowLabels()[source]

Return all row labels.

GetColLabels()[source]

Return all column labels.

ReorderColumns(order)[source]

Re-orders the grid columns according to the given sequence of column indices.

A call to this method must be followed by a call to Refresh().

Parameters:

order – Sequence of column indices (starting from 0) specifying the new column ordering.

fsleyes_widgets.widgetgrid.WG_SELECTABLE_CELLS = 1

If this style is enabled, individual cells can be selected.

fsleyes_widgets.widgetgrid.WG_SELECTABLE_ROWS = 2

If this style is enabled, whole rows can be selected.

fsleyes_widgets.widgetgrid.WG_SELECTABLE_COLUMNS = 4

If this style is enabled, whole columns can be selected.

fsleyes_widgets.widgetgrid.WG_KEY_NAVIGATION = 8

If this style is enabled along with one of the *_SELECTABLE_* styles, the user may use the keyboard to navigate between cells, rows, or columns.

fsleyes_widgets.widgetgrid.WG_DRAGGABLE_COLUMNS = 16

If this style is enabled, column names can be dragged with the mouse to re-order them.

fsleyes_widgets.widgetgrid.EVT_WG_SELECT = <wx.core.PyEventBinder object>

Identifier for the WidgetGridSelectEvent.

fsleyes_widgets.widgetgrid.EVT_WG_REORDER = <wx.core.PyEventBinder object>

Identifier for the WidgetGridReorderEvent.

fsleyes_widgets.widgetgrid.WidgetGridSelectEvent

Event generated when an item in a WidgetGrid is selected. A WidgetGridSelectEvent has the following attributes:

  • row Row index of the selected item. If -1, an entire column has been selected.

  • col Column index of the selected item. If -1, an entire row has been selected.

fsleyes_widgets.widgetgrid.WidgetGridReorderEvent

Event generated when the columns in a WidgetGrid are reordered. A WidgetGridReorderEvent has the following attributes:

  • order The new column order.

fsleyes_widgets.widgetgrid.TRIANGLE_ICON = b'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wIFDQoeGSImZAAAACZpVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVAgb24gYSBNYWOV5F9bAAAAZklEQVQY053PwQmEUAyE4U8Ftw5L8KAlbksetgIrsBLRy8O9RBDxCTowhyTDH4YH+iFhyzhFRn8T2t3v1DFDTXEDJdobWouyimHBig51AGZ8MWAtTsW201xctf+gObxsYpfVFH6nP5vqKwqbBq3zAAAAAElFTkSuQmCC'

Icon used as the drop marker when columns are being re-ordered by mouse drag.