8.5.3.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:
toolbar (
QToolBar) – The toolbar to use as defaultmenu (
QMenu) – The menu to use as default
- 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[, 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=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.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/menuauto_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 action
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 menumenu (
QMenu) – a parent menu 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 menu
- Returns:
The created menu
- Return type:
QMenu
See also
- add_toolbar(short_name, title='', parent=None)[source]
Create and add a toolbar
- Parameters:
- Returns:
The created toolbar
- Return type:
QToolBar
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:
- 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_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
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:
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
- 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)
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
- property toolbar: qtpy.QtWidgets.QToolBar
Get the default toolbar
- class pymodaq_gui.managers.action_manager.QAction(*args: Any, **kwargs: Any)[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
- 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 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]) – a string defining a shortcut for this actionenabled (
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 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: