Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/pymodaq_gui/managers/action_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def add_action(self, short_name: str = '', name: str = '', icon_name: Union[str,
elif isinstance(toolbar, str):
toolbar = self.get_toolbar(toolbar)
elif not isinstance(toolbar, QtWidgets.QToolBar):
raise TypeError(f'toolbar must be either None, a string, or QToolBar, got {type(menu)}')
raise TypeError(f'toolbar must be either None, a string, or QToolBar, got {type(toolbar)}')

if auto_menu:
if menu is None:
menu = self._menu
Expand All @@ -301,8 +302,8 @@ def add_action(self, short_name: str = '', name: str = '', icon_name: Union[str,
return self._actions[short_name]

def add_widget(self, short_name, klass: Union[str, QtWidgets.QWidget, object], *args, tip='',
toolbar: QtWidgets.QToolBar = None, visible=True, signal_str=None,
slot: Callable=None, enabled=True, **kwargs):
toolbar: Union[str, QtWidgets.QToolBar] = None, visible=True, signal_str=None,
slot: Callable=None, enabled=True, auto_toolbar=True, **kwargs):
"""Create and add a widget to a toolbar

Parameters
Expand All @@ -325,16 +326,25 @@ def add_widget(self, short_name, klass: Union[str, QtWidgets.QWidget, object], *
a callable connected to the signal
enabled: bool
enable state of the widget
auto_toolbar: bool
if True add this action to the defined toolbar
kwargs: dict
variable named arguments passed as is to the widget constructor
Returns
-------
QtWidgets.QWidget
"""
if toolbar is None:
toolbar = self._toolbar
if auto_toolbar:
if toolbar is None:
toolbar = self._toolbar
elif isinstance(toolbar, str):
toolbar = self.get_toolbar(toolbar)
elif not isinstance(toolbar, QtWidgets.QToolBar):
raise TypeError(f'toolbar must be either None, a string, or QToolBar, got {type(toolbar)}')

widget = addwidget(klass, *args, tip=tip, toolbar=toolbar, visible=visible, signal_str=signal_str,
slot=slot, enabled=enabled, **kwargs)

if widget is not None:
self._actions[short_name] = widget
else:
Expand Down Expand Up @@ -456,7 +466,7 @@ def actions(self) -> list[QAction]:
def actions_names(self) -> list[str]:
return list(self._actions.keys())

def get_action(self, name) -> QAction:
def get_action(self, name) -> Union[QAction, QtWidgets.QWidget]:
"""Getter of a given action

Parameters
Expand Down
Loading