spyder.api.widgets.menus#
Spyder API menu widgets.
Module Attributes
Constant representing a separator line between groups in a menu. |
|
Generic |
Classes
Pseudo-enum listing sections in the pane options (hamburger) menu. |
|
Pseudo-enum listing the menu types dockable plugin main widgets have. |
|
|
Options menu for |
|
A QMenu subclass implementing additional functionality for Spyder. |
Menu style adjustments that can only be done with a proxy style. |
- spyder.api.widgets.menus.MENU_SEPARATOR: None = None#
Constant representing a separator line between groups in a menu.
- class spyder.api.widgets.menus.T#
Generic
SpyderMenutype variable (TypeVar).alias of TypeVar(‘T’, bound=
SpyderMenu)
- class spyder.api.widgets.menus.OptionsMenuSections[source]#
Bases:
objectPseudo-enum listing sections in the pane options (hamburger) menu.
- class spyder.api.widgets.menus.PluginMainWidgetMenus[source]#
Bases:
objectPseudo-enum listing the menu types dockable plugin main widgets have.
- class spyder.api.widgets.menus.SpyderMenuProxyStyle[source]#
Bases:
QProxyStyleMenu style adjustments that can only be done with a proxy style.
Deprecated since version 6.2: This class will be moved to the private
_SpyderMenuProxyStylein Spyder 6.2, while the current public name will become an alias raising aDeprecationWarningon use, and removed in 7.0.It was never intended to be used directly by plugins, and its functionality is automatically inherited by using
SpyderMenu.- pixelMetric(
- metric: PixelMetric,
- option: QStyleOption | None = None,
- widget: QWidget | None = None,
Calculate the value of the given pixel metric.
This is a callback intended to be called internally by Qt.
- Parameters:
metric (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:
- class spyder.api.widgets.menus.SpyderMenu(
- parent: QWidget | None = None,
- menu_id: str | None = None,
- title: str | None = None,
- min_width: int | None = None,
- reposition: bool = True,
Bases:
QMenu,SpyderFontsMixinA QMenu subclass implementing additional functionality for Spyder.
All menus in Spyder must inherit from this class.
- MENUS: list[tuple[QWidget | None, str | None, SpyderMenu]] = []#
List of 3-tuples, one per menu, describing each menu.
Contains the menu’s parent widget object, its name as a string, and the
SpyderMenuobject itself, in that order.
- APP_MENU: bool = False#
Whether this is a main application menu or a plugin menu.
Set this to
Trueif this is an application menu;Falseotherwise.
- HORIZONTAL_MARGIN_FOR_ITEMS: int = 6#
The QSS horizontal (left/right) margin for menu items, in pixels.
- HORIZONTAL_PADDING_FOR_ITEMS: int = 9#
The QSS horizontal (left/right) padding for menu items, in pixels.
- __init__(
- parent: QWidget | None = None,
- menu_id: str | None = None,
- title: str | None = None,
- min_width: int | None = None,
- reposition: bool = True,
Create a menu for Spyder.
- Parameters:
parent (QWidget | None, optional) – The menu’s parent widget, or
Noneif no parent.menu_id (str | None, optional) – Unique string identifier for the menu, or
Noneif no ID.title (str | None, optional) – Localized title for the menu, or
None(default) if no title.min_width (int or None, optional) – Minimum width for the menu, or
None(default) for no min width.reposition (bool, optional) – Whether to vertically reposition the menu due to its padding.
Trueby default.
- Return type:
None
- clear_actions() → None[source]#
Remove actions from the menu (including custom references).
- Return type:
None
- add_action(
- action: spyder.utils.qthelpers.SpyderAction | SpyderMenu,
- section: str | None = None,
- before: str | None = None,
- before_section: str | None = None,
- check_before: bool = True,
- omit_id: bool = False,
Add action to a given menu section.
- Parameters:
action (spyder.utils.qthelpers.SpyderAction | SpyderMenu) – The action or menu object to add to the menu.
section (str | None, optional) – The section id in which to insert the
action, orNone(default) for no section.before (str | None, optional) – Make the
actionappear before the action with the identifierbefore. IfNone(default), add it to the end.before_section (str | None, optional) – Make the item section appear prior to
before_section. IfNone(the default), add the section to the end.check_before (bool, optional) – Check if the
beforeaction is already part of the menu before adding this one, and if so save it to be added later. This is necessary to avoid an infinite recursion when adding unintroduced actions with this method again.Trueby default.omit_id (bool, optional) – If
False, the default, then the menu will check ifaction.action_idexists and is set to a string, and raise anAttributeErrorif either is not the case. IfTrue, it will add theactionanyway.
- Return type:
None
- Raises:
AttributeError – If
omit_idisFalse(the default) andaction.action_iddoes not exist or is not set to a string.
- remove_action(item_id: str) → None[source]#
Remove the action with the given string identifier.
- Parameters:
item_id (str) – The string identifier of the action to remove.
- Return type:
None
- get_title() → str | None[source]#
Return the title for the menu.
- Returns:
The menu’s title, or
Noneif it doesn’t have one set.- Return type:
str | None
- get_actions() → list[SpyderMenu | spyder.utils.qthelpers.SpyderAction][source]#
Return a parsed list of menu items/actions.
Includes a
MENU_SEPARATORbetween each defined menu section.- Returns:
The list of menu items/actions for this menu.
- Return type:
list[SpyderMenu | spyder.utils.qthelpers.SpyderAction]
- render(force: bool = False) → None[source]#
Create the menu prior to showing it. This takes into account sections and location of menus.
- Parameters:
force (bool, optional) – Whether to force rendering the menu.
- __str__() → str[source]#
Output this menu’s class name and identifier as a string.
- Returns:
The menu’s class name and string identifier, in the format :file:
SpyderMenu({MENU_ID}).- Return type:
- __repr__() → str[source]#
Output this menu’s class name and identifier as a string.
- Returns:
The menu’s class name and string identifier, in the format :file:
SpyderMenu({MENU_ID}).- Return type:
- showEvent(event: QShowEvent) → None[source]#
Perform adjustments when the menu is going to be shown.
- Parameters:
event (QShowEvent) – The event object showing the menu.
- Return type:
None