fsleyes.frame

This module provides the FSLeyesFrame which is the top level frame for FSLeyes.

class fsleyes.frame.FSLeyesFrame(parent, overlayList, displayCtx, restore=False, save=True, fontSize=None, menu=True)[source]

Bases: __main__.docbuilder.run.<locals>.MockClass

A FSLeyesFrame is a simple wx.Frame which acts as a container for ViewPanel instances.

A wx.lib.agw.aui.AuiManager is used so that ViewPanel panels can be dynamically laid out and reconfigured by the user.

Menus

The FSLeyesFrame has the following menus:

FSLeyes

General actions, such as help, quit, about.

File

File actions such as adding a new overlay.

Overlay

Actions for working with overlays.

View

Options to open a new ViewPanel.

Settings

Options which are specific to the currently visible ViewPanel instances. A separate sub-menu is added for each visible ViewPanel. All ViewPanel classes inherit from the ActionProvider class - any actions that have been defined are added as menu items here.

Tools

Options which invoke some sort of tool - some global tools are added to this menu, along with tools that are specific to each active view.

Saving/restoring state

When a FSLeyesFrame is closed, it saves some display settings so that they can be restored the next time a FSLeyesFrame is opened. The settings are saved using the settings module. Currently, the frame position, size, and layout (see the layout module) are saved.

Programming interface

The FSLeyesFrame provides the following properties and methods for programmatically configuring the display:

overlayList

Returns the OverlayList which contains the overlays being displayed by this FSLeyesFrame.

displayCtx

Returns the top-level DisplayContext associated with this FSLeyesFrame.

viewPanels

Returns a list of all ViewPanel instances that are currenlty displayed in this FSLeyesFrame.

focusedViewPanel

Returns the ViewPanel which currently has focus, the first ViewPanel if none have focus, or None if there are no ViewPanels.

auiManager

Returns the wx.lib.agw.aui.AuiManager` object which is managing the layout of this ``FSLeyesFrame.

getViewPanelInfo

Returns the AuiPaneInfo class which contains layout information about the given ViewPanel.

getViewPanelID

Returns the ID that was assigned to the given ViewPanel.

getViewPanelTitle

Returns the ID that was assigned to the given ViewPanel.

addViewPanel

Adds a new ViewPanel to the centre of the frame, and a menu item allowing the user to configure the view.

viewPanelDefaultLayout

After a ViewPanel is added via the view menu, this method is called to perform some basic initialisation on the panel.

removeViewPanel

Removes the given ViewPanel from this FSLeyesFrame.

removeAllViewPanels

Removes all view panels from this FSLeyesFrame.

refreshViewMenu

Re-creates the View menu.

refreshLayoutMenu

Re-creates the View -> Layouts sub-menu.

refreshSettingsMenu

Re-creates the Settings menu.

refreshToolsMenu

Re-creates the Tools menu.

populateMenu

Creates menu items for every Action available on the given target, or for every named action in the actionNames list.

Close

Closes this FSLeyesFrame.

Actions

The fsleyes.actions.frameactions module contains some actions which are monkey-patched into the FSLeyesFrame class. These actions are made available to the user via menu items and/or keyboard shortcuts.

Note

All of the functions defined in the fsleyes.actions.frameactions module are treated as first-class methods of the FSLeyesFrame class (i.e. they are assumed to be present). They are only in a separate module to keep file sizes down.

__init__(parent, overlayList, displayCtx, restore=False, save=True, fontSize=None, menu=True)[source]

Create a FSLeyesFrame.

Parameters
  • parent – The wx parent object.

  • overlayList – The OverlayList.

  • displayCtx – The master DisplayContext.

  • restore – Restores previous saved layout. If False, no view panels will be displayed.

  • save – Save current layout when closed.

  • fontSize – Application-wide font size to use. Defaults to 10.

  • menu – Whether or not to create a menu bar.

property overlayList

Returns the OverlayList which contains the overlays being displayed by this FSLeyesFrame.

property displayCtx

Returns the top-level DisplayContext associated with this FSLeyesFrame.

property viewPanels

Returns a list of all ViewPanel instances that are currenlty displayed in this FSLeyesFrame.

property focusedViewPanel

Returns the ViewPanel which currently has focus, the first ViewPanel if none have focus, or None if there are no ViewPanels.

property menuActions

Returns a dictionary containing all global Action objects that are bound to menu items.

getOverlayList = <MagicMock name='mock.utils.deprecated.deprecated()()' id='4396606371632'>
getDisplayContext = <MagicMock name='mock.utils.deprecated.deprecated()()' id='4396606371632'>
getViewPanels = <MagicMock name='mock.utils.deprecated.deprecated()()' id='4396606371632'>
getFocusedViewPanel = <MagicMock name='mock.utils.deprecated.deprecated()()' id='4396606371632'>
getViewPanelID(viewPanel)[source]

Returns the ID that was assigned to the given ViewPanel. This is a sequentially increasing integer, starting from 1.

getViewPanelTitle(viewPanel)[source]

Returns the ID that was assigned to the given ViewPanel. This is a sequentially increasing integer, starting from 1.

getViewPanelInfo(viewPanel)[source]

Returns the AuiPaneInfo class which contains layout information about the given ViewPanel.

property auiManager

Returns the wx.lib.agw.aui.AuiManager` object which is managing the layout of this ``FSLeyesFrame.

