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(*args, **kwargs)[source]
Bases:
ViewPanelThe
CanvasPanelclass is aViewPanelwhich is the base class for all panels which display overlays usingOpenGL(e.g. theOrthoPaneland theLightBoxPanel). ACanvasPanelinstance uses aSceneOptsinstance to control much of its functionality. TheSceneOptsinstance used by aCanvasPanelcan be accessed via thesceneOpts()property.The
CanvasPanelclass 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
CanvasPanelmust 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.Call
ViewPanel.initProfile()with the initial interaction profile
Actions
The following actions are available through a
CanvasPanel(see theactionsmodule):Takes a screenshot of the currently displayed scene on this
CanvasPanel.Generates an animated GIF of the currently displayed scene and movie mode settings on this
CanvasPanel.Shows the command line arguments which can be used to re-create the currently displayed scene.
Toggles the value of
movieMode.Toggles the value of
syncOverlayDisplay.Toggles the value of
syncOverlayVolume.Adding content
To support colour bar and screenshot functionality, the
CanvasPaneluses a hierarchy ofwx.Panelinstances, 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. ThecentrePanelLayoutmethod simply adds the canvas container directly to the centre panel. Sub-classes which have more advanced layout requirements (e.g. theLightBoxPanelneeds 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
If
True(the default), theDisplayContext.locationfor thisCanvasPanelis linked to the masterDisplayContextlocation.
- syncOverlayOrder
If
True(the default), theDisplayContext.overlayOrderfor thisCanvasPanelis linked to the masterDisplayContextoverlay order.
- syncOverlayDisplay
If
True(the default), the properties of theDisplayandDisplayOptsinstances for every overlay, as managed by theDisplayContextfor thisCanvasPanel, are linked to the properties of allDisplayandDisplayOptsinstances managed by the masterDisplayContextinstance.
- syncOverlayVolume
If
True(the default), the volume/timepoint properties of theDisplayOptsinstances for every overlay, as managed by theDisplayContextfor thisCanvasPanel, are linked to the properties of allDisplayOptsinstances managed by the masterDisplayContextinstance.
- movieMode
If
True, and the currently selected overlay (seeDisplayContext.selectedOverlay) is aImageinstance with its display managed by aVolumeOptsinstance, the displayed volume is changed periodically, according to themovieRateproperty.The update is performed on the main application thread via
wx.CallLater.
- movieRate
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
Axis along which the movie should be played, relative to the currently selected
Image.
- movieSyncRefresh
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
wxparent object.overlayList – The
OverlayListinstance.displayCtx – The
DisplayContextinstance.sceneOpts – A
SceneOptsinstance for thisCanvasPanel- must be created by sub-classes.
- Arb frame:
The
FSLeyesFrameinstance.
- 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
ShowCommandLineActionclass.
- applyCommandLineArgs()[source]
Shows the command line arguments which can be used to re-create the currently displayed scene. See the
ApplyCommandLineActionclass.
- toggleDisplaySync()[source]
Toggles the value of
syncOverlayDisplay.
- toggleVolumeSync()[source]
Toggles the value of
syncOverlayVolume.
- property contentPanel
Returns the
wx.Panelto which sub-classes must add their content. See the note on adding content.
- property containerPanel
Returns the
wx.Panelwhich contains theColourBarPanelif 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
ColourBarCanvasinstance which is used by theColourBarPanelto render the colour bar.Otherwise,
Noneis returned.
- getGLCanvases()[source]
This method must be overridden by subclasses, and must return a list containing all
SliceCanvasinstances 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). CallscanvasPanelLayout().
- __labelSizeChanged(*a, **kwa)
Called when the
SceneOpts.lablSizechanges. If a colour bar is being displayed, it is updated, and the panel layout is refreshed.
- __bgfgColourChanged(*a, **kwa)
Called when the
SceneOpts.bgColourorSceneOpts.fgColourproperties change. Updates background/foreground colours.The
SliceCanvasOpts.bgColourproperties 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), thisOrthoPanelis refreshed.
- __annotations__ = {}
- __module__ = 'fsleyes.views.canvaspanel'
- __movieModeChanged(*a)
Called when the
movieModeproperty 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()whenmovieModechanges 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
Truewhen called from__movieModeChanged(). IfTrue, and the movie loop is already running, this method does nothing.
- canRunMovie(overlay, opts)[source]
Returns
TrueorFalse, depending on whether movie mode is possible with the given z`overlay`` andopts.
- 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 givenoptsinstance 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 4DImagebeing displayed as avolume(see theVolumeOptsclass), theNiftiOpts.volumeproperty is incremented and all GL canvases in thisCanvasPanelare refreshed.- Returns:
Trueif the movie loop was started,Falseotherwise.
- 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
movieSyncRefreshproperty.