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
()[source]¶ 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)[source]¶ Load the named layout, and apply it to the given
FSLeyesFrame
. Thekwargs
are passed through to theapplyLayout()
function.
-
fsleyes.layouts.
applyLayout
(frame, name, layout, message=None)[source]¶ 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).
- frame – The
-
fsleyes.layouts.
saveLayout
(frame, name)[source]¶ Serialises the layout of the given
FSLeyesFrame
and saves it as a layout with the given name.
-
fsleyes.layouts.
serialiseLayout
(frame)[source]¶ 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 - theFSLeyesFrame
uses anAuiManager
to lay outViewPanel
instances, and each of theseViewPanels
use their ownAuiManager
to lay out control panels.The layout for a single
AuiManager
can be serialised to a string via theAuiManager.SavePerspective
andAuiManager.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.
- A layout string for the
Each of these pieces of information are then concatenated into a single newline separated string.
-
fsleyes.layouts.
deserialiseLayout
(layout)[source]¶ 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 theFSLeyesFrame
. - An
aui
layout string for theFSLeyesFrame
- A list of lists, one for each
ViewPanel
, with each list containing a collection of control panel class types - the children of the correspondingViewPanel
. - A list of strings, one
aui
layout string for eachViewPanel
. - A list of dictionaries, one for each
ViewPanel
, containing property{name : value}
pairs to be applied to theViewPanel
. - A list of dictionaries, one for each
ViewPanel
, containing property{name : value}
pairs to be applied to theSceneOpts
instance associated with theViewPanel
. If theViewPanel
is not aCanvasPanel
, the dictionary will be empty.
- A list of
-
fsleyes.layouts.
_addToLayoutList
(layout)[source]¶ Adds the given layout name to the list of saved layouts.
-
fsleyes.layouts.
_removeFromLayoutList
(layout)[source]¶ Removes the given layout name from the list of saved layouts.
-
fsleyes.layouts.
_addControlPanel
(viewPanel, panelType)[source]¶ Adds a control panel to the given
ViewPanel
.Parameters: - viewPanel – A
ViewPanel
instance. - panelType – A control panel type.
- viewPanel – A
-
fsleyes.layouts.
_getPanelProps
(panel)[source]¶ Creates and returns two dictionaries, containing properties of the given
ViewPanel
(and its associatedSceneOpts
instance, if it is aCanvasPanel
), which are to be saved as part of a seriaised FSLeyes layout. The properties to be saved are listed in theVIEWPANEL_PROPS
dictionary.