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:
Returns the current grid size as a tuple containing
(rows, cols)
.Set the size of the widdget grid.
Redraws the contents of this
WidgetGrid
.Removes the specified
row
from the grid, destroying all widgets on that row.Inserts a new row into the
WidgetGrid
at the specifiedrow
index.Set the colours used in this
WidgetGrid
.Adds the given widget to the grid.
Convenience method which creates a
wx.StaticText
widget with the given text, and passes it to theSetWidget()
method.Removes and destroys all widgets from the grid, and sets the grid size to
(0, 0)
.Labels
Shows/hides the grid row labels.
Shows/hides the grid column labels.
Sets a label for the specified row.
Sets a label for the specified column.
Selections
Returns the currently selected item, as a tuple of
(row, col)
indices.Select the given item.
Styles
The
WidgetGrid
supports the following styles:wx.HSCROLL
Use a horizontal scrollbar.
wx.VSCROLL
Use a vertical scrollbar.
Individual cells are selectable.
Rows are selectable.
WG_SELECTABLE_COLUMN
Columns are selectable.
The keyboard can be used for navigation.
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 theSetNavKeys()
method.Events
The following events may be emitted by a
WidgetGrid
:Create a
WidgetGrid
.- Parameters:
parent – The
wx
parent object.style – Style flags - can be a combination of
wx.HSCROLL
,wx.VSCROLL
,WG_SELECTABLE_CELLS
,WG_SELECTABLE_ROWS
,WG_SELECTABLE_COLUMNS
,WG_KEY_NAVIGATION
, andWG_DRAGGABLE_COLUMNS
.
- 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.
- Enable(enable=True)[source]
Enables/disable this
WidgetGrid
, and recursively does the same to all of its children.
- 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
. TheRefresh()
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.
Set the keys used for keyboard navigation (if the
WG_KEY_NAVIGATION
style is enabled). Setting an argument toNone
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.
- 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 theWidgetGrid
.
- GetColumn(widget)[source]
Returns the index of the column in which the given
widget
is located, or-1
if it is not in theWidgetGrid
.
- 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 toRefresh()
, but a call toLayout
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 specifiedrow
index. This method must be followed by a call toRefresh()
.
- ClearGrid()[source]
Removes and destroys all widgets from the grid, and sets the grid size to
(0, 0)
. TheRefresh()
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 theSetWidget()
method.If there is already a
wx.StaticText
widget at the givenrow
/col
, it is re-used, and its label simply updated.- Parameters:
row – Row index.
col – Column index.
text – Text to display.
- 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, thecol
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.
- 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. AWidgetGridSelectEvent
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. AWidgetGridReorderEvent
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.