feat(positioner_box): use the stop button as a plain device stop in all positioner boxes

This commit is contained in:
wyzula_j authored and Jan Wyzula committed 2026-11-09 13:55:29 +01:00
1 parent c35539f779
commit 9a01751246
6 files changed
+67 -14

No files matched your search

@@ -11,7 +11,7 @@ from qtpy.QtCore import Qt, Signal
from qtpy.QtGui import QDoubleValidator
from qtpy.QtWidgets import QDoubleSpinBox
from bec_widgets.utils.colors import apply_theme, get_accent_colors
from bec_widgets.utils.colors import apply_theme
from bec_widgets.utils.error_popups import SafeProperty, SafeSlot
from bec_widgets.utils.ui_loader import UILoader
from bec_widgets.widgets.control.device_control.positioner_box.positioner_box_base import (
@@ -80,11 +80,10 @@ class PositionerBox(PositionerBoxBase):
db.setFixedWidth(self.dimensions[1])
self.ui.step_size.setStepType(QDoubleSpinBox.AdaptiveDecimalStepType)
self.ui.stop.clicked.connect(self.on_stop)
# the button stops the motor and leaves the scan queue alone
self.ui.stop.device_stop = True
self.ui.stop.button.clicked.connect(self.on_stop)
self.ui.stop.setToolTip("Stop")
self.ui.stop.setStyleSheet(
f"QPushButton {{background-color: {get_accent_colors().emergency.name()}; color: white;}}"
)
self.ui.tweak_right.clicked.connect(self.on_tweak_right)
self.ui.tweak_right.setToolTip("Tweak right")
self.ui.tweak_left.clicked.connect(self.on_tweak_left)
@@ -115,13 +115,10 @@
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QPushButton" name="stop">
<widget class="StopButton" name="stop">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Stop</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
@@ -226,6 +223,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>StopButton</class>
<extends>QWidget</extends>
<header>stop_button</header>
</customwidget>
<customwidget>
<class>PositionIndicator</class>
<extends>QWidget</extends>
@@ -122,6 +122,8 @@ class PositionerBox2D(PositionerBoxBase):
_init_ui(self.setpoint_validator_hor, "horizontal")
_init_ui(self.setpoint_validator_ver, "vertical")
# the button stops the two motors and leaves the scan queue alone
self.ui.stop_button.device_stop = True
self.ui.stop_button.button.clicked.connect(self.on_stop)
self.ui.step_decrease_hor.clicked.connect(self.on_step_dec_hor)
@@ -153,11 +153,7 @@
</layout>
</item>
<item>
<widget class="QPushButton" name="stop">
<property name="text">
<string>Stop</string>
</property>
</widget>
<widget class="StopButton" name="stop"/>
</item>
<item>
<widget class="QToolButton" name="tweak_left">
@@ -252,6 +248,11 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>StopButton</class>
<extends>QWidget</extends>
<header>stop_button</header>
</customwidget>
<customwidget>
<class>PositionIndicator</class>
<extends></extends>
+29
View File
@@ -9,6 +9,7 @@ from qtpy.QtWidgets import QPushButton
from bec_widgets.tests.client_mocks import mocked_client
from bec_widgets.tests.fake_devices import Positioner
from bec_widgets.widgets.control.buttons.stop_button.stop_button import StopButton
from bec_widgets.widgets.control.device_control.positioner_box import (
PositionerBox,
PositionerControlLine,
@@ -186,3 +187,31 @@ def test_positioner_box_device_without_precision(qtbot, positioner_box):
assert positioner_box.ui.step_size.value() == 10**-mock_return * 10
else:
assert positioner_box.ui.step_size.value() == 10**-8 * 10
@pytest.mark.parametrize("box_class", [PositionerBox, PositionerControlLine])
def test_stop_only_stops_the_motor(qtbot, mocked_client, box_class):
"""The Stop looks like the Scan Control Stop without its menu and only stops samx."""
with mock.patch(
"bec_widgets.widgets.control.device_control.positioner_box.positioner_box_base.PositionerBoxBase._check_device_is_valid",
return_value=True,
):
box = create_widget(qtbot, box_class, device="samx", client=mocked_client)
stop = box.ui.stop
assert isinstance(stop, StopButton)
assert stop.device_stop and stop.arrow.isHidden()
assert stop.toolTip() == "Stop"
stop.setEnabled(True)
with (
mock.patch.object(box.client.connector, "send") as send,
mock.patch.object(stop.queue, "request_scan_abortion") as abort,
mock.patch.object(stop.queue, "request_scan_halt") as halt,
):
stop.button.click()
stop.button.click()
assert send.call_args_list == 2 * [
mock.call(MessageEndpoints.stop_devices(), VariableMessage(value=["samx"]))
]
abort.assert_not_called()
halt.assert_not_called()
assert stop.button.text() == "Stop"
@@ -135,3 +135,23 @@ def test_disable_enable_controls_and_persist_across_device_change(
# Re-enable and verify UI
positioner_box_2d.enable_controls_ver = True
qtbot.waitUntil(lambda: all(w.isEnabled() for w in _ver_buttons(positioner_box_2d)))
def test_stop_only_stops_both_motors(positioner_box_2d):
"""The Stop stops samx and samy; it shows no scan menu and leaves the scan queue alone."""
stop = positioner_box_2d.ui.stop_button
assert stop.device_stop and stop.arrow.isHidden()
stop.setEnabled(True)
with (
mock.patch.object(positioner_box_2d.client.connector, "send") as send,
mock.patch.object(stop.queue, "request_scan_abortion") as abort,
mock.patch.object(stop.queue, "request_scan_halt") as halt,
):
stop.button.click()
stop.button.click()
assert send.call_args_list == 2 * [
mock.call(MessageEndpoints.stop_devices(), VariableMessage(value=["samx", "samy"]))
]
abort.assert_not_called()
halt.assert_not_called()
assert stop.button.text() == "Stop"