wip state drag&drop

This commit is contained in:
2026-05-29 17:14:42 +02:00
parent c1714e3d15
commit 589bb6b7c3
3 changed files with 16 additions and 3 deletions
+1
View File
@@ -733,6 +733,7 @@ class BeamlineStateManager(RPCBase):
Supported values:
``"config"``: drag the full state configuration dictionary.
``"device"``: drag only the configured device name.
``"name"``: drag only the beamline state name.
"""
@rpc_call
@@ -77,7 +77,7 @@ class BeamlineStatePill(BECWidget, QWidget):
"unknown": "help",
}
_SETTINGS_FIELD_WIDTH = 280
_VALID_DRAG_PAYLOAD_MODES = {"config", "device"}
_VALID_DRAG_PAYLOAD_MODES = {"config", "device", "name"}
MIME_PAYLOAD = "application/x-bec-beamline-state-payload"
MIME_CONFIG = "application/x-bec-beamline-state-config"
MIME_NAME = "application/x-bec-beamline-state-name"
@@ -359,6 +359,7 @@ class BeamlineStatePill(BECWidget, QWidget):
Supported values:
``"config"``: drag the full state configuration dictionary.
``"device"``: drag only the configured device name.
``"name"``: drag only the beamline state name.
"""
return self._drag_payload_mode
@@ -643,6 +644,8 @@ class BeamlineStatePill(BECWidget, QWidget):
"""Return the currently configured drag payload."""
if self._drag_payload_mode == "device":
return str(self._state_field("device") or "")
if self._drag_payload_mode == "name":
return self._state_name or ""
return self._state_config
def _state_field(self, name: str) -> Any:
@@ -1245,6 +1248,7 @@ class BeamlineStateManager(BECWidget, QWidget):
Supported values:
``"config"``: drag the full state configuration dictionary.
``"device"``: drag only the configured device name.
``"name"``: drag only the beamline state name.
"""
return self._drag_payload_mode
@@ -1657,6 +1661,7 @@ if __name__ == "__main__": # pragma: no cover
mode_combo = QComboBox(window)
mode_combo.addItem("Drag full config", "config")
mode_combo.addItem("Drag device name", "device")
mode_combo.addItem("Drag state name", "name")
mode_combo.currentIndexChanged.connect(
lambda: setattr(manager, "drag_payload_mode", mode_combo.currentData())
)
+9 -2
View File
@@ -153,6 +153,13 @@ def test_beamline_state_pill_drag_payload_modes(qtbot, mocked_client):
assert bytes(device_mime.data(BeamlineStatePill.MIME_DEVICE)).decode("utf-8") == "samx"
assert device_mime.text() == "samx"
widget.drag_payload_mode = "name"
name_mime = widget._create_drag_mime_data()
assert bytes(name_mime.data(BeamlineStatePill.MIME_PAYLOAD)).decode("utf-8") == "limits"
assert bytes(name_mime.data(BeamlineStatePill.MIME_NAME)).decode("utf-8") == "limits"
assert name_mime.text() == "limits"
def test_beamline_state_manager_adds_and_removes_pills(qtbot, mocked_client):
widget = BeamlineStateManager(client=mocked_client)
@@ -216,9 +223,9 @@ def test_beamline_state_manager_propagates_drag_payload_mode(qtbot, mocked_clien
assert widget._state_pills["limits"].drag_payload_mode == "device"
widget.drag_payload_mode = "config"
widget.drag_payload_mode = "name"
assert widget._state_pills["limits"].drag_payload_mode == "config"
assert widget._state_pills["limits"].drag_payload_mode == "name"
def test_beamline_state_manager_propagates_idle_card_background(qtbot, mocked_client):