getAuiManager = <MagicMock name='mock.utils.deprecated.deprecated()()' id='4396606371632'>
removeViewPanel(viewPanel)[source]

Removes the given ViewPanel from this FSLeyesFrame.

removeAllViewPanels()[source]

Removes all view panels from this FSLeyesFrame.

Note

This method should be used to clear the frame, rather than removing each ViewPanel individually via removeViewPanel(). This is because when one ViewPanel is closed, the display settings of the remaining ViewPanel instances may be modified. If these remaining ViewPanels are then immediately closed, thay may not have had enough time to reconfigure themselves (e.g. GLVolume instances re-creating their ImageTexture instance due to a change in DisplayContext.syncOverlayDisplay), and ugly things will happen (e.g. an ImageTexture trying to configure itself after it has already been destroyed).

So just use this method instead.

addViewPanel(panelCls, title=None, **kwargs)[source]

Adds a new ViewPanel to the centre of the frame, and a menu item allowing the user to configure the view.

Parameters
  • panelCls – The ViewPanel type to be added.

  • title – Title to give the view. If not provided, it is assumed that a name is present for the view type in strings.titles.

Returns

The newly created ViewPanel.

All other arguments are passed to the __init__ method of the child DisplayContext that is created for the new view.

viewPanelDefaultLayout(viewPanel)[source]

After a ViewPanel is added via the view menu, this method is called to perform some basic initialisation on the panel. This basically amounts to adding toolbars.

refreshViewMenu()[source]

Re-creates the View menu.

refreshLayoutMenu()[source]

Re-creates the View -> Layouts sub-menu.

refreshSettingsMenu()[source]

Re-creates the Settings menu.

refreshToolsMenu()[source]

Re-creates the Tools menu.

refreshPerspectiveMenu = <MagicMock name='mock.utils.deprecated.deprecated()()' id='4396606371632'>
populateMenu(menu, target, actionNames=None, actionTitles=None, **kwargs)[source]

Creates menu items for every Action available on the given target, or for every named action in the actionNames list.

Called by the __addViewPanelMenu() method to generate a menu for new ViewPanel instances, but can also be called for other purposes.

Parameters
  • menu – The wx.Menu to be populated.

  • target – The object which has actions to be bound to the menu items.

  • actionNames – If provided, only menu items for the actions named in this list will be created. May contain None, which indicates that a menu separator should be added at that point.

  • actionTitles – Optional dict containing {name : title} mappings for some actions. If not provided, it is assumed that a name for the action exists in strings.actions.

All other keyword arguments are passed through to the __onViewPanelMenuItem() method.

Returns

A list containing the (Action, wx.MenuItem) pairs that were added to the menu.

__addViewPanelMenu(panel, title)

Called by addViewPanel(). Adds a menu item for the newly created ViewPanel instance, and adds any tools for the view panel to the tools menu.

Parameters
  • panel – The newly created ViewPanel instance.

  • title – The name given to the panel.

__onViewPanelMenuItem(target, actionName, shortcut, ignoreFocus=False, runOnIdle=False)

Called when a menu item from a ViewPanel menu, or a menu otherwise created via createMenu(), is selected, either via menu selection, or from a bound keyboard shortcut. This callback is configured in the createMenu() method.

Parameters
  • target – The target instance for the action, most often a ViewPanel.

  • actionName – The name of the Action which is associated with the menu item.

  • shortcut – The keyboard shortcut code (see wx.AcceleratorEntry.ToString) associated with the menu item, of None if there is no shortcut.

  • ignoreFocus – If True, the action is executed on the target. Otherwise (the default), the action is executed on the currently focused ViewPanel.

  • runOnIdle – If True, the action is executed on the idle.idle loop. Otherwise (the default), the action is executed on the calling thread.

__onViewPanelClose(ev=None, panel=None, displaySync=True)

