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)[source]

Bases: fsleyes.views.viewpanel.ViewPanel

The CanvasPanel class is a ViewPanel which is the base class for all panels which display overlays using OpenGL (e.g. the OrthoPanel and the LightBoxPanel). A CanvasPanel instance uses a SceneOpts instance to control much of its functionality. The SceneOpts instance used by a CanvasPanel can be accessed via the sceneOpts() property.

The CanvasPanel class contains settings and functionality common to all sub-classes, including movie mode (see movieMode), the ability to show a colour bar (a ColourBarPanel; see SceneOpts.showColourBar), and a number of actions.

Sub-class implementations

Sub-classes of the CanvasPanel must do the following:

  1. Add their content to the panel that is accessible via the contentPanel() property (see the note on adding content).

  2. Override the getGLCanvases() method.

  3. Call the centrePanelLayout() method in their __init__ method.

  4. Override the centrePanelLayout() method if any custom layout is necessary.

  5. Call ViewPanel.initProfile() with the initial interaction profile

Actions

The following actions are available through a CanvasPanel (see the actions 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.

Adding content

To support colour bar and screenshot functionality, the CanvasPanel uses a hierarchy of wx.Panel instances, depicted in the following containment hierarchy diagram:

digraph canvasPanel { graph [size=""]; node [style="filled", shape="box", fillcolor="#ddffdd", fontname="sans"]; rankdir="BT"; 1 [label="CanvasPanel"]; 2 [label="Centre panel"]; 3 [label="Custom content (for complex layouts)"]; 4 [label="Container panel"]; 5 [label="ColourBarPanel"]; 6 [label="Content panel"]; 7 [label="Content added by sub-classes"]; 2 -> 1; 3 -> 2; 4 -> 2; 5 -> 4; 6 -> 4; 7 -> 6; }

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, via containerPanel(). Everything in the container panel will appear in screenshots (see the screenshot() method).

The centrePanelLayout() method lays out the centre panel, using the layoutContainerPanel() method to lay out the colour bar and the content panel. The centrePanelLayout method simply adds the canvas container directly to the centre panel. Sub-classes which have more advanced layout requirements (e.g. the LightBoxPanel needs a scrollbar) may override the centrePanelLayout() method to implement their own layout. These sub-class implementations must:

  1. Call the layoutContainerPanel() method.

  2. Add the container panel (accessed via containerPanel()) to the centre panel (accessed via centrePanel()).

  3. Add any other custom content to the centre panel.

syncLocation = <MagicMock name='mock.Boolean()' id='4118803744'>

If True (the default), the DisplayContext.location for this CanvasPanel is linked to the master DisplayContext location.

syncOverlayOrder = <MagicMock name='mock.Boolean()' id='4118803744'>

If True (the default), the DisplayContext.overlayOrder for this CanvasPanel is linked to the master DisplayContext overlay order.

syncOverlayDisplay = <MagicMock name='mock.Boolean()' id='4118803744'>

If True (the default), the properties of the Display and DisplayOpts instances for every overlay, as managed by the DisplayContext for this CanvasPanel, are linked to the properties of all Display and DisplayOpts instances managed by the master DisplayContext instance.

syncOverlayVolume = <MagicMock name='mock.Boolean()' id='4118803744'>

If True (the default), the volume/timepoint properties of the DisplayOpts instances for every overlay, as managed by the DisplayContext for this CanvasPanel, are linked to the properties of all DisplayOpts instances managed by the master DisplayContext instance.

movieMode = <MagicMock name='mock.Boolean()' id='4118803744'>

If True, and the currently selected overlay (see DisplayContext.selectedOverlay) is a Image instance with its display managed by a VolumeOpts instance, the displayed volume is changed periodically, according to the movieRate property.

The update is performed on the main application thread via wx.CallLater.

movieRate = <MagicMock name='mock.Int()' id='4117859440'>

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='4118567808'>

Axis along which the movie should be played, relative to the currently selected Image.

movieSyncRefresh = <MagicMock name='mock.Boolean()' id='4118803744'>

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)[source]

Create a CanvasPanel.

Parameters
  • parent – The wx parent object.

  • overlayList – The OverlayList instance.

  • displayCtx – The DisplayContext instance.

  • sceneOpts – A SceneOpts instance for this CanvasPanel - must be created by sub-classes.

Arb frame

The FSLeyesFrame instance.

destroy()[source]

Makes sure that any remaining control panels are destroyed cleanly, and calls ViewPanel.destroy().

screenshot()[source]

Takes a screenshot of the currently displayed scene on this CanvasPanel.

See the ScreenshotAction.

movieGif()[source]

Generates an animated GIF of the currently displayed scene and movie mode settings on this CanvasPanel.

See the MovieGifAction.

showCommandLineArgs()[source]

Shows the command line arguments which can be used to re-create the currently displayed scene. See the ShowCommandLineAction class.

applyCommandLineArgs()[source]

Shows the command line arguments which can be used to re-create the currently displayed scene. See the ApplyCommandLineAction class.

toggleMovieMode()[source]

Toggles the value of movieMode.

toggleDisplaySync()[source]

Toggles the value of syncOverlayDisplay.

toggleVolumeSync()[source]

Toggles the value of syncOverlayVolume.

property sceneOpts

Returns the SceneOpts instance used by this CanvasPanel.

property contentPanel

Returns the wx.Panel to which sub-classes must add their content. See the note on adding content.

property containerPanel

Returns the wx.Panel which contains the ColourBarPanel if it is being displayed, and the content panel. See the note on adding content.

property colourBarCanvas

If a colour bar is being displayed, this method returns the ColourBarCanvas instance which is used by the ColourBarPanel to render the colour bar.

Otherwise, None is returned.

getGLCanvases()[source]

This method must be overridden by subclasses, and must return a list containing all SliceCanvas instances which are being displayed.

centrePanelLayout()[source]

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()[source]

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.

__colourBarPropsChanged(*a)

Called when any colour bar display properties are changed (see SceneOpts). Calls canvasPanelLayout().

__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.

__bgfgColourChanged(*a, **kwa)

Called when the SceneOpts.bgColour or SceneOpts.fgColour properties change. Updates background/foreground colours.

The SliceCanvasOpts.bgColour properties are bound to SceneOpts.bgColour,(see HasProperties.bindProps()), so we don’t need to manually update them.

Parameters

refresh – Must be passed as a keyword argument. If True (the default), this OrthoPanel is refreshed.

__annotations__ = {}
__module__ = 'fsleyes.views.canvaspanel'
__movieModeChanged(*a)

Called when the movieMode property changes. If it has been enabled, calls __movieUpdate(), to start the movie loop.

__movieLoop(startLoop=False)

Manages the triggering of the next movie frame. This method is called by __movieModeChanged() when movieMode 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(). If True, and the movie loop is already running, this method does nothing.

canRunMovie(overlay, opts)[source]

Returns True or False, depending on whether movie mode is possible with the given z`overlay`` and opts.

getMovieFrame(overlay, opts)[source]

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)[source]

Called by __movieFrame(). Updates the properties on the given opts 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.

__movieFrame()

Called by __movieLoop().

If the currently selected overlay (see DisplayContext.selectedOverlay) is a 4D Image being displayed as a volume (see the VolumeOpts class), the NiftiOpts.volume property is incremented and all GL canvases in this CanvasPanel are refreshed.

Returns

True if the movie loop was started, False otherwise.

movieSync()[source]

Called by __movieUpdate(). Updates all GL canvases, attempting to refresh them in a synchronised 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 will refresh the GL canvases in either a synchronised or unsynchronised manner, depending upon the value of the movieSyncRefresh property.