fsleyes.layouts

This module provides functions for managing layouts - stored view and control panel layouts for FSLeyes. Layouts may be persisted using the settings module. A few layouts are also built in, and are defined in the BUILT_IN_LAYOUTS dictionary.

Note

Prior to FSLeyes 0.24.0, layouts were called perspectives.

The layouts module provides the following functions. These are intended for use by the FSLeyesFrame, but can be used in other ways too:

getAllLayouts

Returns a list containing the names of all saved layouts.

loadLayout

Load the named layout, and apply it to the given FSLeyesFrame.

applyLayout

Applies the given serialised layout string to the given FSLeyesFrame.

saveLayout

Serialises the layout of the given FSLeyesFrame and saves it as a layout with the given name.

removeLayout

Deletes the named layout.

serialiseLayout

Serialises the layout of the given FSLeyesFrame, and returns it as a string.

deserialiseLayout

Deserialises a layout string which was created by the serialiseLayout() string.

A layout defines a layout for a FSLeyesFrame. It specifies the type and layout of one or more views (defined in the views module) and, within each view, the type and layout of one or more controls (defined in the controls module). See the fsleyes documentation for an overview of views and controls.

All of this information is stored as a string - see the serialiseLayout() function for details on its storage format.

fsleyes.layouts.getAllLayouts()

Returns a list containing the names of all saved layouts. The returned list does not include built-in layouts - these are accessible in the BUILT_IN_LAYOUTS dictionary.

fsleyes.layouts.loadLayout(frame, name, **kwargs)

Load the named layout, and apply it to the given FSLeyesFrame. The kwargs are passed through to the applyLayout() function.

fsleyes.layouts.applyLayout(frame, name, layout, message=None)

Applies the given serialised layout string to the given FSLeyesFrame.

Parameters
  • frame – The FSLeyesFrame instance.

  • name – The layout name.

  • layout – The serialised layout string.

  • message – A message to display (using the status module).

fsleyes.layouts.saveLayout(frame, name)

Serialises the layout of the given FSLeyesFrame and saves it as a layout with the given name.

fsleyes.layouts.removeLayout(name)

Deletes the named layout.

fsleyes.layouts.serialiseLayout(frame)

Serialises the layout of the given FSLeyesFrame, and returns it as a string.

Note

This function was written against wx.lib.agw.aui.AuiManager as

it exists in wxPython 3.0.2.0.

FSLeyes uses a hierarchy of wx.lib.agw.aui.AuiManager instances for its layout - the FSLeyesFrame uses an AuiManager to lay out ViewPanel instances, and each of these ViewPanels use their own AuiManager to lay out control panels.

The layout for a single AuiManager can be serialised to a string via the AuiManager.SavePerspective and AuiManager.SavePaneInfo methods. One of these strings consists of:

  • A name, ‘layout1’ or ‘layout2’, specifying the AUI version (this will always be at least ‘layout2’ for FSLeyes).

  • A set of key-value set of key-value pairs defining the top level panel layout.

  • A set of key-value pairs for each pane, defining its layout. the AuiManager.SavePaneInfo method returns this for a single pane.

These are all encoded in a single string, with the above components separated with ‘|’ characters, and the pane-level key-value pairs separated with a ‘;’ character. For example:

layout2|key1=value1|name=Pane1;caption=Pane 1| name=Pane2;caption=Pane 2|doc_size(5,0,0)=22|

This function queries each of the AuiManagers, and extracts the following:

  • A layout string for the FSLeyesFrame.

  • A string containing a comma-separated list of ViewPanel class names, in the same order as they are specified in the frame layout string.

  • For each ViewPanel:

    • A layout string for the ViewPanel

    • A string containing a comma-separated list of control panel class names, in the same order as specified in the ViewPanel layout string.

Each of these pieces of information are then concatenated into a single newline separated string.

fsleyes.layouts.deserialiseLayout(layout)

Deserialises a layout string which was created by the serialiseLayout() string.

Returns

A tuple containing the following:

  • A list of ViewPanel class types - the children of the FSLeyesFrame.

  • An aui layout string for the FSLeyesFrame

  • A list of lists, one for each ViewPanel, with each list containing a collection of control panel class types - the children of the corresponding ViewPanel.

  • A list of strings, one aui layout string for each ViewPanel.

  • A list of dictionaries, one for each ViewPanel, containing property {name : value} pairs to be applied to the ViewPanel.

  • A list of dictionaries, one for each ViewPanel, containing property {name : value} pairs to be applied to the SceneOpts instance associated with the ViewPanel. If the ViewPanel is not a CanvasPanel, the dictionary will be empty.

fsleyes.layouts._addToLayoutList(layout)

Adds the given layout name to the list of saved layouts.

fsleyes.layouts._removeFromLayoutList(layout)

Removes the given layout name from the list of saved layouts.

fsleyes.layouts._addControlPanel(viewPanel, panelType)

Adds a control panel to the given ViewPanel.

Parameters
  • viewPanel – A ViewPanel instance.

  • panelType – A control panel type.

fsleyes.layouts._getPanelProps(panel)

Creates and returns two dictionaries, containing properties of the given ViewPanel (and its associated SceneOpts instance, if it is a CanvasPanel), which are to be saved as part of a seriaised FSLeyes layout. The properties to be saved are listed in the VIEWPANEL_PROPS dictionary.