Called when the user closes a ViewPanel. May also be called programmatically via the removeViewPanel() or :removeAllViewPanels` :method.

The __addViewPanelMenu() method adds a Close menu item for every view panel, and binds it to this method.

This method does the following:

  1. Makes sure that the ViewPanel: is destroyed correctly

  2. Removes the Settings sub-menu corresponding to the ViewPanel.

  3. Makes sure that any remaining ViewPanel panels are arranged nicely.

  4. If the displaySync parameter is True, calls __configDisplaySync().

Parameters
  • evwx event, passed when a ViewPanel is closed by the user:

  • panel – If called programmatically, the ViewPanel to close.

  • displaySync – If True (the default), and only one ViewPanel remains after this one is removed, that remaining ViewPanel is synchronised to the master DisplayContext.

__configDisplaySync(newPanel=None)

Called by addViewPanel() and __onViewPanelClose().

This method ensures that the display properties, overlay order, and selected overlay for the DisplayContext of at least least one CanvasPanel is synced to the master DisplayContext.

Parameters

newPanel – If this method has been called as a result of a new ViewPanel being added, a reference to the new panel.

Close(**kwargs)[source]

Closes this FSLeyesFrame. See __onClose().

Parameters
  • askUnsaved – Defaults to True. If False, the user is not asked whether they want to save any unsaved overlays.

  • askLayout – Defaults to the save value passed to __init__(). Controls whether the user is asked if they want to save the current layout.

__onClose(ev)

Called when the user closes this FSLeyesFrame.

Saves the frame position, size, and layout, so it may be preserved the next time it is opened. See the _restoreState() method.

__restoreState(restore)

Called by __init__().

If any frame size/layout properties have previously been saved via the settings module, they are read in, and applied to this frame.

Parameters

restore – If False, any saved layout state is ignored.

__makeMenuBar()

Constructs a bunch of menu items for this FSLeyesFrame.

__enableMenus(state)

Enables/disables some of the menus. Only the menus which are useless without any view panels open are affected.

__makeFSLeyesMenu(menu)

Called by __makeMenuBar(). Creates the FSLeyes menu.

__makeFileMenu()

Called by __makeMenuBar(). Creates the File menu.

__makeRecentPathsMenu(*a)

Populates the “File -> Recent files” menu. This method is called by the __makeFileMenu(), and also by the RecentPathManager when paths are added.

__onRecentPath(ev)

Called when a recent path is selected from the “File -> Recent files” menu item. Loads the path. See the __makeRecentPathsMenu() method.

__makeViewMenu()

Called by refreshViewMenu(). Creates the view panel menu.

Returns

A list containing the (Action, wx.MenuItem) pairs that were added to the menu.

__makeLayoutMenu()

Called by refreshLayoutMenu(). Re-creates the View->Layouts menu.

__makeOverlayMenu()

Called by __makeMenuBar(). Creates/configures the Overlay menu.

__makeToolsMenu()

Called by refreshToolsMenu(). Populates the Tools menu with tools that are not bound to a specific ViewPanel (and which are always present).

__makeViewPanelTools()

Called when a view panel is added or removed. Refreshes the Tools menu.

__selectedOverlayChanged(*a)

Called when the DisplayContext.selectedOverlay, or when the Display.name property of the currently selected overlay changes. Updates the overlay name item in the Overlay menu*.

__module__ = 'fsleyes.frame'
addHistogramPanel(*args, **kwargs)

Adds a new HistogramPanel.

addLightBoxPanel(*args, **kwargs)

Adds a new LightBoxPanel.

addOrthoPanel(*args, **kwargs)

Adds a new OrthoPanel.

addPowerSpectrumPanel(*args, **kwargs)

Adds a new PowerSpectrumPanel.

addScene3DPanel(*args, **kwargs)

Adds a new Scene3DPanel.

addShellPanel(*args, **kwargs)

Adds a new ShellPanel.

addTimeSeriesPanel(*args, **kwargs)

Adds a new TimeSeriesPanel.

closeFSLeyes(*args, **kwargs)

Closes FSLeyes.

openHelp(*args, **kwargs)

Opens FSLeyes help in a web browser.

removeFocusedViewPanel(*args, **kwargs)

Removes the ViewPanel which currently has focus.

selectNextOverlay(*args, **kwargs)

Increments the DisplayContext.selectedOverlay.

selectPreviousOverlay(*args, **kwargs)

Decrements the DisplayContext.selectedOverlay.

setFSLDIR(*args, **kwargs)

Opens a directory dialog allowing the user to select a value for $FSLDIR.

toggleOverlayVisibility(*args, **kwargs)

Shows/hides the currently selected overlay.