8.5.8.8. pymodaq_gui.utils.menu_utils module
Shared utility for building nested QMenu structures.
Uses QMenu(title, parent) to create submenus so that Qt takes C++
ownership and PySide6 does not garbage-collect them prematurely.
- class pymodaq_gui.utils.menu_utils.StickyMenu(*args, sticky_all=False, sticky_predicate=None, **kwargs)[source]
Bases:
QMenuA
QMenuthat stays open after an action is triggered.By default the menu remains open only when a checkable action is clicked (the typical use-case for toolbar-visibility toggles). Pass
sticky_all=Trueto keep the menu open after any action click, which is useful for multi-selection menus. For fine-grained control supply a sticky_predicate: a callable that receives the triggeredQActionand returnsTruewhen the menu should stay open.- Parameters:
*args – Forwarded to
QMenu(title, parent, …).sticky_all (
bool) – WhenTruethe menu never closes on a click regardless of whether the action is checkable. Ignored if sticky_predicate is given.sticky_predicate (
Optional[Callable[[QAction],bool]]) – Custom predicate that decides per-action whether the menu stays open. When provided, sticky_all is ignored.**kwargs – Forwarded to
QMenu.
Methods
mouseReleaseEvent(event)
- pymodaq_gui.utils.menu_utils.build_menu_from_iterable(menu, items, leaf_callback, path=())[source]
Populate menu recursively from a nested dict / list / tuple.
- Parameters:
menu (
QMenu) – The menu to populate.items (
dict | list | tuple | str) –The menu content:
dict— keys become submenu titles (when the corresponding value is a non-empty container) or leaf action labels (otherwise).list/tuple— each element is either astr(leaf action) or a single-keydict(submenu or leaf).str— shorthand for[str].
leaf_callback (
Callable) – Invoked when a leaf action is triggered. name is the action label; path is the full tuple of labels from the root to that action.path (
tuple) – Accumulated prefix — callers should leave this at its default.
- Return type: