7.3.3. Managers

API of the various managers, special classes to deals with QAction, Paramaters, ControlModules…

addaction([name, icon_name, tip, checkable, ...])

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

QAction(*args, **kwargs)

QAction subclass to mimic signals as pushbuttons.

ActionManager([toolbar, menu])

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

ParameterManager([settings_name, action_list])

Class dealing with Parameter and ParameterTree

ModulesManager([detectors, actuators, ...])

Class to manage DAQ_Viewers and DAQ_Moves with UI to select some

class pymodaq.utils.managers.action_manager.QAction(*args, **kwargs)[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.utils.managers.action_manager.addaction(name: str = '', icon_name: str = '', tip='', checkable=False, checked=False, slot: Callable | None = None, toolbar: QToolBar | None = None, menu: QMenu | None = 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

class pymodaq.utils.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, 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

is_action_checked

Dispatch methods based on type signature

is_action_enabled

Dispatch methods based on type signature

is_action_visible

Dispatch methods based on type signature

set_action_checked

Dispatch methods based on type signature

set_action_enabled

Dispatch methods based on type signature

set_action_text(action_name, text)

Convenience method to set the displayed text on an action

set_action_visible

Dispatch methods based on type signature

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.

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 = None, visible=True, signal_str=None, slot: Callable | None = 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 menu

Get the default menu

property toolbar

Get the default toolbar

class pymodaq.utils.managers.parameter_manager.ParameterManager(settings_name: str | None = None, action_list: tuple = ('save', 'update', 'load'))[source]

Class dealing with Parameter and ParameterTree

params

Defining the Parameter tree like structure

Type:

list of dicts

settings_name

The particular name to give to the object parent Parameter (self.settings)

Type:

str

settings

The higher level (parent) Parameter

Type:

Parameter

settings_tree

widget Holding a ParameterTree and a toolbar for interacting with the tree

Type:

QWidget

tree

the underlying ParameterTree

Type:

ParameterTree

Attributes:
settings
settings_tree
tree

Methods

child_added(param, data)

Non-mandatory method to be subclassed for actions to perform when a param has been added in self.settings

load_settings_slot([file_path])

Method to load settings into the parameter using a xml file extension.

param_deleted(param)

Non-mandatory method to be subclassed for actions to perform when one of the param in self.settings has been deleted

save_settings_slot([file_path])

Method to save the current settings using a xml file extension.

update_settings_slot([file_path])

Method to update settings using a xml file extension.

value_changed(param)

Non-mandatory method to be subclassed for actions to perform (methods to call) when one of the param's value in self._settings is changed

create_parameter

parameter_tree_changed

child_added(param, data)[source]

Non-mandatory method to be subclassed for actions to perform when a param has been added in self.settings

Parameters:
  • param (Parameter) – the parameter where child will be added

  • data (Parameter) – the child parameter

load_settings_slot(file_path: Path | None = None)[source]

Method to load settings into the parameter using a xml file extension.

The starting directory is the user config folder with a subfolder called settings folder

Parameters:

file_path (Path) – Path like object pointing to a xml file encoding a Parameter object If None, opens a file explorer window to pick manually a file

param_deleted(param)[source]

Non-mandatory method to be subclassed for actions to perform when one of the param in self.settings has been deleted

Parameters:

param (Parameter) – the parameter that has been deleted

save_settings_slot(file_path: Path | None = None)[source]

Method to save the current settings using a xml file extension.

The starting directory is the user config folder with a subfolder called settings folder

Parameters:

file_path (Path) – Path like object pointing to a xml file encoding a Parameter object If None, opens a file explorer window to save manually a file

update_settings_slot(file_path: Path | None = None)[source]

Method to update settings using a xml file extension.

The file should define the same settings structure (names and children)

The starting directory is the user config folder with a subfolder called settings folder

Parameters:

file_path (Path) – Path like object pointing to a xml file encoding a Parameter object If None, opens a file explorer window to pick manually a file

value_changed(param)[source]

Non-mandatory method to be subclassed for actions to perform (methods to call) when one of the param’s value in self._settings is changed

Parameters:

param (Parameter) – the parameter whose value just changed

Examples

>>> if param.name() == 'do_something':
>>>     if param.value():
>>>         print('Do something')
>>>         self.settings.child('main_settings', 'something_done').setValue(False)
class pymodaq.utils.managers.modules_manager.ModulesManager(detectors=[], actuators=[], selected_detectors=[], selected_actuators=[], **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:
Nactuators

Get the number of selected actuators

Ndetectors

Get the number of selected detectors

actuators

Get the list of selected actuators

actuators_all

Get the list of all actuators

actuators_name

Get all the names of the actuators

detectors

Get the list of selected detectors

detectors_all

Get the list of all detectors

detectors_name

Get all the names of the detectors

modules

Get the list of all detectors and actuators

modules_all

Get the list of all detectors and actuators

selected_actuators_name

Get/Set the names of the selected actuators

selected_detectors_name

Get/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

get_det_data_list()

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_datas(**kwargs)

Do a single grab of connected and selected detectors

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

test_move_actuators()

Do a move of selected actuator

value_changed(param)

Non-mandatory method to be subclassed for actions to perform (methods to call) when one of the param's value in self._settings is changed

actuators_changed

det_done

det_done_signal

detectors_changed

move_done

move_done_signal

reset_signals

show_only_control_modules

timeout_signal

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 used

  • signal (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

get_mod_from_name(name, mod='det') DAQ_Move | DAQ_Viewer[source]

Getter of a given module from its name (title)

Parameters:
  • name (str) –

  • mod (str) – either ‘det’ for DAQ_Viewer modules or ‘act’ for DAQ_Move modules

get_mods_from_names(names, mod='det')[source]

Getter of a list of given modules from their name (title)

Parameters:
  • names (list of str) –

  • mod (str) – either ‘det’ for DAQ_Viewer modules or ‘act’ for DAQ_Move modules

classmethod get_names(modules)[source]

Get the titles of a list of Control Modules

Parameters:

modules (list of DAQ_Move and/or DAQ_Viewer) –

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_datas(**kwargs)[source]

Do a single grab of connected and selected detectors

move_actuators(dte_act: DataToExport, mode='abs', polling=True) DataToExport[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 actuators

  • mode (str) – either ‘abs’ for absolute positionning or ‘rel’ for relative

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

DataToExport with the selected actuators’s name as key and current actuators’s value as value

order_positions(positions: DataToExport)[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

test_move_actuators()[source]

Do a move of selected actuator

value_changed(param)[source]

Non-mandatory method to be subclassed for actions to perform (methods to call) when one of the param’s value in self._settings is changed

Parameters:

param (Parameter) – the parameter whose value just changed

Examples

>>> if param.name() == 'do_something':
>>>     if param.value():
>>>         print('Do something')
>>>         self.settings.child('main_settings', 'something_done').setValue(False)
property Nactuators

Get the number of selected actuators

property Ndetectors

Get the number of selected detectors

property actuators: List[DAQ_Move]

Get the list of selected actuators

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

Get the list of all detectors

property detectors_name

Get all the names of the detectors

property modules

Get the list of all detectors and actuators

property modules_all

Get the list of all detectors and actuators

property selected_actuators_name: List[str]

Get/Set the names of the selected actuators

property selected_detectors_name

Get/Set the names of the selected detectors