From 810801ca6625a4046fd148701723f1e02fe9a961 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 9 Apr 2025 17:36:17 +0200 Subject: [PATCH] feat(main_window): add launcher menu and functionality to show launcher --- .../containers/main_window/main_window.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bec_widgets/widgets/containers/main_window/main_window.py b/bec_widgets/widgets/containers/main_window/main_window.py index 9e1c4852..ec235d6c 100644 --- a/bec_widgets/widgets/containers/main_window/main_window.py +++ b/bec_widgets/widgets/containers/main_window/main_window.py @@ -70,12 +70,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")