Action handler#

The cdl.core.gui.actionhandler module handles all application actions (menus, toolbars, context menu). These actions point to DataLab panels, processors, objecthandler, …

Utility classes#

class cdl.core.gui.actionhandler.SelectCond#

Signal or image select conditions

static always(selected_groups: list[ObjectGroup], selected_objects: list[SignalObj | ImageObj]) bool#

Always true

static exactly_one(selected_groups: list[ObjectGroup], selected_objects: list[SignalObj | ImageObj]) bool#

Exactly one signal or image is selected

static exactly_one_group(selected_groups: list[ObjectGroup], selected_objects: list[SignalObj | ImageObj]) bool#

Exactly one group is selected

static at_least_one_group_or_one_object(sel_groups: list[ObjectGroup], sel_objects: list[SignalObj | ImageObj]) bool#

At least one group or one signal or image is selected

static at_least_one(sel_groups: list[ObjectGroup], sel_objects: list[SignalObj | ImageObj]) bool#

At least one signal or image is selected

static at_least_two(sel_groups: list[ObjectGroup], sel_objects: list[SignalObj | ImageObj]) bool#

At least two signals or images are selected

static with_roi(selected_groups: list[ObjectGroup], selected_objects: list[SignalObj | ImageObj]) bool#

At least one signal or image has a ROI

