8.5.4.1. pymodaq_gui.managers.action_manager module
- class pymodaq_gui.managers.action_manager.ActionManager(toolbar=None, menu=None)[source]
Bases:
objectMixIn Class to be used by all UserInterface to manage their QActions and the action they are connected to
- Parameters:
- Attributes:
- actions
- actions_names
menuGet the default menu
menusGet all menus
menus_namesGet all menu names
toolbarGet the default toolbar
toolbarsGet all toolbars
toolbars_namesGet 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, parent_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:strhas_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
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=False, enabled=True, icon_checked=None, icon_color=None, icon_checked_color=None, flip_h=False, flip_v=False, before=None, action=None)[source]
Create a new action and add it to toolbar and menu
- Parameters:
short_name (
str) – the name as referenced in the dict self.actionsname (
str) – Displayed name if should be displayed inicon_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 actioncheckable (
bool) – set the checkable state of the actionchecked (
bool) – set the current state of the actiontoolbar (
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_tovisible (
bool) – display or not the action in the toolbar/menushortcut (
Union[str,Key,QKeySequence]) – Using this shortcut will trigger the actionauto_toolbar (
bool) – if True add this action to the defined toolbarauto_menu (
bool) – if True add this action to the defined menuenabled (
bool) – set the enabled state of this actionicon_checked (
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) Optional, if set, will be the icon when the action is checkedicon_color (
Union[QColor,bytes,str]) – color to be applied (if possible) to the unchecked iconicon_checked_color (
Union[QColor,bytes,str]) – color to be applied to the checked icon (if any)flip_h (
bool) – mirror the icon horizontally (left ↔ right)flip_v (
bool) – mirror the icon vertically (top ↔ bottom)before (
Union[str,QAction,WidgetActionProxy,None]) – if set, the action is inserted before this action in the toolbar/menu; accepts a short_name str, a QAction instance, or a WidgetActionProxyaction (
QAction|QWidgetAction)
See also
affect_to,pymodaq.resources.QtDesigner_Ressources.icon_library,pymodaq.utils.managers.action_manager.add_action
Create and add a menu to a parent menu
- Parameters:
short_name (
str) – the name as referenced in the dict self._menustitle (
str) – Displayed title of the menu. When menu is also provided and title is non-empty, the title overrides the instance’s own title.parent_menu (
QMenuBar|QMenu|str) – the parent menu or menubar where this menu should be added. If None, uses the default menuicon_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 menumenu (
QMenu) – an existing QMenu instance to register instead of creating a new one.before (
Union[QMenu,str,None]) – if specified, the new menu will be inserted before this menu (by instance or short_name); if None the menu is appended at the end
- Returns:
The created (or provided) menu
- Return type:
See also
- add_toolbar(short_name, title='', parent=None, toolbar=None, area=<ToolBarArea.TopToolBarArea: 4>, add_break=True, before=None)[source]
Create and add a toolbar
- Parameters:
short_name (
str) – the name as referenced in the dict self._toolbarstitle (
str) – Displayed title of the toolbarparent (
QWidget) – parent widget for the toolbar (typically a QMainWindow)toolbar (
QToolBar) – A given toolbar, if None, it is createdarea (
ToolBarArea, optional) – the area where this toolbar should be added, valid only for a QMainWindow parentadd_break (
bool, optional) – If True, a toolbar break is added in the given area before adding the toolbar, valid only for a QMainWindow parentbefore (
Union[str,QToolBar,None]) – if specified, the new toolbar will be inserted before this toolbar (by instance or short_name)
- Returns:
The created toolbar
- Return type:
See also
- 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.actionsklass (
Union[str,QWidget,object]) – should be a custom widget class or the name of a standard widget of QWidgetsargs (
list) – variable arguments passed as is to the widget constructortip (
str) – a tooltip to be displayed when hovering above the widgettoolbar (
Union[str,QToolBar]) – a toolbar where the widget should be added.visible (
bool) – display or not the action in the toolbar/menusignal_str (
str) – an attribute of type Signal of the widgetslot (
Callable) – a callable connected to the signalenabled (
bool) – enable state of the widgetauto_toolbar (
bool) – if True add this action to the defined toolbarkwargs (
dict) – variable named arguments passed as is to the widget constructor
- Return type:
Union[WidgetActionProxy,QWidget]
- affect_to(action_name, obj)[source]
Affect action to an object either a toolbar or a menu
- Parameters:
action_name (
Union[str,QAction,WidgetActionProxy]) – The action name as defined in setup_actionsobj (
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 dictslot (
method) – a method/functionconnect (
bool) – if True connect the trigger signal of the action to the defined slot else disconnect itsignal_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,WidgetActionProxy]
Getter of a given menu
- 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:
Check if a menu has been defined
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
Set the default menu
- Parameters:
menu (
QMenu) – The menu 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)
See also
- 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
Get the default menu
Get all menus
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
- class pymodaq_gui.managers.action_manager.QAction(icon_unchecked, name='', icon_checked=None, icon_color=None, icon_checked_color=None, flip_h=False, flip_v=False)[source]
Bases:
QActionQAction 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
- property clicked
- class pymodaq_gui.managers.action_manager.WidgetActionProxy(widget, action)[source]
Bases:
QWidgetWrapper class of a Widget and its associated toolbar Action. All methods call are forwarded to the wrapped Widget. Even its class name is copied.
Only the setVisible method is different, as the Action need to be hidden. (monkey-patching setVisible on the widget wasn’t compatible with PySide6)
- Attributes:
- action
- widget
Methods
setVisible(visible)
- 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, icon_checked=None, icon_color=None, icon_checked_color=None, flip_h=False, flip_v=False, before=None, action=None)[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 actioncheckable (
bool) – set the checkable state of the actionchecked (
bool) – set the current state of the actionslot (
Callable) – Method or function that will be called when the action is triggeredtoolbar (
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/menushortcut (
Union[str,Key,QKeySequence]) – Using this shortcut will trigger the actionenabled (
bool) – set the enabled stateicon_checked (
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) Optional, if set, will be the icon when the action is checked (checkable will be set to True)icon_color (
Union[QColor,str]) – color to be applied (if possible) to the unchecked iconicon_checked_color (
Union[QColor,str]) – color to be applied to the checked icon (if any)flip_h (
bool) – mirror the icon horizontally (left ↔ right)flip_v (
bool) – mirror the icon vertically (top ↔ bottom)before (
QAction) – if set, the action is inserted before this action in the toolbar/menu; if None the action is appended at the endaction (
QAction|QWidgetAction)
- 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 QWidgetsargs (
list) – variable arguments passed as is to the widget constructortip (
str) – a tooltip to be displayed when hovering above the widgettoolbar (
QToolBar) – a toolbar where the widget should be added.visible (
bool) – display or not the action in the toolbar/menusignal_str (
str) – an attribute of type Signal of the widgetslot (
Callable) – a callable connected to the signalenabled (
bool) – enable state of the widgetkwargs (
dict) – variable named arguments used as is in the widget constructorsetters (
dict) – method/value pair of the widget (for instance setMaximumWidth)
- Return type:
Union[WidgetActionProxy,QWidget]