fsleyes.toolbar

This module provides the FSLeyesToolBar class, the base class for all toolbars in FSLeyes.

class fsleyes.toolbar.FSLeyesToolBar(parent, overlayList, displayCtx, frame, height=32, orient=<MagicMock name='mock.HORIZONTAL' id='140572300692880'>, *args, **kwargs)[source]

Bases: fsleyes.panel.FSLeyesPanel

Base class for all FSLeyes toolbars.

The FSLeyesToolBar is a regular wx.PyPanel which to which a group of tools can be added, where a tool may be any wx control.

See also the ControlToolBar, which is the true base-class for all toolbars that are added to FSLeyes view panels.

Tools can be added to a FSLeyesToolBar with the following methods:

AddTool

Adds the given tool to this FSLeyesToolBar.

InsertTool

Inserts the given tool into this FSLeyesToolBar, at the specified index.

InsertTools

Inserts the given sequence of tools into this FSLeyesToolBar, at the specified index.

SetTools

Replaces all of the existing tools in this FSLeyesToolBar with the given sequence of tools.

MakeLabelledTool

Creates a panel containing the given tool, and a label for the tool. The panel is returned, but is not added to this FSLeyesToolBar - you will have to do that yourself, e.g.::.

When the horizontal size of a FSLeyesToolBar becomes too small to display all of its tools, the toolbar is compressed: some tools are hidden, and buttons are displayed on each end of the toolbar, allowing the user to scroll through the toolbar, to access the hidden tools. The user may also use the mouse wheel to scroll through the toolbar.

A collapsed FSLeyesToolBar looks something like this:

_images/fsleyestoolbar.png
__init__(parent, overlayList, displayCtx, frame, height=32, orient=<MagicMock name='mock.HORIZONTAL' id='140572300692880'>, *args, **kwargs)[source]

Create a FSLeyesToolBar.

Parameters
  • parent – The wx parent object.

  • overlayList – The OverlayList, containing all overlays being displayed.

  • displayCtx – A DisplayContext, which defines how the overlays are to be displayed.

  • frame – The FSLeyesFrame object.

  • height – Desired toolbar height in pixels. This value is used to look up appropriately sized left/right arrow icons.

  • actionz – A dictionary of actions passed through to the ActionProvider.__init__().

All other arguments are passed through to FSLeyesPanel.__init__().

GetOrient()[source]

Returns the orientation of this FSLeyesToolBar, either wx.HORIZONTAL or wx.VERTICAL.

MakeLabelledTool(tool, labelText, labelSide=<MagicMock name='mock.TOP' id='140572300699264'>, expand=False)[source]

Creates a panel containing the given tool, and a label for the tool. The panel is returned, but is not added to this FSLeyesToolBar - you will have to do that yourself, e.g.:

labelledTool = toolbar.MakeLabelledTool(tool, 'Label', wx.BOTTOM)
toolbar.AddTool(labelledTool)
Parameters
  • tool – A wx control.

  • labelText – A label for the tool.

  • labelSide – Which side of the tool to put the label - wx.TOP, wx.BOTTOM, wx.LEFT, or wx.RIGHT.

  • expand – Defaults to False. If True, the widget and label will be set up so they expand to fit all available space

Enable(*args, **kwargs)[source]

Enables/disables all tools in this FSLeyesToolBar.

Parameters
  • args – Passed to the Enable method of each tool.

  • kwargs – Passed to the Enable method of each tool.

GetTools()[source]

Returns a list containing all tools in this FSLeyesToolBar.

GetToolCount()[source]

Returns the number of tools in this FSLeyesToolBar.

AddDivider()[source]

Adds a ToolBarDivider to the end of the toolbar.

InsertDivider(index=None)[source]

Inserts a ToolBarDivider into the toolbar at the specified index.

AddTool(tool)[source]

Adds the given tool to this FSLeyesToolBar.

InsertTools(tools, index=None)[source]

Inserts the given sequence of tools into this FSLeyesToolBar, at the specified index.

Parameters
  • tools – A sequence of tools to add.

  • index – Insert the tools before this index (default: end).

SetTools(tools, destroy=False)[source]

Replaces all of the existing tools in this FSLeyesToolBar with the given sequence of tools.

Parameters
  • tools – Sequence of new tools to add.

  • destroy – If True all of the old tools are destroyed.

InsertTool(tool, index=None, postevent=True, redraw=True)[source]

Inserts the given tool into this FSLeyesToolBar, at the specified index.

Parameters
  • tool – The tool to insert.

  • index – Index to insert the tool.

  • postevent – If True, a ToolBarEvent will be generated. Pass False to suppress this event.

  • redraw – If True, the toolbar is redrawn. Pass False to suppress this behaviour.

DoGetBestSize()[source]

Calculates and returns the best size for this toolbar, simply the minimum size that will fit all tools.

This method is called by wx when this toolbar is laid out.

ClearTools(destroy=False, startIdx=None, endIdx=None, postevent=True)[source]

Removes all tools, or a range of tools, from this FSLeyesToolBar.

Parameters
  • destroy – If True, the removed tools are destroyed.

  • startIdx – Start index of tools to remove. If not provided, defaults to 0.

  • endIdx – End index of tools to remove (exclusive). If not provided, defaults to GetToolCount().

  • postevent – If True, a ToolBarEvent will be generated. Set to False to suppress the event.

__onMouseWheel(ev)

Called when the mouse wheel is rotated on this FSLeyesToolBar.

Calls __onLeftButton() or __onRightButton(), depending on the rotation direction.

__onLeftButton(ev=None)

Called when the left toolbar button is pressed.

If the toolbar is compressed, it is scrolled to the left.

__onRightButton(ev=None)

Called when the right toolbar button is pressed.

If the toolbar is compressed, it is scrolled to the right.

__drawToolBar(*a)

Draws this FSLeyesToolBar.

If the toolbar is big enough, all tools are drawn. Otherwise, the method figures out out how many tools can be drawn, and which tools to draw, given the current size.

__annotations__ = {}
__module__ = 'fsleyes.toolbar'
fsleyes.toolbar.EVT_TOOLBAR_EVENT = <MagicMock id='140572333905600'>

Identifier for the ToolBarEvent event.

fsleyes.toolbar.ToolBarEvent = <MagicMock id='140572333905600'>

Event emitted when one or more tools is/are added/removed to/from a FSLeyesToolBar.

class fsleyes.toolbar.ToolBarDivider(parent, width=10, height=32, orient=<MagicMock name='mock.VERTICAL' id='140572302042656'>)[source]

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

An empty wx.Panel intended to be used for dividing space in a FSLeyesToolBar.

__annotations__ = {}
__module__ = 'fsleyes.toolbar'
__init__(parent, width=10, height=32, orient=<MagicMock name='mock.VERTICAL' id='140572302042656'>)[source]

Initialize self. See help(type(self)) for accurate signature.