7.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, optional) – The toolbar to use as default

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

Attributes:
actions
menu

Get the default menu

toolbar

Get the default toolbar

Methods

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

Create a new action and add it to toolbar and menu

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

has_action(action_name)

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

set_action_text(action_name, text)

Convenience method to set the displayed text on an action

set_menu(menu)

affect a menu to self

set_toolbar(toolbar)

affect a toolbar to self

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: str = '', name: str = '', icon_name: str = '', 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 (str) – png file name to produce the icon

  • 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 (QToolBar) – a toolbar where action should be added. Actions can also be added later see affect_to

  • menu (QMenu) – a menu where action should be added. 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_widget(short_name, klass: str | QWidget, *args, tip='', toolbar: _QToolBar = None, visible=True, signal_str=None, slot: Callable = None, **kwargs)[source]

Create and add a widget to a toolbar

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

  • klass (str or QWidget) – 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

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

Return type:

QtWidgets.QWidget

affect_to(action_name, obj: _QToolBar | _QMenu)[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 (QToolbar or QMenu) – The object where to add the action

connect_action(name, slot, 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) QAction[source]

Getter of a given action

Parameters:

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

Return type:

QAction

has_action(action_name) bool[source]

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

Returns:

bool

Return type:

True if the action exists, False otherwise

set_action_text(action_name: str, text: str)[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]

affect a menu to self

Parameters:

menu – QtWidgets.QMenu

set_toolbar(toolbar)[source]

affect a toolbar to self

Parameters:

toolbar – QtWidgets.QToolBar

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]
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: QMenuBar

Get the default menu

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: _QToolBar

Get the default toolbar

class pymodaq_gui.managers.action_manager.QAction(*args, **kwargs)[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: str)[source]
property clicked
pymodaq_gui.managers.action_manager.addaction(name: str = '', icon_name: str = '', tip='', checkable=False, checked=False, slot: Callable = None, toolbar: _QToolBar = None, menu: _QMenu = 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 (str) – png file name to produce the icon

  • 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 (str) – a string defining a shortcut for this action

  • enabled (bool) – set the enabled state

pymodaq_gui.managers.action_manager.addwidget(klass: str | QWidget, *args, tip='', toolbar: _QToolBar = None, visible=True, signal_str=None, slot: Callable = None, setters={}, **kwargs)[source]

Create and eventually add a widget to a toolbar

Parameters:
  • klass (str or QWidget) – 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

  • 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:

QtWidgets.QWidget

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