fsleyes.views.canvaspanel
¶
This module provides the CanvasPanel
class, which is the base
class for all panels which display overlays using OpenGL
.
-
class
fsleyes.views.canvaspanel.
CanvasPanel
(parent, overlayList, displayCtx, frame, sceneOpts)¶ Bases:
fsleyes.views.viewpanel.ViewPanel
The
CanvasPanel
class is aViewPanel
which is the base class for all panels which display overlays usingOpenGL
(e.g. theOrthoPanel
and theLightBoxPanel
). ACanvasPanel
instance uses aSceneOpts
instance to control much of its functionality. TheSceneOpts
instance used by aCanvasPanel
can be accessed via thesceneOpts()
property.The
CanvasPanel
class contains settings and functionality common to all sub-classes, including movie mode (seemovieMode
), the ability to show a colour bar (aColourBarPanel
; seeSceneOpts.showColourBar
), and a number of actions.Sub-class implementations
Sub-classes of the
CanvasPanel
must do the following:- Add their content to the panel that is accessible via the
contentPanel()
property (see the note on adding content). - Override the
getGLCanvases()
method. - Call the
centrePanelLayout()
method in their__init__
method. - Override the
centrePanelLayout()
method if any custom layout is necessary.
Actions
The following actions are available through a
CanvasPanel
(see theactions
module):screenshot
Takes a screenshot of the currently displayed scene on this CanvasPanel
.movieGif
Generates an animated GIF of the currently displayed scene and movie mode settings on this CanvasPanel
.showCommandLineArgs
Shows the command line arguments which can be used to re-create the currently displayed scene. toggleMovieMode
Toggles the value of movieMode
.toggleDisplaySync
Toggles the value of syncOverlayDisplay
.toggleVolumeSync
Toggles the value of syncOverlayVolume
.toggleOverlayList
Toggles an OverlayListPanel
.toggleOverlayInfo
Toggles an OverlayInfoPanel
.toggleAtlasPanel
Toggles an AtlasPanel
.toggleDisplayToolBar
Toggles an OverlayDisplayToolBar
.toggleDisplayPanel
Toggles an OverlayDisplayPanel
.toggleCanvasSettingsPanel
Toggles a CanvasSettingsPanel
.toggleLocationPanel
Toggles a LocationPanel
.toggleClusterPanel
Toggles a ClusterPanel
.toggleLookupTablePanel
Toggles a LookupTablePanel
.toggleClassificationPanel
Toggles a MelodicClassificationPanel
.Adding content
To support colour bar and screenshot functionality, the
CanvasPanel
uses a hierarchy ofwx.Panel
instances, depicted in the following containment hierarchy diagram:As depicted in the diagram, sub-classes need to add their content to the content panel. This panel is accessible via the
contentPanel()
property.The centre panel is the
ViewPanel.centrePanel()
. The container panel is also available, viacontainerPanel()
. Everything in the container panel will appear in screenshots (see thescreenshot()
method).The
centrePanelLayout()
method lays out the centre panel, using thelayoutContainerPanel()
method to lay out the colour bar and the content panel. ThecentrePanelLayout
method simply adds the canvas container directly to the centre panel. Sub-classes which have more advanced layout requirements (e.g. theLightBoxPanel
needs a scrollbar) may override thecentrePanelLayout()
method to implement their own layout. These sub-class implementations must:- Call the
layoutContainerPanel()
method. - Add the container panel (accessed via
containerPanel()
) to the centre panel (accessed viacentrePanel()
). - Add any other custom content to the centre panel.
-
syncLocation
= <MagicMock name='mock.Boolean()' id='139845844115072'>¶ If
True
(the default), theDisplayContext.location
for thisCanvasPanel
is linked to the masterDisplayContext
location.
-
syncOverlayOrder
= <MagicMock name='mock.Boolean()' id='139845844115072'>¶ If
True
(the default), theDisplayContext.overlayOrder
for thisCanvasPanel
is linked to the masterDisplayContext
overlay order.
-
syncOverlayDisplay
= <MagicMock name='mock.Boolean()' id='139845844115072'>¶ If
True
(the default), the properties of theDisplay
andDisplayOpts
instances for every overlay, as managed by theDisplayContext
for thisCanvasPanel
, are linked to the properties of allDisplay
andDisplayOpts
instances managed by the masterDisplayContext
instance.
-
syncOverlayVolume
= <MagicMock name='mock.Boolean()' id='139845844115072'>¶ If
True
(the default), the volume/timepoint properties of theDisplayOpts
instances for every overlay, as managed by theDisplayContext
for thisCanvasPanel
, are linked to the properties of allDisplayOpts
instances managed by the masterDisplayContext
instance.
-
movieMode
= <MagicMock name='mock.Boolean()' id='139845844115072'>¶ If
True
, and the currently selected overlay (seeDisplayContext.selectedOverlay
) is aImage
instance with its display managed by aVolumeOpts
instance, the displayed volume is changed periodically, according to themovieRate
property.The update is performed on the main application thread via
wx.CallLater
.
-
movieRate
= <MagicMock name='mock.Int()' id='139845843069248'>¶ The movie update rate in milliseconds. The value of this property is inverted so that a high value corresponds to a fast rate, which makes more sense when displayed as an option to the user.
-
movieAxis
= <MagicMock name='mock.Choice()' id='139845843612560'>¶ Axis along which the movie should be played, relative to the currently selected
Image
.
-
movieSyncRefresh
= <MagicMock name='mock.Boolean()' id='139845844115072'>¶ Whether, when in movie mode, to synchronise the refresh for GL canvases. This is not possible in some platforms/environments.
-
__init__
(parent, overlayList, displayCtx, frame, sceneOpts)¶ Create a
CanvasPanel
.Parameters: - parent – The
wx
parent object. - overlayList – The
OverlayList
instance. - displayCtx – The
DisplayContext
instance. - sceneOpts – A
SceneOpts
instance for thisCanvasPanel
- must be created by sub-classes.
- parent – The
-
destroy
()¶ Makes sure that any remaining control panels are destroyed cleanly, and calls
ViewPanel.destroy()
.
-
screenshot
()¶ Takes a screenshot of the currently displayed scene on this
CanvasPanel
.See the
ScreenshotAction
.
-
movieGif
()¶ Generates an animated GIF of the currently displayed scene and movie mode settings on this
CanvasPanel
.See the
MovieGifAction
.
-
showCommandLineArgs
()¶ Shows the command line arguments which can be used to re-create the currently displayed scene. See the
ShowCommandLineAction
class.
-
applyCommandLineArgs
()¶ Shows the command line arguments which can be used to re-create the currently displayed scene. See the
ApplyCommandLineAction
class.
-
toggleDisplaySync
()¶ Toggles the value of
syncOverlayDisplay
.
-
toggleVolumeSync
()¶ Toggles the value of
syncOverlayVolume
.
-
toggleOverlayList
()¶ Toggles an
OverlayListPanel
. SeeViewPanel.togglePanel()
.
-
toggleOverlayInfo
(floatPane=False)¶ Toggles an
OverlayInfoPanel
. SeeViewPanel.togglePanel()
.
-
toggleAtlasPanel
()¶ Toggles an
AtlasPanel
. SeeViewPanel.togglePanel()
.
-
toggleDisplayToolBar
()¶ Toggles an
OverlayDisplayToolBar
. SeeViewPanel.togglePanel()
.
-
toggleDisplayPanel
(floatPane=False)¶ Toggles an
OverlayDisplayPanel
. SeeViewPanel.togglePanel()
.
-
toggleCanvasSettingsPanel
(floatPane=False)¶ Toggles a
CanvasSettingsPanel
. SeeViewPanel.togglePanel()
.
-
toggleLocationPanel
()¶ Toggles a
LocationPanel
. SeeViewPanel.togglePanel()
.
-
toggleClusterPanel
()¶ Toggles a
ClusterPanel
. SeeViewPanel.togglePanel()
.
-
toggleLookupTablePanel
()¶ Toggles a
LookupTablePanel
. SeeViewPanel.togglePanel()
.
-
toggleClassificationPanel
()¶ Toggles a
MelodicClassificationPanel
. SeeViewPanel.togglePanel()
.
-
contentPanel
¶ Returns the
wx.Panel
to which sub-classes must add their content. See the note on adding content.
-
containerPanel
¶ Returns the
wx.Panel
which contains theColourBarPanel
if it is being displayed, and the content panel. See the note on adding content.
-
colourBarCanvas
¶ If a colour bar is being displayed, this method returns the
ColourBarCanvas
instance which is used by theColourBarPanel
to render the colour bar.Otherwise,
None
is returned.
-
getSceneOptions
= <MagicMock name='mock.deprecated()()' id='139845843667040'>¶
-
getContentPanel
= <MagicMock name='mock.deprecated()()' id='139845843667040'>¶
-
getContainerPanel
= <MagicMock name='mock.deprecated()()' id='139845843667040'>¶
-
getColourBarCanvas
= <MagicMock name='mock.deprecated()()' id='139845843667040'>¶
-
getGLCanvases
()¶ This method must be overridden by subclasses, and must return a list containing all
SliceCanvas
instances which are being displayed.
-
centrePanelLayout
()¶ Lays out the centre panel. This method may be overridden by sub-classes which need more advanced layout logic. See the note on adding content
-
layoutContainerPanel
()¶ Creates a
wx.Sizer
, and uses it to lay out the colour bar panel and canvas panel. The sizer object is returned.This method is used by the default
centrePanelLayout()
method, and is available for custom sub-class implementations to use.
-
_CanvasPanel__bgfgColourChanged
(*a, **kwa)¶ Called when the
SceneOpts.bgColour
orSceneOpts.fgColour
properties change. Updates background/foreground colours.The
SliceCanvasOpts.bgColour
properties are bound toSceneOpts.bgColour
,(seeHasProperties.bindProps()
), so we don’t need to manually update them.Parameters: refresh – Must be passed as a keyword argument. If True
(the default), thisOrthoPanel
is refreshed.
-
_CanvasPanel__colourBarPropsChanged
(*a)¶ Called when any colour bar display properties are changed (see
SceneOpts
). CallscanvasPanelLayout()
.
-
_CanvasPanel__labelSizeChanged
(*a, **kwa)¶ Called when the
SceneOpts.lablSize
changes. If a colour bar is being displayed, it is updated, and the panel layout is refreshed.
-
_CanvasPanel__movieFrame
()¶ Called by
__movieLoop()
.If the currently selected overlay (see
DisplayContext.selectedOverlay
) is a 4DImage
being displayed as avolume
(see theVolumeOpts
class), theNiftiOpts.volume
property is incremented and all GL canvases in thisCanvasPanel
are refreshed.Returns: True
if the movie loop was started,False
otherwise.
-
_CanvasPanel__movieLoop
(startLoop=False)¶ Manages the triggering of the next movie frame. This method is called by
__movieModeChanged()
whenmovieMode
changes and when the selected overlay changes, and also by__syncMovieRefresh()
and__unsyncMovieRefresh()
while the movie loop is running, to trigger the next frame.Parameters: startLoop – This is set to True
when called from__movieModeChanged()
. IfTrue
, and the movie loop is already running, this method does nothing.
-
_CanvasPanel__movieModeChanged
(*a)¶ Called when the
movieMode
property changes. If it has been enabled, calls__movieUpdate()
, to start the movie loop.
-
_CanvasPanel__syncMovieRefresh
(canvases, rate)¶ Updates all canvases in a synchronised manner. All canvases are refreshed, and then the front/back buffers are swapped on each of them.
Parameters: - canvases – List of canvases to update. It is assumed that
FreezeDraw
andFreezeSwapBuffers
has been called on every canvas. - rate – Delay to trigger the next movie update.
- canvases – List of canvases to update. It is assumed that
-
_CanvasPanel__unsyncMovieRefresh
(canvases, rate)¶ Called by
__movieUpdate()
. Updates all canvases in an unsynchronised manner.Ideally all canvases should be drawn off-screen (i.e. rendered to the back buffer), and then all refreshed together (back and front buffers swapped). Unfortunately some OpenGL drivers seem to have trouble with this approach, and require drawing and front/back buffer swaps to be done at the same time. This method is used for those drivers.
Parameters: - canvases – List of canvases to update. It is assumed that
FreezeDraw
andFreezeSwapBuffers
has been called on every canvas. - rate – Delay to trigger the next movie update.
- canvases – List of canvases to update. It is assumed that
-
__module__
= 'fsleyes.views.canvaspanel'¶
-
canRunMovie
(overlay, opts)¶ Returns
True
orFalse
, depending on whether movie mode is possible with the given z`overlay`` andopts
.
-
getMovieFrame
(overlay, opts)¶ Returns the current movie frame for the given overlay.
A movie frame is typically a sequentially increasing number in some minimum/maximum range, e.g. a voxel or volume index.
This method may be overridden by sub-classes for custom behaviour (e.g. the
Scene3DPanel
).
-
doMovieUpdate
(overlay, opts)¶ Called by
__movieFrame()
. Updates the properties on the givenopts
instance to move forward one frame in the movie.This method may be overridden by sub-classes for custom behaviour (e.g. the
Scene3DPanel
).Returns: A value which identifies the current movie frame. This may be a volume or voxel index, or a world coordinate location on one axis.
- Add their content to the panel that is accessible via the