fsleyes.editor.editor
¶
This module provides the Editor
class, which provides
functionality to edit the data in an Image
overlay.
-
class
fsleyes.editor.editor.
Editor
(image, overlayList, displayCtx, recordSelection=False)[source]¶ Bases:
fsleyes.actions.ActionProvider
The
Editor
class provides functionality to edit the data of anImage
overlay. AnEditor
instance is associated with a specificImage
overlay, passed to__init__()
.An
Editor
instance uses aselection.Selection
object which allows voxel selections to be made, and keeps track of all changes to both the selection and image data.The editing process
Making changes to the data in an
Image
involves two steps:Create a selection
Change the value of voxels in that selection
The first step can be peformed by working directly with the
Selection
object - this is accessible via thegetSelection()
method. ThefillSelection()
method can be used to perform the second step.Some convenience methods are also provided for working with selections:
Returns the
selection.Selection
instance currently in use.Fills the current selection with the specified value or values.
Copies the
Image
data in the current selection.Pastes the data in the given
clipboard
into theImage
that is managed by thisEditor
.Change tracking
An
Editor
instance keeps track of all changes made to theImage
data and to theSelection
Every selection/data change made is recorded usingSelectionChange
andValueChange
instances, which are stored in a list. These changes can be undone (and redone), through theundo()
andredo()
“action” methods (see theactions
module). Changes to theSelection
object are, by default, only recorded when the selection is cleared. However, you can track all selection changes by initialising anEditor
instance withrecordSelection=True
.Sometimes it is useful to treat many small changes as a single large change. For example, if a selection is being updated by dragging the mouse across a canvas, storing a separate change for every change in mouse position would result in many small changes which, if the user then wishes to undo, would have to be undone one by one. This problem can be overcome by the use of change groups. Whenever an operation similar to the above begins, you can call the
startChangeGroup()
method - from now on, all changes will be aggregated into one group. When the operation completes, call theendChangeGroup()
to stop group changes. When undoing/redoing changes, all of the changes in a change group will be undone/redone together.-
__init__
(image, overlayList, displayCtx, recordSelection=False)[source]¶ Create an
Editor
.- Parameters
image – The
Image
instance being edited.overlayList – The
OverlayList
instance.displayCtx – The
DisplayContext
instance.recordSelection – Defaults to
False
. IfTrue
, changes to theselection.Selection
are recorded in the change history.
-
destroy
()[source]¶ Removes some property listeners, and clears references to objects to prevent memory leaks.
-
getSelection
()[source]¶ Returns the
selection.Selection
instance currently in use.
-
clearSelection
(*args, **kwargs)[source]¶ Clears the
selection.Selection
(seeselection.Selection.clearSelection()
). If thisEditor
is not recording all selection changes (recordSelection=False
in__init__()
), the selection state before being cleared is saved in the change history.All arguments are passed through to
Selection.clearSelection()
.
-
fillSelection
(newVals)[source]¶ Fills the current selection with the specified value or values.
- Parameters
newVals – A scalar value, or a sequence containing the same number of values as the current selection size.
-
startChangeGroup
()[source]¶ Starts a change group. All subsequent changes will be grouped together, for
undo()
/redo()
purposes, until a call toendChangeGroup()
.
-
endChangeGroup
()[source]¶ Ends a change group previously started by a call to
startChangeGroup()
.
-
recordChanges
(record=True)[source]¶ Cause this
Editor
to either record or ignore any changes that are made to the selection or the image data until further notice.- Parameters
record – If
True
, changes are recorded. Otherwise they are ignored.
-
ignoreChanges
()[source]¶ Cause this
Editor
to ignore any changes that are made to the selection or the image data until further notice. Call therecordChanges()
method to resume recording changes.
-
undo
()[source]¶ Un-does the most recent change. Returns a list containing all change objects that were undone - either
ValueChange
orSelectionChange
objects.
-
redo
()[source]¶ Re-does the most recent undone change. Returns a list containing all change objects that were undone - either
ValueChange
orSelectionChange
objects.
-
copySelection
()[source]¶ Copies the
Image
data in the current selection. Returns the data in a format that can be passed directly to thepasteSelection()
method of this, or another,Editor
instance.Note
The format of the returned data might change, so I haven’t specified it.
-
pasteSelection
(clipboard)[source]¶ Pastes the data in the given
clipboard
into theImage
that is managed by thisEditor
.The
clipboard
is assumed to have been created by thecopySelection()
method of anotherEditor
instance which is managing anImage
that has the same resolution and dimensions as theImage
managed by this instance.
-
__selectionChanged
(*a)¶ Called when the current
Selection.selection
changes.Saves a record of the change with a
SelectionChange
object.
-
__changeMade
(change)¶ Called by the
fillSelection()
and__selectionChanged()
methods, whenever a data/selection change is made.Saves the change, and updates the state of the
undo()
/redo()
methods.
-
__applyChange
(change)¶ Called by the
fillSelection()
andredo()
methods.Applies the given
change
(either aValueChange
or aSelectionChange
).
-
__revertChange
(change)¶ Called by the
undo()
method. Reverses the change made by the givenchange
object, (either aValueChange
or aSelectionChange
)
-
__makeSlice
(offset, shape, volume=None)¶ Generate a tuple of
slice
objects and/or integers, suitable for indexing a region of an image at the givenoffset
, with the givenshape
. If the image has more than three dimensions, the generated slice will index the specifiedvolume
(assumed to be a sequence of indices).
-
__annotations__
= {}¶
-
__module__
= 'fsleyes.editor.editor'¶
-
class
fsleyes.editor.editor.
ValueChange
(overlay, volume, offset, oldVals, newVals)[source]¶ Bases:
object
Represents a change which has been made to the data for an
Image
instance. Stores the location, the old values, and the new values.-
__init__
(overlay, volume, offset, oldVals, newVals)[source]¶ Create a
ValueChange
.- Parameters
overlay – The
Image
instance.volume – Sequence of volume indices, if
overlay
has more than 3 dimensions.offset – Location (voxel coordinates) of the change.
oldVals – A
numpy
array containing the old image values.newVals – A
numpy
array containing the new image values.
-
__annotations__
= {}¶
-
__dict__
= mappingproxy({'__module__': 'fsleyes.editor.editor', '__doc__': 'Represents a change which has been made to the data for an\n :class:`.Image` instance. Stores the location, the old values,\n and the new values.\n ', '__init__': <function ValueChange.__init__>, '__dict__': <attribute '__dict__' of 'ValueChange' objects>, '__weakref__': <attribute '__weakref__' of 'ValueChange' objects>, '__annotations__': {}})¶
-
__module__
= 'fsleyes.editor.editor'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
fsleyes.editor.editor.
SelectionChange
(overlay, offset, oldSelection, newSelection)[source]¶ Bases:
object
Represents a change which has been made to a
selection.Selection
instance. Stores the location, the old selection, and the new selection.-
__init__
(overlay, offset, oldSelection, newSelection)[source]¶ Create a
SelectionChange
.- Parameters
overlay – The
Image
instance.offset – Location (voxel coordinates) of the change.
oldSelection – A
numpy
array containing the old selection.newSelection – A
numpy
array containing the new selection.
-
__annotations__
= {}¶
-
__dict__
= mappingproxy({'__module__': 'fsleyes.editor.editor', '__doc__': 'Represents a change which has been made to a\n :class:`.selection.Selection` instance. Stores the location, the old\n selection, and the new selection.\n ', '__init__': <function SelectionChange.__init__>, '__dict__': <attribute '__dict__' of 'SelectionChange' objects>, '__weakref__': <attribute '__weakref__' of 'SelectionChange' objects>, '__annotations__': {}})¶
-
__module__
= 'fsleyes.editor.editor'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-