From 55baa84eb6723b30b407092bc36f826b826cc934 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Thu, 10 Apr 2025 13:19:41 +0200 Subject: [PATCH] feat(main_window): add launcher menu and functionality to show launcher --- .../containers/main_window/main_window.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bec_widgets/widgets/containers/main_window/main_window.py b/bec_widgets/widgets/containers/main_window/main_window.py index cb76703e..9b3ae946 100644 --- a/bec_widgets/widgets/containers/main_window/main_window.py +++ b/bec_widgets/widgets/containers/main_window/main_window.py @@ -18,6 +18,7 @@ MODULE_PATH = os.path.dirname(bec_widgets.__file__) class BECMainWindow(BECWidget, QMainWindow): RPC = False + PLUGIN = False def __init__( self, @@ -70,12 +71,43 @@ class BECMainWindow(BECWidget, QMainWindow): def _fetch_theme(self) -> str: return self.app.theme.theme + def _get_launcher_from_qapp(self): + """ + Get the launcher from the QApplication instance. + """ + from bec_widgets.applications.launch_window import LaunchWindow + + qapp = QApplication.instance() + widgets = qapp.topLevelWidgets() + widgets = [w for w in widgets if isinstance(w, LaunchWindow)] + if widgets: + return widgets[0] + return None + + def _show_launcher(self): + """ + Show the launcher if it exists. + """ + launcher = self._get_launcher_from_qapp() + if launcher: + launcher.show() + launcher.activateWindow() + launcher.raise_() + def _setup_menu_bar(self): """ Setup the menu bar for the main window. """ menu_bar = self.menuBar() + ########################################## + # Launch menu + launch_menu = menu_bar.addMenu("New") + + open_launcher_action = QAction("Open Launcher", self) + launch_menu.addAction(open_launcher_action) + open_launcher_action.triggered.connect(self._show_launcher) + ######################################## # Theme menu theme_menu = menu_bar.addMenu("Theme")