Action handler#

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

Utility classes#

class datalab.gui.actionhandler.SelectCond[source]#

Signal or image select conditions

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

Always true

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

Exactly one signal or image is selected

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

Exactly one group is selected

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

Exactly one group or one signal or image is selected

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

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[source]#

At least one signal or image is selected

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

At least two signals or images are selected

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

At least one signal or image has a ROI

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

Exactly one signal or image has a ROI

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

Exactly one signal or image has annotations

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

At least one signal or image has annotations

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

At least one signal or image has results

class datalab.gui.actionhandler.ActionCategory(value)[source]#

Action categories

Handler classes#

class datalab.gui.actionhandler.SignalActionHandler(panel: SignalPanel | ImagePanel, panel_toolbar: QW.QToolBar, view_toolbar: QW.QToolBar)[source]#

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

create_first_actions()[source]#

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

create_last_actions()[source]#

Create actions that are added to the menus in the end

action_for(function_or_name: Callable | str, position: int | None = None, separator: bool = False, 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) QW.QAction#

Create action for a feature.

Parameters:
  • function_or_name – function or name of the feature

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

  • separator – add separator before action in menu

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

  • 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

add_action(action: QW.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: QW.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

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

Check if annotations clipboard is not empty

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

Check if metadata clipboard is not empty

new_action(title: str, position: int | None = None, separator: bool = False, triggered: Callable | None = None, toggled: Callable | None = None, shortcut: QW.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) QW.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, store_ref: 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.

  • store_ref – Optional attribute name to store menu reference. Defaults to None.

Yields:

None

property object_suffix: str#

Object suffix (e.g. β€œsig” for signal, β€œima” for image)

populate_results_delete_submenu() None#

Populate the Results Delete submenu dynamically based on current selection

populate_roi_remove_submenu() None#

Populate the ROI Remove submenu dynamically based on current selection

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 datalab.gui.actionhandler.ImageActionHandler(panel: SignalPanel | ImagePanel, panel_toolbar: QW.QToolBar, view_toolbar: QW.QToolBar)[source]#

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

create_first_actions()[source]#

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

create_last_actions()[source]#

Create actions that are added to the menus in the end

action_for(function_or_name: Callable | str, position: int | None = None, separator: bool = False, 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) QW.QAction#

Create action for a feature.

Parameters:
  • function_or_name – function or name of the feature

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

  • separator – add separator before action in menu

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

  • 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

add_action(action: QW.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: QW.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

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

Check if annotations clipboard is not empty

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

Check if metadata clipboard is not empty

new_action(title: str, position: int | None = None, separator: bool = False, triggered: Callable | None = None, toggled: Callable | None = None, shortcut: QW.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) QW.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, store_ref: 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.

  • store_ref – Optional attribute name to store menu reference. Defaults to None.

Yields:

None

property object_suffix: str#

Object suffix (e.g. β€œsig” for signal, β€œima” for image)

populate_results_delete_submenu() None#

Populate the Results Delete submenu dynamically based on current selection

populate_roi_remove_submenu() None#

Populate the ROI Remove submenu dynamically based on current selection

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