From 20a1c5ddb3cd0763ce69bba5a893f54c56678706 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Wed, 9 Apr 2025 12:35:25 +0200 Subject: [PATCH] feat(launcher): add option for launching with auto updates --- bec_widgets/applications/bw_launch.py | 17 ++++++++++++++ bec_widgets/applications/launch_dialog.ui | 2 +- bec_widgets/applications/launch_window.py | 27 ++++++++++++++--------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/bec_widgets/applications/bw_launch.py b/bec_widgets/applications/bw_launch.py index d6e62506..3805e69e 100644 --- a/bec_widgets/applications/bw_launch.py +++ b/bec_widgets/applications/bw_launch.py @@ -1,6 +1,23 @@ +from bec_widgets.cli.auto_updates import AutoUpdates from bec_widgets.widgets.containers.dock.dock_area import BECDockArea def dock_area(object_name: str | None = None): _dock_area = BECDockArea(object_name=object_name) return _dock_area + + +def auto_update_dock_area(object_name: str | None = None) -> BECDockArea: + """ + Create a dock area with auto update enabled. + + Args: + object_name(str): The name of the dock area. + + Returns: + BECDockArea: The created dock area. + """ + _dock_area = BECDockArea(object_name=object_name) + _dock_area.set_auto_update(AutoUpdates) + _dock_area.auto_update.enabled = True # type:ignore + return _dock_area diff --git a/bec_widgets/applications/launch_dialog.ui b/bec_widgets/applications/launch_dialog.ui index 586cb400..103a8ee0 100644 --- a/bec_widgets/applications/launch_dialog.ui +++ b/bec_widgets/applications/launch_dialog.ui @@ -22,7 +22,7 @@ - + PushButton diff --git a/bec_widgets/applications/launch_window.py b/bec_widgets/applications/launch_window.py index 6fcdc7c1..3f3efc7c 100644 --- a/bec_widgets/applications/launch_window.py +++ b/bec_widgets/applications/launch_window.py @@ -1,23 +1,23 @@ +from __future__ import annotations + import os +from typing import TYPE_CHECKING from bec_lib.logger import bec_logger -from qtpy.QtCore import QSize -from qtpy.QtGui import QAction, QActionGroup -from qtpy.QtWidgets import QApplication, QMainWindow, QSizePolicy, QStyle +from qtpy.QtWidgets import QApplication, QSizePolicy import bec_widgets from bec_widgets.cli.rpc.rpc_register import RPCRegister -from bec_widgets.utils import UILoader -from bec_widgets.utils.bec_widget import BECWidget -from bec_widgets.utils.colors import apply_theme from bec_widgets.utils.container_utils import WidgetContainerUtils from bec_widgets.widgets.containers.dock.dock_area import BECDockArea -from bec_widgets.widgets.containers.main_window.addons.web_links import BECWebLinksMixin from bec_widgets.widgets.containers.main_window.main_window import BECMainWindow logger = bec_logger.logger MODULE_PATH = os.path.dirname(bec_widgets.__file__) +if TYPE_CHECKING: # pragma: no cover + from qtpy.QtWidgets import QWidget + class LaunchWindow(BECMainWindow): RPC = True @@ -36,20 +36,27 @@ class LaunchWindow(BECMainWindow): self.load_ui(ui_file_path) self.ui.open_dock_area.setText("Open Dock Area") self.ui.open_dock_area.clicked.connect(lambda: self.launch("dock_area")) + self.ui.open_auto_update_dock_area.setText("Open Dock Area with Auto Update") + self.ui.open_auto_update_dock_area.clicked.connect( + lambda: self.launch("auto_update_dock_area", "auto_updates") + ) def launch( self, launch_script: str, name: str | None = None, geometry: tuple[int, int, int, int] | None = None, - ) -> "BECDockArea": - """Create a new dock area. + ) -> QWidget: + """Launch the specified script. If the launch script creates a QWidget, it will be + embedded in a BECMainWindow. If the launch script creates a BECMainWindow, it will be shown + as a separate window. Args: + launch_script(str): The name of the script to be launched. name(str): The name of the dock area. geometry(tuple): The geometry parameters to be passed to the dock area. Returns: - BECDockArea: The newly created dock area. + QWidget: The created dock area. """ from bec_widgets.applications import bw_launch