8.5.3.1. pymodaq_gui.managers.action_manager module

class pymodaq_gui.managers.action_manager.ActionManager(toolbar=None, menu=None)[source]

Bases: object

MixIn Class to be used by all UserInterface to manage their QActions and the action they are connected to

Parameters:
  • toolbar (QToolBar) – The toolbar to use as default

  • menu (QMenu) – The menu to use as default

Attributes:
actions
actions_names
menu

Get the default menu

menus

Get all menus

menus_names

Get all menu names

toolbar

Get the default toolbar

toolbars

Get all toolbars

toolbars_names

Get all toolbar names

Methods

add_action([short_name, name, icon_name, ...])

Create a new action and add it to toolbar and menu

add_menu(short_name, title[, menu, ...])

Create and add a menu to a parent menu

add_toolbar(short_name[, title, parent])

Create and add a toolbar

add_widget(short_name, klass, *args[, tip, ...])

Create and add a widget to a toolbar

affect_to(action_name, obj)

Affect action to an object either a toolbar or a menu

connect_action(name[, slot, connect, ...])

Connect (or disconnect) the action referenced by name to the given slot

get_action(name)

Getter of a given action

get_menu(name)

Getter of a given menu

get_toolbar(name)

Getter of a given toolbar

has_action(action_name)

Check if an action has been defined :type action_name: str :param action_name: The action name as defined in setup_actions :type action_name: str

has_menu(menu_name)

Check if a menu has been defined

has_toolbar(toolbar_name)

Check if a toolbar has been defined

reference_menu(short_name, menu)

Add an existing toolbar to the list of managed toolbars

reference_toolbar(short_name, toolbar)

Add an existing toolbar to the list of managed toolbars

set_action_text(action_name, text)

Convenience method to set the displayed text on an action

set_menu(menu)

Set the default menu

set_toolbar(toolbar)

Set the default toolbar

setup_actions()

Method where to create actions to be subclassed.

is_action_checked

is_action_enabled

is_action_visible

set_action_checked

set_action_enabled

set_action_visible

add_action(short_name='', name='', icon_name='', tip='', checkable=False, checked=False, toolbar=None, menu=None, visible=True, shortcut=None, auto_toolbar=True, auto_menu=True, enabled=True)[source]

Create a new action and add it to toolbar and menu

Parameters:
  • short_name (str) – the name as referenced in the dict self.actions

  • name (str) – Displayed name if should be displayed in

  • icon_name (Union[str, Path, QIcon]) – str/Path: the png file name/path to produce the icon QtGui.QIcon: the instance of a QIcon element ThemeIcon enum: the value of QtGui.QIcon.ThemeIcon (requires Qt>=6.7)

  • tip (str) – a tooltip to be displayed when hovering above the action

  • checkable (bool) – set the checkable state of the action

  • checked (bool) – set the current state of the action

  • toolbar (Union[str, QToolBar, None]) –

    a toolbar where action should be added. Can be: - None: adds to the default menu (self._toolbar) - str: toolbar name as registered via add_toolbar() - QToolbar: direct QToolbar instance

    Actions can also be added later see affect_to

  • menu (Union[str, QMenu, None]) – Where to add the action. Can be: - None: adds to the default menu (self._menu) - str: menu name as registered via add_menu() - QMenu: direct QMenu instance Actions can also be added later see affect_to

  • visible (bool) – display or not the action in the toolbar/menu

  • auto_toolbar (bool) – if True add this action to the defined toolbar

  • auto_menu (bool) – if True add this action to the defined menu

  • enabled (bool) – set the enabled state of this action

See also

affect_to, pymodaq.resources.QtDesigner_Ressources.Icon_Library, pymodaq.utils.managers.action_manager.add_action

add_menu(short_name, title, menu=None, icon_name='', auto_menu=True)[source]

Create and add a menu to a parent menu

