fsleyes.actions.base¶
This module provides the Action, NeedOverlayAction, and
ToggleAction classes. See the actions package documentation
for more details.
-
exception
fsleyes.actions.base.ActionDisabledError[source]¶ Bases:
ExceptionException raised when an attempt is made to call a disabled
Action.-
__module__= 'fsleyes.actions.base'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
fsleyes.actions.base.BoundWidget(parent, evType, widget)[source]¶ Bases:
objectContainer class used by
Actioninstances to store references to widgets that are currently bound to them.-
__init__(parent, evType, widget)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
isAlive()[source]¶ Returns
Trueif the widget contained by thisBoundWidgetis still alive,Falseotherwise.
-
__dict__= mappingproxy({'__module__': 'fsleyes.actions.base', '__doc__': 'Container class used by :class:`Action` instances to store references\n to widgets that are currently bound to them.\n ', '__init__': <function BoundWidget.__init__>, 'isAlive': <function BoundWidget.isAlive>, '__dict__': <attribute '__dict__' of 'BoundWidget' objects>, '__weakref__': <attribute '__weakref__' of 'BoundWidget' objects>, '__annotations__': {}})¶
-
__module__= 'fsleyes.actions.base'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
fsleyes.actions.base.Action(overlayList, displayCtx, func, name=None)[source]¶ Bases:
__main__.docbuilder.run.<locals>.MockClassRepresents an action of some sort.
-
enabled= <MagicMock name='mock.Boolean()' id='4117273880'>¶ Controls whether the action is currently enabled or disabled. When this property is
Falsecalls to the action will result in aActionDisabledError.
-
static
supportedViews()[source]¶ May be overridden to declare that this Action should be associated with a specific
ViewPanel. If overridden, must return a list containing all of the supportedViewPaneltypes.
-
static
ignoreTool()[source]¶ Used by the FSLeyes
pluginsmodule for actions which are loaded as plugins. Can be used to tell thepluginsmodule that a particularActionshould not be added as an option to the FSLeyes Tools menu.Note that this method must be implemented on the class that is to be ignored - inherited implementations from base classes are not considered.
-
__init__(overlayList, displayCtx, func, name=None)[source]¶ Create an
Action.- Parameters
overlayList – The
OverlayList.displayCtx – The
DisplayContextassociated with thisAction; note that this is not necessarily the masterDisplayContext.func – The action function.
name – Action name. Defaults to
func.__name__.
Note
If an
Actionencapsulates a method of anActionProviderinstance, it is assumed that thenameis the name of the method on the instance.
-
property
actionName¶ Returns the name of this
Action, often the method name of theActionProviderthat implements the action. Not to be confused withname().
-
property
name¶ Not to be confused with
actionName(). Returns a unique name for a specificActioninstance, which can be used (e.g.) for registering property listeners.
-
property
overlayList¶ Return a reference to the
OverlayList.
-
property
displayCtx¶ Return a reference to the
DisplayContext.
-
__call__(*args, **kwargs)[source]¶ Calls this action. An
ActionDisabledErrorwill be raised ifenabledisFalse.
-
bindToWidget(parent, evType, widget, wrapper=None)[source]¶ Binds this action to the given
wxwidget.- Parameters
parent – The
wxobject on which the event should be bound.evType – The
wxevent type.widget – The
wxwidget.wrapper – Optional custom wrapper function used to execute the action.
-
__unbindWidget(index)¶ Unbinds the widget at the specified index into the
__boundWidgetslist. Does not remove it from the list.
-
unbindAllWidgets()[source]¶ Unbinds all widgets which have been bound via
bindToWidget().
-
getBoundWidgets()[source]¶ Returns a list of
BoundWidgetinstances, containing all widgets which have been bound to thisAction.
-
__enabledChanged(*args)¶ Internal method which is called when the
enabledproperty changes. Enables/disables any bound widgets.
-
__module__= 'fsleyes.actions.base'¶
-
-
class
fsleyes.actions.base.ToggleAction(*args, **kwargs)[source]¶ Bases:
fsleyes.actions.base.ActionA
ToggleActionanActionwhich is intended to encapsulate actions that toggle some sort of state. For example, aToggleActioncould be used to encapsulate an action which opens and/or closes a dialog window.-
toggled= <MagicMock name='mock.Boolean()' id='4117273880'>¶ Boolean which tracks the current state of the
ToggleAction.
-
__init__(*args, **kwargs)[source]¶ Create a
ToggleAction.- Parameters
autoToggle – Must be specified as a keyword argument. If
True(the default), the state oftoggledis inverted every time this action is called. Otherwise, the state oftoggled, and of all bound widgets/menu items, needs to be changed manually.
All other arguments are passed to
Action.__init__().
-
__call__(*args, **kwargs)[source]¶ Call this
ToggleAction. The value of thetoggledproperty is flipped.
-
bindToWidget(parent, evType, widget, wrapper=None)[source]¶ Bind this
ToggleActionto a widget. If the widget is awx.MenuItem, itsCheckis called whenever thetoggledstate changes.
-
__toggledChanged(*a)¶ Internal method called when
toggledchanges. Updates the state of any bound widgets.
-
__module__= 'fsleyes.actions.base'¶
-
-
class
fsleyes.actions.base.NeedOverlayAction(overlayList, displayCtx, func=None, overlayType=<MagicMock name='mock.data.image.Image' id='4117295080'>)[source]¶ Bases:
fsleyes.actions.base.ActionThe
NeedOverlayActionis a convenience base class for actions which can only be executed when an overlay of a specific type is selected. It enables/disables itself based on the type of the currently selected overlay.-
__init__(overlayList, displayCtx, func=None, overlayType=<MagicMock name='mock.data.image.Image' id='4117295080'>)[source]¶ Create a
NeedOverlayAction.- Parameters
overlayList – The
OverlayList.displayCtx – The
DisplayContext.func – The action function
overlayType – The required overlay type (defaults to
Image)
-
__module__= 'fsleyes.actions.base'¶
-
destroy()[source]¶ Removes listeners from the
DisplayContextandOverlayList, and callsAction.destroy().
-
__selectedOverlayChanged(*a)¶ Called when the selected overlay, or overlay list, changes.
Enables/disables this action depending on the nature of the selected overlay.
-