From c1714e3d15ff223b2bcfe093a21806c7fe31ba6b Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Fri, 29 May 2026 17:11:07 +0200 Subject: [PATCH] wip added to dock area as util --- bec_widgets/cli/client.py | 123 ++++++++++++++++++ bec_widgets/cli/designer_plugins.py | 10 ++ .../widgets/containers/dock_area/dock_area.py | 5 + tests/unit_tests/test_dock_area.py | 11 +- 4 files changed, 148 insertions(+), 1 deletion(-) diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 1f84fa5a..df821022 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -32,6 +32,8 @@ _Widgets = { "BECQueue": "BECQueue", "BECShell": "BECShell", "BECStatusBox": "BECStatusBox", + "BeamlineStateManager": "BeamlineStateManager", + "BeamlineStatePill": "BeamlineStatePill", "BecConsole": "BecConsole", "DapComboBox": "DapComboBox", "DeviceBrowser": "DeviceBrowser", @@ -717,6 +719,127 @@ class BaseROI(RPCBase): """ +class BeamlineStateManager(RPCBase): + """Widget displaying and managing all BEC beamline states.""" + + _IMPORT_MODULE = "bec_widgets.widgets.services.beamline_states.beamline_state_pill" + + @property + @rpc_call + def drag_payload_mode(self) -> "str": + """ + Payload mode used by pills dragged from this manager. + + Supported values: + ``"config"``: drag the full state configuration dictionary. + ``"device"``: drag only the configured device name. + """ + + @rpc_call + def set_drag_payload_mode(self, mode: "str") -> "None": + """ + Set the payload mode used for drag-and-drop. + """ + + @property + @rpc_call + def idle_card_background(self) -> "bool": + """ + Whether idle collapsed pills keep the status-tinted card background. + """ + + @rpc_call + def set_idle_card_background(self, enabled: "bool") -> "None": + """ + Set whether idle collapsed pills keep the status-tinted card background. + """ + + @rpc_call + def refresh_states(self) -> "None": + """ + Fetch the latest cached available beamline states and update the list immediately. + """ + + @rpc_call + def clear_filters(self) -> "None": + """ + None + """ + + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + + @rpc_call + def attach(self): + """ + None + """ + + @rpc_call + def detach(self): + """ + Detach the widget from its parent dock widget (if widget is in the dock), making it a floating widget. + """ + + @rpc_timeout(None) + @rpc_call + def screenshot(self, file_name: "str | None" = None): + """ + Take a screenshot of the dock area and save it to a file. + """ + + +class BeamlineStatePill(RPCBase): + """Compact widget showing one BEC beamline state.""" + + _IMPORT_MODULE = "bec_widgets.widgets.services.beamline_states.beamline_state_pill" + + @property + @rpc_call + def state_name(self) -> "str | None": + """ + Name of the BEC beamline state displayed by this pill. + """ + + @rpc_call + def set_state_name(self, state_name: "str | None", title: "str | None" = None) -> "None": + """ + Set the BEC beamline state this pill displays. + + Args: + state_name: State name as published by ``AvailableBeamlineStatesMessage``. + title: Optional human-readable title for the state. + """ + + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + + @rpc_call + def attach(self): + """ + None + """ + + @rpc_call + def detach(self): + """ + Detach the widget from its parent dock widget (if widget is in the dock), making it a floating widget. + """ + + @rpc_timeout(None) + @rpc_call + def screenshot(self, file_name: "str | None" = None): + """ + Take a screenshot of the dock area and save it to a file. + """ + + class BecConsole(RPCBase): """A console widget with access to a shared registry of terminals, such that instances can be moved around.""" diff --git a/bec_widgets/cli/designer_plugins.py b/bec_widgets/cli/designer_plugins.py index bdbdcb6f..6315596e 100644 --- a/bec_widgets/cli/designer_plugins.py +++ b/bec_widgets/cli/designer_plugins.py @@ -19,6 +19,14 @@ designer_plugins = { "BECShell": ("bec_widgets.widgets.editors.bec_console.bec_console", "BECShell"), "BECSpinBox": ("bec_widgets.widgets.utility.spinbox.decimal_spinbox", "BECSpinBox"), "BECStatusBox": ("bec_widgets.widgets.services.bec_status_box.bec_status_box", "BECStatusBox"), + "BeamlineStateManager": ( + "bec_widgets.widgets.services.beamline_states.beamline_state_pill", + "BeamlineStateManager", + ), + "BeamlineStatePill": ( + "bec_widgets.widgets.services.beamline_states.beamline_state_pill", + "BeamlineStatePill", + ), "BecConsole": ("bec_widgets.widgets.editors.bec_console.bec_console", "BecConsole"), "ColorButton": ("bec_widgets.widgets.utility.visual.color_button.color_button", "ColorButton"), "ColorButtonNative": ( @@ -118,6 +126,8 @@ widget_icons = { "BECShell": "hub", "BECSpinBox": "123", "BECStatusBox": "widgets", + "BeamlineStateManager": "format_list_bulleted", + "BeamlineStatePill": "info", "BecConsole": "terminal", "ColorButton": "colors", "ColorButtonNative": "colors", diff --git a/bec_widgets/widgets/containers/dock_area/dock_area.py b/bec_widgets/widgets/containers/dock_area/dock_area.py index 01e0656e..acd03392 100644 --- a/bec_widgets/widgets/containers/dock_area/dock_area.py +++ b/bec_widgets/widgets/containers/dock_area/dock_area.py @@ -385,6 +385,11 @@ class BECDockArea(DockAreaWidget): "bec_shell": (widget_icons["BECShell"], "Add BEC Shell", "BECShell"), "sbb_monitor": (widget_icons["SBBMonitor"], "Add SBB Monitor", "SBBMonitor"), "log_panel": (widget_icons["LogPanel"], "Add LogPanel", "LogPanel"), + "beamline_state_manager": ( + widget_icons["BeamlineStateManager"], + "Add Beamline State Manager", + "BeamlineStateManager", + ), } # Create expandable menu actions (original behavior) diff --git a/tests/unit_tests/test_dock_area.py b/tests/unit_tests/test_dock_area.py index 35c1900b..10334ede 100644 --- a/tests/unit_tests/test_dock_area.py +++ b/tests/unit_tests/test_dock_area.py @@ -869,7 +869,14 @@ class TestToolbarFunctionality: def test_toolbar_utils_actions(self, advanced_dock_area): """Test utils toolbar actions trigger widget creation.""" - utils_actions = ["queue", "terminal", "status", "progress_bar", "sbb_monitor"] + utils_actions = [ + "queue", + "terminal", + "status", + "progress_bar", + "sbb_monitor", + "beamline_state_manager", + ] for action_name in utils_actions: with patch.object(advanced_dock_area, "new") as mock_new: @@ -2428,6 +2435,7 @@ class TestFlatToolbarActions: "flat_terminal", "flat_bec_shell", "flat_sbb_monitor", + "flat_beamline_state_manager", ] for action_name in utils_actions: @@ -2472,6 +2480,7 @@ class TestFlatToolbarActions: "flat_terminal": "BecConsole", "flat_bec_shell": "BECShell", "flat_sbb_monitor": "SBBMonitor", + "flat_beamline_state_manager": "BeamlineStateManager", } for action_name, widget_type in utils_action_mapping.items():