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:
Exception
Exception 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:
object
Container class used by
Action
instances 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
True
if the widget contained by thisBoundWidget
is still alive,False
otherwise.
- __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, instance=None, name=None)[source]¶
Bases:
__main__.docbuilder.run.<locals>.MockClass
Represents an action of some sort.
- enabled = <MagicMock name='mock.Boolean()' id='140572303765904'>¶
Controls whether the action is currently enabled or disabled. When this property is
False
calls to the action will result in aActionDisabledError
.
- __init__(overlayList, displayCtx, func, instance=None, name=None)[source]¶
Create an
Action
.- Parameters
overlayList – The
OverlayList
.displayCtx – The
DisplayContext
associated with thisAction
; note that this is not necessarily the masterDisplayContext
.func – The action function.
instance – Object associated with the function, if this
Action
is encapsulating an instance method.name – Action name. Defaults to
func.__name__
.
Note
If an
Action
encapsulates a method of anActionProvider
instance, it is assumed that thename
is the name of the method on the instance.
- property overlayList¶
Return a reference to the
OverlayList
.
- property displayCtx¶
Return a reference to the
DisplayContext
.
- property instance¶
Return the instance which owns this
Action
, if relevant. ReturnsNone
otherwise.
- __call__(*args, **kwargs)[source]¶
Calls this action. An
ActionDisabledError
will be raised ifenabled
isFalse
.
- bindToWidget(parent, evType, widget, wrapper=None)[source]¶
Binds this action to the given
wx
widget.- Parameters
parent – The
wx
object on which the event should be bound.evType – The
wx
event type.widget – The
wx
widget.wrapper – Optional custom wrapper function used to execute the action.
- __unbindWidget(index)¶
Unbinds the widget at the specified index into the
__boundWidgets
list. Does not remove it from the list.
- unbindAllWidgets()[source]¶
Unbinds all widgets which have been bound via
bindToWidget()
.
- getBoundWidgets()[source]¶
Returns a list of
BoundWidget
instances, containing all widgets which have been bound to thisAction
.
- __enabledChanged(*args)¶
Internal method which is called when the
enabled
property changes. Enables/disables any bound widgets.
- __annotations__ = {}¶
- __module__ = 'fsleyes.actions.base'¶
- class fsleyes.actions.base.ToggleAction(*args, **kwargs)[source]¶
Bases:
fsleyes.actions.base.Action
A
ToggleAction
anAction
which is intended to encapsulate actions that toggle some sort of state. For example, aToggleAction
could be used to encapsulate an action which opens and/or closes a dialog window.- toggled = <MagicMock name='mock.Boolean()' id='140572303765904'>¶
Boolean which tracks the current state of the
ToggleAction
.
- __init__(*args, **kwargs)[source]¶
Create a
ToggleAction
. All arguments are passed toAction.__init__()
.
- __call__(*args, **kwargs)[source]¶
Call this
ToggleAction
. The value of thetoggled
property is flipped.
- bindToWidget(parent, evType, widget, wrapper=None)[source]¶
Bind this
ToggleAction
to a widget. If the widget is awx.MenuItem
, itsCheck
is called whenever thetoggled
state changes.
- __toggledChanged(*a)¶
Internal method called when
toggled
changes. Updates the state of any bound widgets.
- __annotations__ = {}¶
- __module__ = 'fsleyes.actions.base'¶
- class fsleyes.actions.base.NeedOverlayAction(overlayList, displayCtx, func=None, overlayType=<MagicMock name='mock.data.image.Image' id='140572304216640'>)[source]¶
Bases:
fsleyes.actions.base.Action
The
NeedOverlayAction
is 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='140572304216640'>)[source]¶
Create a
NeedOverlayAction
.- Parameters
overlayList – The
OverlayList
.displayCtx – The
DisplayContext
.func – The action function
overlayType – The required overlay type (defaults to
Image
)
- __annotations__ = {}¶
- __module__ = 'fsleyes.actions.base'¶
- destroy()[source]¶
Removes listeners from the
DisplayContext
andOverlayList
, 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.