8.3.3. Managers
API of the various managers, special classes to deals with QAction, Parameters, ControlModules…
|
Create a new action and add it eventually to a toolbar and a menu |
|
QAction subclass to mimic signals as pushbuttons. |
|
MixIn Class to be used by all UserInterface to manage their QActions and the action they are connected to |
|
Class dealing with Parameter and ParameterTree management. |
|
Class to manage DAQ_Viewers and DAQ_Moves with UI to select some |
- class pymodaq_gui.managers.action_manager.QAction(*args: Any, **kwargs: Any)[source]
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
- 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
- class pymodaq_gui.managers.action_manager.ActionManager(toolbar=None, menu=None)[source]
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 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
Get the default menu
Get all menus
Get all menu names
- property toolbar: qtpy.QtWidgets.QToolBar
Get the default toolbar
- class pymodaq_gui.managers.parameter_manager.ParameterManager(settings_name=None, action_list=('search', 'save', 'update', 'load'), tree=None)[source]
Class dealing with Parameter and ParameterTree management.
This class provides a complete parameter management system with support for saving, loading, and updating parameters from XML files. It also includes search functionality and callback methods for responding to parameter changes.
- Parameters:
settings_name (
Optional[str]) – The name to assign to the root Parameter object. If None, uses the class attribute ‘settings_name’. Default is None.action_list (
tuple) – Tuple of action names to include in the toolbar. Valid values are: ‘search’, ‘save’, ‘update’, and ‘load’. Default is (‘search’, ‘save’, ‘update’, ‘load’).tree (
ParameterTree) – Allow the use of modified ParameterTree (allowing drag/drop for instance)
- params
Class attribute defining the Parameter tree structure. Should be overridden in subclasses to define the specific parameter hierarchy.
- Type:
listofdicts
- settings
The root Parameter object containing all parameter definitions
- Type:
Parameter
- settings_tree
Widget holding a ParameterTree and a toolbar for interacting with the tree
- Type:
- tree
The underlying ParameterTree widget for displaying parameters
- Type:
ParameterTree
Examples
>>> class MyManager(ParameterManager): ... settings_name = 'my_settings' ... params = [ ... {'title': 'Main:', 'name': 'main_settings', 'type': 'group', 'children': [ ... {'title': 'Value:', 'name': 'value', 'type': 'int', 'value': 0}, ... ]}, ... ] ... ... def value_changed(self, param): ... if param.name() == 'value': ... print(f'Value changed to: {param.value()}')
- Attributes:
settingsParameter: The root parameter object containing all settings.
settings_treeQWidget: The main widget containing the parameter tree and toolbar.
treeParameterTree: The underlying parameter tree widget.
Methods
child_added(param, data)Non-mandatory method to be subclassed for actions to perform when a child parameter is added.
create_parameter(settings)Create a Parameter object from various input types.
limits_changed(param, data)Non-mandatory method to be subclassed for actions to perform when parameter limits change.
load_settings_slot([file_path])Load settings from an XML file, replacing current settings entirely.
Handle toolbar expand/collapse events and manage search filter state.
options_changed(param, data)Non-mandatory method to be subclassed for actions to perform when parameter options change.
param_deleted(param)Non-mandatory method to be subclassed for actions to perform when a parameter is deleted.
parameter_tree_changed(param, changes)Handle changes in the parameter tree and dispatch to specific handlers.
save_settings_slot([file_path])Save the current settings to an XML file.
search_settings_slot([text])Handle search text changes and filter the parameter tree.
update_settings_slot([file_path])Update settings from an XML file with matching structure validation.
value_changed(param)Non-mandatory method to be subclassed for actions to perform when a parameter value changes.
- static create_parameter(settings)[source]
Create a Parameter object from various input types.
- Parameters:
settings (
Union[Parameter,List[Dict[str,str]],Path]) – The settings to convert. Can be: - A Parameter object (creates a copy) - A list of dictionaries defining parameter structure - A Path or string pointing to an XML file with saved parameters- Returns:
A new Parameter object created from the input settings
- Return type:
Parameter- Raises:
TypeError – If settings is not one of the supported types
Examples
>>> params_list = [{'title': 'Value', 'name': 'val', 'type': 'int', 'value': 5}] >>> param = ParameterManager.create_parameter(params_list) >>> print(param.child('val').value()) 5
- child_added(param, data)[source]
Non-mandatory method to be subclassed for actions to perform when a child parameter is added.
This method is called automatically when a new child parameter is added to the parameter tree. Override this method in subclasses to implement custom behavior in response to parameter additions.
- Parameters:
param (
Parameter) – The parent parameter to which the child is being addeddata (
Parameter) – The child parameter that was added
Examples
>>> def child_added(self, param, data): ... if param.name() == 'dynamic_list': ... print(f'New item added: {data.name()}') ... self.update_item_count()
Notes
For this method to be triggered, one of the following Parameter methods must be used: - addChild() - addChildren() - insertChildren()
- limits_changed(param, data)[source]
Non-mandatory method to be subclassed for actions to perform when parameter limits change.
This method is called automatically when the limits (min/max bounds) of a parameter are changed. Override this method in subclasses to respond to limit changes, such as validating dependent parameters or updating the UI.
- Parameters:
Examples
>>> def limits_changed(self, param, data): ... if param.name() == 'temperature': ... min_temp, max_temp = data ... print(f'Temperature range updated: {min_temp}°C to {max_temp}°C') ... self.validate_current_temperature()
Notes
For this method to be triggered, the Parameter.setLimits() method must be used.
- load_settings_slot(file_path=None)[source]
Load settings from an XML file, replacing current settings entirely.
Opens a file dialog for the user to select a file, or uses the provided file path. The current parameter tree structure is completely replaced with the loaded settings.
- Parameters:
file_path (
Path) – Path to the XML file containing saved settings. If None or False, opens a file dialog for the user to select a file. Default is None.
Notes
The starting directory for the file dialog is the user’s config folder with a ‘settings’ subfolder. This method completely replaces the current settings structure, unlike update_settings_slot() which requires matching structure.
Warning
This operation replaces all current settings. Any unsaved changes will be lost.
Examples
>>> manager = ParameterManager() >>> # Interactive load >>> manager.load_settings_slot() >>> # Programmatic load >>> manager.load_settings_slot(Path('saved_settings.xml'))
See also
update_settings_slotUpdate settings while preserving structure
save_settings_slotSave current settings to file
- on_toolbar_toggled()[source]
Handle toolbar expand/collapse events and manage search filter state.
When the toolbar is expanded, restores the previous search filter. When collapsed, clears the search filter to show all parameters again.
Notes
This ensures that collapsing the toolbar (which hides the search field) also clears any active search filter, providing a consistent user experience.
- options_changed(param, data)[source]
Non-mandatory method to be subclassed for actions to perform when parameter options change.
This method is called automatically when options of a parameter are modified using the setOpts() method. Override this method in subclasses to respond to option changes such as visibility, enabled state, or other properties.
- Parameters:
Examples
>>> def options_changed(self, param, data): ... if param.name() == 'advanced_mode' and 'visible' in data: ... if data['visible']: ... print('Advanced options are now visible') ... else: ... print('Advanced options are now hidden')
Notes
For this method to be triggered, the Parameter.setOpts() method must be used.
- param_deleted(param)[source]
Non-mandatory method to be subclassed for actions to perform when a parameter is deleted.
This method is called automatically when a parameter is removed from the parameter tree. Override this method in subclasses to implement custom cleanup or notification behavior.
- Parameters:
param (
Parameter) – The parameter that has been deleted from the tree
Examples
>>> def param_deleted(self, param): ... if param.name() == 'temporary_setting': ... print(f'Temporary setting {param.name()} was removed') ... self.cleanup_related_resources(param)
Notes
For this method to be triggered, the Parameter.removeChild() method must be used.
- parameter_tree_changed(param, changes)[source]
Handle changes in the parameter tree and dispatch to specific handlers.
This method is called whenever any change occurs in the parameter tree. It processes the changes and calls the appropriate handler method based on the type of change.
- Parameters:
Notes
The following change types are handled: - ‘childAdded’: A new child parameter was added - ‘value’: A parameter value was changed - ‘parent’: A parameter was removed (parent changed to None) - ‘options’: Parameter options were modified - ‘limits’: Parameter limits were changed
- save_settings_slot(file_path=None)[source]
Save the current settings to an XML file.
Opens a file dialog for the user to select a save location, or uses the provided file path. The settings are serialized to XML format and saved to disk.
- Parameters:
file_path (
Path) – Path where the settings should be saved. If None or False, opens a file dialog for the user to select a location. The file extension must be ‘.xml’. Default is None.
Notes
The starting directory for the file dialog is the user’s config folder with a ‘settings’ subfolder. The file is automatically given a .xml extension if not already present.
Examples
>>> manager = ParameterManager() >>> # Interactive save >>> manager.save_settings_slot() >>> # Programmatic save >>> manager.save_settings_slot(Path('my_settings.xml'))
- search_settings_slot(text='')[source]
Handle search text changes and filter the parameter tree.
This slot is connected to the search widget’s text changed signal. It stores the current search text and applies the filter to show only matching parameters.
- Parameters:
text (
str) – The search text to filter parameters by. Empty string shows all parameters. Default is “”.
Notes
The search is typically case-insensitive and matches against parameter names and titles.
- update_settings_slot(file_path=None)[source]
Update settings from an XML file with matching structure validation.
Opens a file dialog for the user to select a file, or uses the provided file path. The loaded settings must have the same structure (parameter names and hierarchy) as the current settings. Only the values are updated, not the structure.
- Parameters:
file_path (
Path) – Path to the XML file containing settings to apply. If None or False, opens a file dialog for the user to select a file. Default is None.
Notes
The starting directory for the file dialog is the user’s config folder with a ‘settings’ subfolder. The loaded settings must have identical structure (same parameter names and children) as the current settings, otherwise the update is rejected with a warning message.
Examples
>>> manager = ParameterManager() >>> # Interactive update >>> manager.update_settings_slot() >>> # Programmatic update >>> manager.update_settings_slot(Path('compatible_settings.xml'))
See also
load_settings_slotLoad settings without structure validation
save_settings_slotSave current settings to file
- value_changed(param)[source]
Non-mandatory method to be subclassed for actions to perform when a parameter value changes.
This method is called automatically when a parameter’s value is changed using the setValue() method. Override this method in subclasses to implement custom behavior in response to value changes.
- Parameters:
param (
Parameter) – The parameter whose value has just changed
Examples
>>> def value_changed(self, param): ... if param.name() == 'enable_feature': ... if param.value(): ... print('Feature enabled') ... self.settings.child('status', 'ready').setValue(True) ... else: ... print('Feature disabled')
Notes
For this method to be triggered, changes must be made using the Parameter.setValue() method, not by direct attribute assignment.
- property settings: Parameter
The root parameter object containing all settings.
- Type:
Parameter
- property settings_tree: qtpy.QtWidgets.QWidget
The main widget containing the parameter tree and toolbar.
- Type:
- property tree: ParameterTree
The underlying parameter tree widget.
- Type:
- class pymodaq.utils.managers.modules_manager.ModulesManager(detectors=None, actuators=None, selected_detectors=None, selected_actuators=None, parent_name='', **kwargs)[source]
Class to manage DAQ_Viewers and DAQ_Moves with UI to select some
Easier to connect control modules signals to slots, test, …
- Parameters:
- Attributes:
NactuatorsGet the number of selected actuators
NdetectorsGet the number of selected detectors
actuatorsGet the list of selected actuators
actuators_allGet the list of all actuators
actuators_nameGet all the names of the actuators
detectorsGet the list of selected detectors
detectors_allGet/Set the list of all detectors
detectors_nameGet all the names of the detectors
modulesGet the list of detectors and actuators
modules_allGet the list of all detectors and actuators
selected_actuators_nameGet/Set the names of the selected actuators
selected_detectors_nameGet/Set the names of the selected detectors
Methods
connect_actuators([connect, slot, signal])Connect the selected actuators signal to a given or default slot
connect_detectors([connect, slot])Connect selected DAQ_Viewers's grab_done_signal to the given slot
Do a snap of selected detectors, to get the list of all the data and processed data
get_mod_from_name(name[, mod])Getter of a given module from its name (title)
get_mods_from_names(names[, mod])Getter of a list of given modules from their name (title)
get_names(modules)Get the titles of a list of Control Modules
get_selected_probed_data([dim])Get the name of selected data names of a given dimensionality
grab_data([check_do_override])Do a single grab of connected and selected detectors
grab_datas(**kwargs)For back compatibility but use self.grab_data
move_actuators(dte_act[, mode, polling])will apply positions to each currently selected actuators.
order_positions(positions)Reorder the content of the DataToExport given the order of the selected actuators
set_actuators(actuators, selected_actuators)Populates actuators and the subset to be selected in the UI
set_detectors(detectors, selected_detectors)Populates detectors and the subset to be selected in the UI
Do a move of selected actuator
value_changed(param)actuators_changed
det_done
det_done_signal
detectors_changed
move_done
move_done_signal
reset_signals
show_only_control_modules
timeout_signal
- classmethod get_names(modules)[source]
Get the titles of a list of Control Modules
- Parameters:
modules (
listofDAQ_Move and/or DAQ_Viewer)
- connect_actuators(connect=True, slot=None, signal='move_done')[source]
Connect the selected actuators signal to a given or default slot
- Parameters:
connect (
bool)slot (
builtin_function_or_method) – method or function the chosen signal will be connected to if None, then the default move_done slot is usedsignal (
str) –What kind of signal is to be used:
’move_done’ will connect the move_done_signal to the slot
’current_value’ will connect the ‘current_value_signal’ to the slot
See also
move_done()
- connect_detectors(connect=True, slot=None)[source]
Connect selected DAQ_Viewers’s grab_done_signal to the given slot
- Parameters:
connect (
bool) – if True, connect to the given slot (or default slot) if False, disconnect all detectors (not only the currently selected ones. This is made because when selected detectors changed if you only disconnect those one, the previously connected ones will stay connected)slot (
method) – A method that should be connected, if None self.det_done is connected by default
- get_det_data_list()[source]
Do a snap of selected detectors, to get the list of all the data and processed data
- Return type:
- get_mod_from_name(name, mod='det')[source]
Getter of a given module from its name (title)
- Parameters:
- Return type:
Union[DAQ_Move,DAQ_Viewer]
- get_mods_from_names(names, mod='det')[source]
Getter of a list of given modules from their name (title)
- get_selected_probed_data(dim='0D')[source]
Get the name of selected data names of a given dimensionality
- Parameters:
dim (
str) – either ‘0D’, ‘1D’, ‘2D’ or ‘ND’
- grab_data(check_do_override=True, **kwargs)[source]
Do a single grab of connected and selected detectors
- move_actuators(dte_act, mode='abs', polling=True)[source]
will apply positions to each currently selected actuators. By Default the mode is absolute but can be
- Parameters:
dte_act (
DataToExport) – the DataToExport of position to apply. Its length must be equal to the number of selected actuatorsmode (
str) – either ‘abs’ for absolute positionning or ‘rel’ for relativepolling (
bool) – if True will wait for the selected actuators to reach their target positions (they have to be connected to a method checking for the position and letting the programm know the move is done (default connection is this object move_done method)
- Return type:
- order_positions(positions)[source]
Reorder the content of the DataToExport given the order of the selected actuators
- set_actuators(actuators, selected_actuators)[source]
Populates actuators and the subset to be selected in the UI
- set_detectors(detectors, selected_detectors)[source]
Populates detectors and the subset to be selected in the UI
- property Nactuators
Get the number of selected actuators
- property Ndetectors
Get the number of selected detectors
- property actuators_all
Get the list of all actuators
- property actuators_name
Get all the names of the actuators
- property detectors: List[DAQ_Viewer]
Get the list of selected detectors
- property detectors_all: List[DAQ_Viewer]
Get/Set the list of all detectors
- property detectors_name
Get all the names of the detectors
- property modules
Get the list of detectors and actuators
- property modules_all
Get the list of all detectors and actuators
- property selected_detectors_name
Get/Set the names of the selected detectors