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)¶ Bases:
wx._core.ScrolledWindowA scrollable panel which displays a tabular grid of widgets. A
WidgetGridlooks something like this:The most important methods are:
GetGridSizeReturns the current grid size as a tuple containing (rows, cols).SetGridSizeSet the size of the widdget grid. RefreshRedraws the contents of this WidgetGrid.DeleteRowRemoves the specified rowfrom the grid, destroying all widgets on that row.InsertRowInserts a new row into the WidgetGridat the specifiedrowindex.SetColoursSet the colours used in this WidgetGrid.SetWidgetAdds the given widget to the grid. SetTextConvenience method which creates a wx.StaticTextwidget with the given text, and passes it to theSetWidget()method.ClearGridRemoves and destroys all widgets from the grid, and sets the grid size to (0, 0).Labels
ShowRowLabelsShows/hides the grid row labels. ShowColLabelsShows/hides the grid column labels. SetRowLabelSets a label for the specified row. SetColLabelSets a label for the specified column. Selections
GetSelectionReturns the currently selected item, as a tuple of (row, col)indices.SetSelectionSelect the given item. Styles
The
WidgetGridsupports the following styles:wx.HSCROLLUse a horizontal scrollbar. wx.VSCROLLUse a vertical scrollbar. WG_SELECTABLE_CELLSIndividual cells are selectable. WG_SELECTABLE_ROWSRows are selectable. WG_SELECTABLE_COLUMNColumns are selectable. WG_KEY_NAVIGATIONThe keyboard can be used for navigation 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
wxparent object. - style – Style flags - can be a combination of
wx.HSCROLL,wx.VSCROLL,WG_SELECTABLE_CELLS,WG_SELECTABLE_ROWS, andWG_SELECTABLE_COLUMNS.
-
_defaultBorderColour= '#000000'¶ The colour of border a border which is shown around every cell in the grid.
-
_defaultOddColour= '#ffffff'¶ Background colour for cells on odd rows.
-
_defaultEvenColour= '#eeeeee'¶ Background colour for cells on even rows.
-
_defaultLabelColour= '#dddddd'¶ Background colour for row and column labels.
-
_defaultSelectedColour= '#cdcdff'¶ Background colour for selected cells.
-
__init__(parent, style=None)¶ Create a
WidgetGrid.Parameters: - parent – The
wxparent object. - style – Style flags - can be a combination of
wx.HSCROLL,wx.VSCROLL,WG_SELECTABLE_CELLS,WG_SELECTABLE_ROWS, andWG_SELECTABLE_COLUMNS.
- parent – The
-
Refresh()¶ Redraws the contents of this
WidgetGrid. This method must be called after the contents of the grid are changed.
-
Hide()¶ Hides this
WidgetGrid.
-
Show(show=True)¶ Shows/hides this
WidgetGrid, and recursively does the same to all of its children.
-
SetColours(**kwargs)¶ 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.
Set the keys used for keyboard navigation (if the
WG_KEY_NAVIGATIONstyle is enabled). Setting an argument toNonewill 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.
-
GetGridSize()¶ Returns the current grid size as a tuple containing
(rows, cols).
-
SetGridSize(nrows, ncols, growCols=None)¶ 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)¶ Returns the index of the row in which the given
widgetis located, or-1if it is not in theWidgetGrid.
-
GetColumn(widget)¶ Returns the index of the column in which the given
widgetis located, or-1if it is not in theWidgetGrid.
-
DeleteRow(row)¶ Removes the specified
rowfrom the grid, destroying all widgets on that row. This method does not need to be followed by a call toRefresh(), but a call toLayoutmay be required.Note
Make sure you reparent any widgets that you do not want destroyed before calling this method.
-
InsertRow(row)¶ Inserts a new row into the
WidgetGridat the specifiedrowindex. This method must be followed by a call toRefresh().
-
ClearGrid()¶ 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)¶ Convenience method which creates a
wx.StaticTextwidget with the given text, and passes it to theSetWidget()method.Parameters: - row – Row index.
- col – Column index.
- text – Text to display.
-
GetWidget(row, col)¶ Returns the widget located at the specified row/column.
-
SetWidget(row, col, widget)¶ 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
IndexErrorif the specified grid location(row, col)is invalid.
-
GetSelection()¶ Returns the currently selected item, as a tuple of
(row, col)indices. If an entire row has been selected, thecolindex will be -1, and vice-versa. If nothing is selected,Noneis returned.
-
SetSelection(row, col)¶ Select the given item. A
ValueErroris 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: Trueif the selected item was changed,Falseotherwise.
-
ShowRowLabels(show=True)¶ Shows/hides the grid row labels. The
Refresh()method must be called afterwards for this method to take effect.
-
ShowColLabels(show=True)¶ Shows/hides the grid column labels. The
Refresh()method must be called afterwards for this method to take effect.
-
SetRowLabel(row, label)¶ Sets a label for the specified row.
Raises an
IndexErrorif the row is invalid.
-
SetColLabel(col, label)¶ Sets a label for the specified column.
Raises an
IndexErrorif the column is invalid.
-
_WidgetGrid__initCell(row, col)¶ Called by
SetGridSize()andInsertRow(). Creates a placeholderwx.Panelat the specified cell.
-
_WidgetGrid__initColLabel(col)¶ Called by
SetGridSize(). Creates a label widget at the specified column
-
_WidgetGrid__initRowLabel(row)¶ Called by
SetGridSize()andInsertRow(). Creates a label widget at the specified row.
-
_WidgetGrid__initWidget(widget, row, col)¶ Called by the
AddWidget()method.Performs some initialisation on a widget which has just been added to the grid.
Parameters: - widget – The widget to initialise
- row – Row index of the widget in the grid.
- col – Column index of the widget in the grid.
-
_WidgetGrid__onChildFocus(ev)¶ If this
WidgetGridis selectable, this method is called when a widget in the grid gains focus. Ensures that the containing cell is selected.
-
_WidgetGrid__onKeyboard(ev)¶ If the
WG_KEY_NAVIGATIONstyle is enabled, this method is called when the user pushes a key while thisWidgetGridhas focus. It changes the currently selected cell, row, or column.
-
_WidgetGrid__onLeftMouseDown(ev)¶ If this
WidgetGridis selectable, this method is called whenever an left mouse down event occurs on an item in the grid.
-
_WidgetGrid__onResize(ev)¶ Called when this
WidgetGridis resized. Makes sure the scrollbars are up to date.
-
_WidgetGrid__refresh()¶ Lays out and re-sizes the entire widget grid.
-
_WidgetGrid__reparent(widget, parent)¶ Convenience method which re-parents the given widget. If
widgetis awx.Sizerthe sizer children are re-parented.
-
_WidgetGrid__scrollTo(row, col)¶ If scrolling is enabled, this method makes sure that the specified row/column is visible.
-
_WidgetGrid__select(row, col, selectType, select=True)¶ Called by the
SetSelection()method. Sets the background colour of the specified row/column to the selection colour, or the default colour.Parameters: - row – Row index. If -1, the colour of the entire column is toggled.
- col – Column index. If -1, the colour of the entire row is toggled.
- selectType – Either
'rows','columns', or'cells'. - select – If
True, the item background colour is set to the selected colour, otherwise it is set to its default colour.
-
_WidgetGrid__selectCell(row, col)¶ Called by the
__onChildFocus()and__onLeftMouseDown()methods. Selects the specified row/column, and generates anEVT_WG_SELECTevent.
-
_WidgetGrid__setBackgroundColour(widget, colour)¶ Convenience method which changes the background colour of the given widget. If
widgetis awx.Sizerthe background colours of the sizer children is updated.
-
__module__= 'fsleyes_widgets.widgetgrid'¶
- parent – The
-
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.EVT_WG_SELECT= <wx.core.PyEventBinder object>¶ Identifier for the
WidgetGridSelectEvent.
-
fsleyes_widgets.widgetgrid.WidgetGridSelectEvent¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