Parameters:
  • short_name (str) – the name as referenced in the dict self._menus

  • title (str) – Displayed title of the menu

  • menu (QMenu) – a parent menu where this menu should be added. If None, uses the default menu

  • icon_name (Union[str, Path, QIcon]) – str/Path: the png file name/path to produce the icon QtGui.QIcon: the instance of a QIcon element ThemeIcon enum: the value of QtGui.QIcon.ThemeIcon (requires Qt>=6.7)

  • auto_menu (bool) – if True add this menu to the defined parent menu

Returns:

The created menu

Return type:

QMenu

See also

add_action, get_menu

add_toolbar(short_name, title='', parent=None)[source]

Create and add a toolbar

Parameters:
  • short_name (str) – the name as referenced in the dict self._toolbars

  • title (str) – Displayed title of the toolbar

  • parent (QWidget) – parent widget for the toolbar (typically a QMainWindow)

Returns:

The created toolbar

Return type:

QToolBar

add_widget(short_name, klass, *args, tip='', toolbar=None, visible=True, signal_str=None, slot=None, enabled=True, auto_toolbar=True, **kwargs)[source]

Create and add a widget to a toolbar

Parameters:
  • short_name (str) – the name as referenced in the dict self.actions

  • klass (Union[str, QWidget, object]) – should be a custom widget class or the name of a standard widget of QWidgets

  • args (list) – variable arguments passed as is to the widget constructor

  • tip (str) – a tooltip to be displayed when hovering above the widget

  • toolbar (Union[str, QToolBar]) – a toolbar where the widget should be added.

  • visible (bool) – display or not the action in the toolbar/menu

  • signal_str (str) – an attribute of type Signal of the widget

  • slot (Callable) – a callable connected to the signal

  • enabled (bool) – enable state of the widget

  • auto_toolbar (bool) – if True add this action to the defined toolbar

  • kwargs (dict) – variable named arguments passed as is to the widget constructor

Return type:

QWidget

affect_to(action_name, obj)[source]

Affect action to an object either a toolbar or a menu

Parameters:
  • action_name (str) – The action name as defined in setup_actions

  • obj (Union[QToolBar, QMenu]) – The object where to add the action

connect_action(name, slot=None, connect=True, signal_name='')[source]

Connect (or disconnect) the action referenced by name to the given slot

Parameters:
  • name (str) – key of the action as referenced in the self._actions dict

  • slot (method) – a method/function

  • connect (bool) – if True connect the trigger signal of the action to the defined slot else disconnect it

  • signal_name (str) – try to use it as a signal (for widgets added…) otherwise use the triggered signal

get_action(name)[source]

Getter of a given action

Parameters:

name (str) – The action name as defined in setup_actions

Return type:

Union[QAction, QWidget]

get_menu(name)[source]

Getter of a given menu

Parameters:

name (str) – The menu name as defined when calling add_menu

Return type:

QMenu

get_toolbar(name)[source]

Getter of a given toolbar

Parameters:

name (str) – The toolbar name as defined when calling add_toolbar

Return type:

QToolBar

has_action(action_name)[source]

Check if an action has been defined :type action_name: str :param action_name: The action name as defined in setup_actions :type action_name: str

Returns:

bool

Return type:

bool

has_menu(menu_name)[source]

Check if a menu has been defined

Parameters:

menu_name (str) – The menu name as defined when calling add_menu

Returns:

bool

Return type:

bool

has_toolbar(toolbar_name)[source]

Check if a toolbar has been defined

Parameters:

toolbar_name (str) – The toolbar name as defined when calling add_toolbar

Returns:

bool

Return type:

bool

reference_menu(short_name, menu)[source]

Add an existing toolbar to the list of managed toolbars

reference_toolbar(short_name, toolbar)[source]

Add an existing toolbar to the list of managed toolbars

set_action_text(action_name, text)[source]

Convenience method to set the displayed text on an action

Parameters:
  • action_name (str) – The action name as defined in setup_actions

  • text (str) – The text to display

set_menu(menu)[source]

Set the default menu

Parameters:

menu (QMenu) – The menu to set as default

set_toolbar(toolbar)[source]

Set the default toolbar

