spyder.api.widgets.toolbars#

Spyder API toolbar widgets.

Module Attributes

ToolbarItem

Type alias for the set of supported objects that can be toolbar items.

ToolbarItemEntry

Type alias for the full tuple entry in the list of toolbar items.

Classes

ApplicationToolbar(parent, toolbar_id, title)

A Spyder main application toolbar.

MainWidgetToolbar([parent, title])

A Spyder dockable plugin toolbar.

SpyderToolbar(parent, title)

This class provides toolbars with some predefined functionality.

ToolbarLocation()

Pseudo-enum listing possible locations for a toolbar.

ToolbarStyle

Proxy style class to control the style of Spyder toolbars.

spyder.api.widgets.toolbars.ToolbarItem#

Type alias for the set of supported objects that can be toolbar items.

alias of SpyderAction | QWidget

spyder.api.widgets.toolbars.ToolbarItemEntry#

Type alias for the full tuple entry in the list of toolbar items.

alias of tuple[SpyderAction | QWidget, str | None, str | None, str | None]

class spyder.api.widgets.toolbars.ToolbarLocation[source]#

Bases: object

Pseudo-enum listing possible locations for a toolbar.

Top: ToolBarArea = 4#

Toolbar at the top of the layout.

Bottom: ToolBarArea = 8#

Toolbar at the bottom of the layout.

class spyder.api.widgets.toolbars.ToolbarStyle[source]#

Bases: QProxyStyle

Proxy style class to control the style of Spyder toolbars.

Deprecated since version 6.2: This class will be renamed to the private _ToolbarStyle in Spyder 6.2, while the current public name will become an alias raising a DeprecationWarning on use, and removed in 7.0.

It was never intended to be used directly by plugins, and its functionality is automatically inherited by using the appropriate ApplicationToolbar and MainWidgetToolbar classes.

TYPE: Literal['Application'] | Literal['MainWidget'] | None = None#

The toolbar type; must be either “Application” or “MainWidget”.

pixelMetric(
pm: PixelMetric,
option: QStyleOption,
widget: QWidget,
) int[source]#

Adjust size of toolbar extension button (in pixels).

From Stack Overflow.

This is a callback intended to be called internally by Qt.

Parameters:
  • pm (PixelMetric) – The pixel metric to calculate.

  • option (QStyleOption | None, optional) – The current style options, or None (default).

  • widget (QWidget | None, optional) – The widget the pixel metric will be used for, or None (default).

Returns:

The resulting pixel metric value, used internally by Qt.

Return type:

int

Raises:

SpyderAPIError – If TYPE is not "Application" or "MainWidget", as then this style would do nothing.

class spyder.api.widgets.toolbars.SpyderToolbar(parent: QWidget | None, title: str)[source]#

Bases: QToolBar

This class provides toolbars with some predefined functionality.

Caution

This class isn’t intended to be used directly; use its subclasses ApplicationToolbar and MainWidgetToolbar instead.

sig_is_rendered: Signal#

Signal to let other objects know that the toolbar is now rendered.

__init__(
parent: QWidget | None,
title: str,
) None[source]#

Create a new toolbar object.

Parameters:
  • parent (QWidget | None) – The parent widget of this one, or None.

  • title (str) – The localized title of this toolbar, to display in the UI.

Return type:

None

add_item(
action_or_widget: spyder.api.widgets.toolbars.ToolbarItem,
section: str | None = None,
before: str | None = None,
before_section: str | None = None,
omit_id: bool = False,
) None[source]#

Add action or widget item to the given toolbar section.

Parameters:
  • action_or_widget (ToolbarItem) – The item to add to the toolbar.

  • section (str | None, optional) – The section id in which to insert the action_or_widget, or None (default) for no section.

  • before (str | None, optional) – Make the action_or_widget appear before the action with the identifier before. If None (default), add it to the end. If before is not None, before_section will be ignored.

  • before_section (str | None, optional) – Make the section appear prior to before_section. If None (the default), add the section to the end. If you provide a before action, the new action will be placed before this one, so the section option will be ignored, since the action will now be placed in the same section as the before action.

  • omit_id (bool, optional) – If False, the default, then the toolbar will check if action.action_id exists and is set to a string, and raise an SpyderAPIError if either is not the case. If True, it will add the action_or_widget anyway.

Return type:

None

Raises:

SpyderAPIError – If omit_id is False (the default) and action_or_widget.action_id does not exist or is not set to a string.

remove_item(item_id: str) None[source]#

Remove the toolbar item with the given string identifier.

Parameters:

item_id (str) – The string identifier of the toolbar item to remove.

Return type:

None

render() None[source]#

Render the toolbar taking into account sections and locations.

Return type:

None

class spyder.api.widgets.toolbars.ApplicationToolbar(parent: QMainWindow, toolbar_id: str, title: str)[source]#

Bases: SpyderToolbar

A Spyder main application toolbar.

These toolbars are placed above all Spyder dockable plugins in the interface.

__init__(
parent: QMainWindow,
toolbar_id: str,
title: str,
) None[source]#

Create a main Spyder application toolbar.

Parameters:
  • parent (QMainWindow) – The parent main window of this toolbar.

  • toolbar_id (str) – The unique string identifier of this toolbar.

  • title (str) – The localized name of this toolbar, displayed in the interface.

Return type:

None

ID: str | None = None#

Unique string toolbar identifier.

This is used by Qt to be able to save and restore the state of widgets.

__str__() str[source]#

Output this toolbar’s class name and identifier as a string.

Returns:

The toolbar’s class name and string identifier, in the format :file:ApplicationToolbar({TOOLBAR_ID}).

Return type:

str

__repr__() str[source]#

Output this toolbar’s class name and identifier as a string.

Returns:

The menu’s class name and string identifier, in the format :file:ApplicationToolbar({TOOLBAR_ID}).

Return type:

str

class spyder.api.widgets.toolbars.MainWidgetToolbar(
parent: QWidget | None = None,
title: str | None = None,
)[source]#

Bases: SpyderToolbar

A Spyder dockable plugin toolbar.

This is used by dockable plugins to have their own toolbars.

ID: str | None = None#

Unique string toolbar identifier.

__init__(
parent: QWidget | None = None,
title: str | None = None,
) None[source]#

Create a new toolbar.

Parameters:
  • parent (QWidget | None, optional) – The parent widget of this one, or None (default).

  • title (str | None, optional) – The localized title of this toolbar, or None (default) for no title.

Return type:

None

set_icon_size(icon_size: QSize) None[source]#

Set the icon size for this toolbar.

Parameters:

icon_size (QSize) – The icon size to set.

Return type:

None