From 565c0bd1e7f4684d8401b6a2827c35422b1125c4 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 24 Sep 2025 09:41:26 -0500 Subject: [PATCH] feat(rpc_base): windows can be raised to front from CLI --- bec_widgets/cli/client_utils.py | 25 +++++++++++++++++++++++++ bec_widgets/cli/rpc/rpc_base.py | 7 ++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/bec_widgets/cli/client_utils.py b/bec_widgets/cli/client_utils.py index 84adc93a..bdcbd05f 100644 --- a/bec_widgets/cli/client_utils.py +++ b/bec_widgets/cli/client_utils.py @@ -285,6 +285,18 @@ class BECGuiClient(RPCBase): """Hide the GUI window.""" return self._hide_all() + def raise_window(self, wait: bool = True) -> None: + """ + Bring GUI windows to the front. + If the GUI server is not running, it will be started. + + Args: + wait(bool): Whether to wait for the server to start. Defaults to True. + """ + if self._check_if_server_is_alive(): + return self._raise_all() + return self._start(wait=wait) + def new( self, name: str | None = None, @@ -460,6 +472,19 @@ class BECGuiClient(RPCBase): for window in self._top_level.values(): window.hide() + def _do_raise_all(self): + """Bring GUI windows to the front.""" + if self.launcher and len(self._top_level) == 0: + self.launcher._run_rpc("raise") # pylint: disable=protected-access + for window in self._top_level.values(): + window._run_rpc("raise") # type: ignore[attr-defined] + + def _raise_all(self): + with wait_for_server(self): + if self._killed: + return + return self._do_raise_all() + def _update_dynamic_namespace(self, server_registry: dict): """ Update the dynamic name space with the given server registry. diff --git a/bec_widgets/cli/rpc/rpc_base.py b/bec_widgets/cli/rpc/rpc_base.py index 9a5f502f..fb1a9c20 100644 --- a/bec_widgets/cli/rpc/rpc_base.py +++ b/bec_widgets/cli/rpc/rpc_base.py @@ -202,6 +202,11 @@ class RPCBase: parent = parent._parent return parent # type: ignore + def raise_window(self): + """Bring this widget (or its container) to the front.""" + # Use explicit call to ensure action name is 'raise' (not 'raise_') + return self._run_rpc("raise") + def _run_rpc( self, method, @@ -225,7 +230,7 @@ class RPCBase: Returns: The result of the RPC call. """ - if method in ["show", "hide"] and gui_id is None: + if method in ["show", "hide", "raise"] and gui_id is None: obj = self._root._server_registry.get(self._gui_id) if obj is None: raise ValueError(f"Widget {self._gui_id} not found.")