class cdl.core.gui.actionhandler.ActionCategory(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Action categories

Handler classes#

class cdl.core.gui.actionhandler.SignalActionHandler(panel: SignalPanel | ImagePanel, panel_toolbar: QW.QToolBar, view_toolbar: QW.QToolBar)#

Object handling signal panel GUI interactions: actions, menus, …

create_first_actions()#

Create actions that are added to the menus in the first place

create_last_actions()#

Create actions that are added to the menus in the end

add_action(action: QAction, select_condition: Callable | None = None) None#

Add action to list of actions.

Parameters:
  • action – action to add

  • select_condition – condition to enable action. Defaults to None. If None, action is enabled if at least one object is selected.

add_to_action_list(action: QAction, category: ActionCategory | None = None, pos: int | None = None, sep: bool = False) None#

Add action to list of actions.

Parameters:
  • action – action to add

  • category – action category. Defaults to None. If None, action is added to the current category.

  • pos – add action to menu at this position. Defaults to None. If None, action is added at the end of the list.

  • sep – add separator before action in menu (or after if pos is positive). Defaults to False.

create_all_actions()#

Create all actions

new_action(title: str, position: int | None = None, separator: bool = False, triggered: Callable | None = None, toggled: Callable | None = None, shortcut: QShortcut | None = None, icon_name: str | None = None, tip: str | None = None, select_condition: Callable | str | None = None, context_menu_pos: int | None = None, context_menu_sep: bool = False, toolbar_pos: int | None = None, toolbar_sep: bool = False, toolbar_category: ActionCategory | None = None) QAction#

Create new action and add it to list of actions.

Parameters:
  • title – action title

  • position – add action to menu at this position. Defaults to None.

  • separator – add separator before action in menu (or after if pos is positive). Defaults to False.

  • triggered – triggered callback. Defaults to None.

  • toggled – toggled callback. Defaults to None.

  • shortcut – shortcut. Defaults to None.

  • icon_name – icon name. Defaults to None.

  • tip – tooltip. Defaults to None.

  • select_condition – selection condition. Defaults to None. If str, must be the name of a method of SelectCond, i.e. one of “always”, “exactly_one”, “exactly_one_group”, “at_least_one_group_or_one_object”, “at_least_one”, “at_least_two”, “with_roi”.

  • context_menu_pos – add action to context menu at this position. Defaults to None.

  • context_menu_sep – add separator before action in context menu (or after if context_menu_pos is positive). Defaults to False.

  • toolbar_pos – add action to toolbar at this position. Defaults to None.

  • toolbar_sep – add separator before action in toolbar (or after if toolbar_pos is positive). Defaults to False.

  • toolbar_category – toolbar category. Defaults to None. If toolbar_pos is not None, this specifies the category of the toolbar. If None, defaults to ActionCategory.VIEW_TOOLBAR if the current category is ActionCategory.VIEW, else to ActionCategory.PANEL_TOOLBAR.

Returns:

New action

new_category(category: ActionCategory) Generator[None, None, None]#

Context manager for creating a new menu.

Parameters:

category – Action category

Yields:

None

new_menu(title: str, icon_name: str | None = None) Generator[None, None, None]#

Context manager for creating a new menu.

Parameters:
  • title – Menu title

  • icon_name – Menu icon name. Defaults to None.

Yields:

None

selected_objects_changed(selected_groups: list[ObjectGroup], selected_objects: list[SignalObj | ImageObj]) None#

Update actions based on selected objects.

Parameters:
  • selected_groups – selected groups

  • selected_objects – selected objects

class cdl.core.gui.actionhandler.ImageActionHandler(panel: SignalPanel | ImagePanel, panel_toolbar: QW.QToolBar, view_toolbar: QW.QToolBar)#

Object handling image panel GUI interactions: actions, menus, …

create_first_actions()#

Create actions that are added to the menus in the first place

create_last_actions()#

Create actions that are added to the menus in the end

add_action(action: QAction, select_condition: Callable | None = None) None#

Add action to list of actions.

Parameters:
  • action – action to add

  • select_condition – condition to enable action. Defaults to None. If None, action is enabled if at least one object is selected.

add_to_action_list(action: QAction, category: ActionCategory | None = None, pos: int | None = None, sep: bool = False) None#

Add action to list of actions.

Parameters:
  • action – action to add

  • category – action category. Defaults to None. If None, action is added to the current category.

  • pos – add action to menu at this position. Defaults to None. If None, action is added at the end of the list.

  • sep – add separator before action in menu (or after if pos is positive). Defaults to False.

create_all_actions()#

Create all actions

new_action(title: str, position: int | None = None, separator: bool = False, triggered: Callable | None = None, toggled: Callable | None = None, shortcut: QShortcut | None = None, icon_name: str | None = None, tip: str | None = None, select_condition: Callable | str | None = None, context_menu_pos: int | None = None, context_menu_sep: bool = False, toolbar_pos: int | None = None, toolbar_sep: bool = False, toolbar_category: ActionCategory | None = None) QAction#

Create new action and add it to list of actions.

Parameters:
  • title – action title

  • position – add action to menu at this position. Defaults to None.

  • separator – add separator before action in menu (or after if pos is positive). Defaults to False.

  • triggered – triggered callback. Defaults to None.

  • toggled – toggled callback. Defaults to None.

  • shortcut – shortcut. Defaults to None.

  • icon_name – icon name. Defaults to None.

  • tip – tooltip. Defaults to None.

  • select_condition – selection condition. Defaults to None. If str, must be the name of a method of SelectCond, i.e. one of “always”, “exactly_one”, “exactly_one_group”, “at_least_one_group_or_one_object”, “at_least_one”, “at_least_two”, “with_roi”.

  • context_menu_pos – add action to context menu at this position. Defaults to None.

  • context_menu_sep – add separator before action in context menu (or after if context_menu_pos is positive). Defaults to False.

  • toolbar_pos – add action to toolbar at this position. Defaults to None.

  • toolbar_sep – add separator before action in toolbar (or after if toolbar_pos is positive). Defaults to False.

  • toolbar_category – toolbar category. Defaults to None. If toolbar_pos is not None, this specifies the category of the toolbar. If None, defaults to ActionCategory.VIEW_TOOLBAR if the current category is ActionCategory.VIEW, else to ActionCategory.PANEL_TOOLBAR.

Returns:

New action

new_category(category: ActionCategory) Generator[None, None, None]#

Context manager for creating a new menu.

Parameters:

category – Action category

Yields:

None

new_menu(title: str, icon_name: str | None = None) Generator[None, None, None]#

Context manager for creating a new menu.

Parameters:
  • title – Menu title

  • icon_name – Menu icon name. Defaults to None.

Yields:

None

selected_objects_changed(selected_groups: list[ObjectGroup], selected_objects: list[SignalObj | ImageObj]) None#

Update actions based on selected objects.

Parameters:
  • selected_groups – selected groups

  • selected_objects – selected objects