fsleyes_widgets.widgetlist
¶
This module provides the WidgetList
class, which displays a list
of widgets.
-
class
fsleyes_widgets.widgetlist.
WidgetList
(parent, style=0)¶ Bases:
wx.lib.scrolledpanel.ScrolledPanel
A scrollable list of widgets.
The
WidgetList
provides a number of features:- Widgets can be grouped.
- A label can be shown next to each widget.
- Widget groups can be collapsed/expanded.
- Widgets and groups can be dynamically added/removed.
The most important methods are:
A
WidgetList
looks something like this:A
WidgetList
emits aWidgetListChangeEvent
whenever its contents change.Create a
WidgetList
.Parameters: parent – The wx
parent object.-
_defaultOddColour
= '#eaeaea'¶ Background colour for widgets on odd rows.
-
_defaultEvenColour
= '#ffffff'¶ Background colour for widgets on even rows.
-
_defaultGroupColour
= '#cdcdff'¶ Border and title background colour for widget groups.
-
__init__
(parent, style=0)¶ Create a
WidgetList
.Parameters: parent – The wx
parent object.
-
DoGetBestSize
()¶ Returns the best size for the widget list, with all group widgets expanded.
-
SetColours
(odd=None, even=None, group=None)¶ Sets the colours used on this
WidgetList
.Each argument is assumed to be a tuple of
(r, g, b)
values, each in the range[0 - 255]
.Parameters: - odd – Background colour for widgets on odd rows.
- even – Background colour for widgets on even rows.
- group – Border/title colour for widget groups.
-
GetGroups
()¶ Returns a list containing the name of every group in this
WidgetList
.
-
HasGroup
(groupName)¶ Returns
True
if thisWidgetList
contains a group with the specified name.
-
RenameGroup
(groupName, newDisplayName)¶ Changes the display name of the specified group.
Note
This method only changes the display name of a group, not the group identifier name. See the
AddGroup()
method.Parameters: - groupName – Name of the group.
- newDisplayName – New display name for the group.
-
AddGroup
(groupName, displayName=None)¶ Add a new group to this
WidgetList
.A
ValueError
is raised if a group with the specified name already exists.Parameters: - groupName – The name of the group - this is used as an identifier for the group.
- displayName – A string to be shown in the title bar for the
group. This can be changed later via the
RenameGroup()
method.
-
GetWidgets
(groupName=None)¶ Returns a list containing all of the widgets that have been added to this
WidgetList
.Parameters: groupName – If provided, only widgets in the specified group will be returned. Otherwise, ungrouped widgets are returned.
-
AddWidget
(widget, displayName, tooltip=None, groupName=None)¶ Add an arbitrary widget to the property list.
If the
groupName
is not provided, the widget is added to a list of top level widgets, which appear at the top of the list, above any groups. Otherwise, the widget is added to the collapsible panel corresponding to the specified group.A
ValueError
is raised if the widget is already contained in the list.Parameters: - widget – The widget to add to the list.
- displayName – The widget label/display name.
- tooltip – A tooltip for the widget.
- groupName –
- Name of the group to which the widget should be
- added.
Note
The provided
widget
may also be awx.Sizer
instances, although support for this is basic. Specifically, only one level of nesting is possible, i.e. the providedwx.Sizer
may not have any otherwx.Sizer
instances as its children.
-
AddSpace
(groupName=None)¶ Adds some empty vertical space to the widget list.
Parameters: groupName – Name of the group tio which the space should be added. If not specified, the space is added to the top level widget list - see the AddWidget()
method.
-
RemoveWidget
(widget, groupName=None)¶ Removes and destroys the specified widget from this
WidgetList
.Parameters: - widget – The widget to remove.
- groupName – Name of the group in which the widget is contained.
-
RemoveGroup
(groupName)¶ Removes the specified group, and destroys all of the widgets contained within it.
-
Clear
()¶ Removes and destroys all widgets and groups.
-
ClearGroup
(groupName)¶ Removes and destroys all widgets in the specified group, but does not remove the group.
-
GroupSize
(groupName)¶ Returns the number of widgets that have been added to the specified group.
-
IsExpanded
(groupName)¶ Returns
True
if the panel for the specified group is currently expanded,False
if it is collapsed
-
Expand
(groupName, expand=True)¶ Expands or collapses the panel for the specified group.
-
_WidgetList__makeWidgetKey
(widget)¶ Widgets are stored in a dictionary - this method generates a string to use as a key, based on the widget
id
.
-
_WidgetList__onGroupExpand
(ev)¶ Called when the user expands or collapses a group. Enforces the
WL_ONE_EXPANDED
style if it is enabled, and refreshes the panel.
-
_WidgetList__onMouseWheel
(ev)¶ Only called if running on GTK. Scrolls the widget list according to the mouse wheel rotation.
-
_WidgetList__refresh
(*args, **kwargs)¶ Updates widget colours (see
__setColours()
), and lays out the widget list.Parameters: postEvent – If True
(the default), aWidgetListChangeEvent
is posted.
-
_WidgetList__setColours
()¶ Called whenever the widget list needs to be refreshed.
Makes sure that odd/even widgets and their labels have the correct background colour.
-
_WidgetList__setLabelWidths
(widgets)¶ Calculates the maximum width of all widget labels, and sets all labels to that width.
This ensures that all labels/widgets line are horizontally aligned.
-
__module__
= 'fsleyes_widgets.widgetlist'¶
-
class
fsleyes_widgets.widgetlist.
_Widget
(displayName, tooltip, label, widget, panel, sizer)¶ Bases:
object
The
_Widget
class is used internally by theWidgetList
to organise references to each widget in the list.-
__init__
(displayName, tooltip, label, widget, panel, sizer)¶ Initialize self. See help(type(self)) for accurate signature.
-
SetBackgroundColour
(colour)¶
-
SetTooltip
(tooltip)¶
-
Bind
(evType, callback)¶
-
Destroy
()¶
-
__dict__
= mappingproxy({'__module__': 'fsleyes_widgets.widgetlist', '__doc__': 'The ``_Widget`` class is used internally by the :class:`WidgetList`\n to organise references to each widget in the list.\n ', '__init__': <function _Widget.__init__>, 'SetBackgroundColour': <function _Widget.SetBackgroundColour>, 'SetTooltip': <function _Widget.SetTooltip>, 'Bind': <function _Widget.Bind>, 'Destroy': <function _Widget.Destroy>, '__dict__': <attribute '__dict__' of '_Widget' objects>, '__weakref__': <attribute '__weakref__' of '_Widget' objects>})¶
-
__module__
= 'fsleyes_widgets.widgetlist'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
fsleyes_widgets.widgetlist.
_Group
(groupName, displayName, gapSizer, parentPanel, colPanel, widgPanel, sizer)¶ Bases:
object
The
_Group
class is used internally byWidgetList
instances to represent groups of widgets that are in the list.-
__init__
(groupName, displayName, gapSizer, parentPanel, colPanel, widgPanel, sizer)¶ Initialize self. See help(type(self)) for accurate signature.
-
__dict__
= mappingproxy({'__module__': 'fsleyes_widgets.widgetlist', '__doc__': 'The ``_Group`` class is used internally by :class:`WidgetList`\n instances to represent groups of widgets that are in the list.\n ', '__init__': <function _Group.__init__>, '__dict__': <attribute '__dict__' of '_Group' objects>, '__weakref__': <attribute '__weakref__' of '_Group' objects>})¶
-
__module__
= 'fsleyes_widgets.widgetlist'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
fsleyes_widgets.widgetlist.
WidgetListChangeEvent
¶ alias of
wx.lib.newevent.NewEvent.<locals>._Event
-
fsleyes_widgets.widgetlist.
EVT_WL_CHANGE_EVENT
= <wx.core.PyEventBinder object>¶ Identifier for the
WidgetListChangeEvent
.
-
fsleyes_widgets.widgetlist.
WL_ONE_EXPANDED
= 1¶ WidgetList
style flag. When applied, at most one group will be expanded at any one time.