Parameters:

toolbar (QToolBar) – The toolbar to set as default

setup_actions()[source]

Method where to create actions to be subclassed. Mandatory

Examples

>>> self.add_action('Quit', 'close2', "Quit program")
>>> self.add_action('Grab', 'camera', "Grab from camera", checkable=True)
>>> self.add_action('Load', 'Open', "Load target file (.h5, .png, .jpg) or data from camera", checkable=False)
>>> self.add_action('Save', 'SaveAs', "Save current data", checkable=False)
property actions: list[QAction]
property actions_names: list[str]
is_action_checked

Dispatch methods based on type signature

See also

Dispatcher

is_action_enabled

Dispatch methods based on type signature

See also

Dispatcher

is_action_visible

Dispatch methods based on type signature

See also

Dispatcher

property menu: qtpy.QtWidgets.QMenu

Get the default menu

property menus: list[qtpy.QtWidgets.QMenu]

Get all menus

property menus_names: list[str]

Get all menu names

set_action_checked

Dispatch methods based on type signature

See also

Dispatcher

set_action_enabled

Dispatch methods based on type signature

See also

Dispatcher

set_action_visible

Dispatch methods based on type signature

See also

Dispatcher

property toolbar: qtpy.QtWidgets.QToolBar

Get the default toolbar

property toolbars: list[qtpy.QtWidgets.QToolBar]

Get all toolbars

property toolbars_names: list[str]

Get all toolbar names

class pymodaq_gui.managers.action_manager.QAction(*args: Any, **kwargs: Any)[source]

Bases: QAction

QAction subclass to mimic signals as pushbuttons. Done to be sure of backcompatibility when I moved from pushbuttons to QAction

Attributes:
clicked

Methods

click

connect_to

set_icon

click()[source]
connect_to(slot)[source]
set_icon(icon_name)[source]
property clicked
pymodaq_gui.managers.action_manager.addaction(name='', icon_name='', tip='', checkable=False, checked=False, slot=None, toolbar=None, menu=None, visible=True, shortcut=None, enabled=True)[source]

Create a new action and add it eventually to a toolbar and a menu

Parameters:
  • name (str) – Displayed name if should be displayed (for instance in menus)

  • icon_name (Union[str, Path, QIcon]) – str/Path: the png file name/path to produce the icon QtGui.QIcon: the instance of a QIcon element ThemeIcon enum: the value of QtGui.QIcon.ThemeIcon (requires Qt>=6.7)

  • tip (str) – a tooltip to be displayed when hovering above the action

  • checkable (bool) – set the checkable state of the action

  • checked (bool) – set the current state of the action

  • slot (Callable) – Method or function that will be called when the action is triggered

  • toolbar (QToolBar) – a toolbar where action should be added.

  • menu (QMenu) – a menu where action should be added.

  • visible (bool) – display or not the action in the toolbar/menu

  • shortcut (Union[str, Key]) – a string defining a shortcut for this action

  • enabled (bool) – set the enabled state

pymodaq_gui.managers.action_manager.addwidget(klass, *args, tip='', toolbar=None, visible=True, signal_str=None, slot=None, setters=None, enabled=True, **kwargs)[source]

Create and eventually add a widget to a toolbar

Parameters:
  • klass (Union[str, QWidget, object]) – should be a custom widget class or the name of a standard widget of QWidgets

  • args (list) – variable arguments passed as is to the widget constructor

  • tip (str) – a tooltip to be displayed when hovering above the widget

  • toolbar (QToolBar) – a toolbar where the widget should be added.

  • visible (bool) – display or not the action in the toolbar/menu

  • signal_str (str) – an attribute of type Signal of the widget

  • slot (Callable) – a callable connected to the signal

  • enabled (bool) – enable state of the widget

  • kwargs (dict) – variable named arguments used as is in the widget constructor

  • setters (dict) – method/value pair of the widget (for instance setMaximumWidth)

Return type:

QWidget

pymodaq_gui.managers.action_manager.create_icon(icon_name)[source]