mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-06-09 14:48:50 +02:00
refactor(positioner-box): cleanup, accept float precision
This commit is contained in:
+14
-16
@@ -138,7 +138,11 @@ class PositionerBoxBase(BECWidget, CompactPopupWidget):
|
||||
signals = msg_content.get("signals", {})
|
||||
# pylint: disable=protected-access
|
||||
hinted_signals = self.dev[device]._hints
|
||||
precision = getattr(self.dev[device], "precision", None)
|
||||
precision = getattr(self.dev[device], "precision", 8)
|
||||
try:
|
||||
precision = int(precision)
|
||||
except (TypeError, ValueError):
|
||||
precision = int(8)
|
||||
|
||||
spinner = ui_components["spinner"]
|
||||
position_indicator = ui_components["position_indicator"]
|
||||
@@ -178,18 +182,12 @@ class PositionerBoxBase(BECWidget, CompactPopupWidget):
|
||||
spinner.setVisible(False)
|
||||
|
||||
if readback_val is not None:
|
||||
if not isinstance(precision, bool) and isinstance(precision, int):
|
||||
text = f"{readback_val:.{precision}f}"
|
||||
else:
|
||||
text = str(readback_val)
|
||||
text = f"{readback_val:.{precision}f}"
|
||||
readback.setText(text)
|
||||
position_emit(readback_val)
|
||||
|
||||
if setpoint_val is not None:
|
||||
if not isinstance(precision, bool) and isinstance(precision, int):
|
||||
text = f"{setpoint_val:.{precision}f}"
|
||||
else:
|
||||
text = str(setpoint_val)
|
||||
text = f"{setpoint_val:.{precision}f}"
|
||||
setpoint.setText(text)
|
||||
|
||||
limits = self.dev[device].limits
|
||||
@@ -213,13 +211,13 @@ class PositionerBoxBase(BECWidget, CompactPopupWidget):
|
||||
ui["readback"].setToolTip(f"{device} readback")
|
||||
ui["setpoint"].setToolTip(f"{device} setpoint")
|
||||
ui["step_size"].setToolTip(f"Step size for {device}")
|
||||
precision = getattr(self.dev[device], "precision", None)
|
||||
if not isinstance(precision, bool) and isinstance(precision, int):
|
||||
ui["step_size"].setDecimals(precision)
|
||||
ui["step_size"].setValue(10**-precision * 10)
|
||||
else: # Default to 8 decimals if precision is not specified
|
||||
ui["step_size"].setDecimals(8)
|
||||
ui["step_size"].setValue(10**-8 * 10)
|
||||
precision = getattr(self.dev[device], "precision", 8)
|
||||
try:
|
||||
precision = int(precision)
|
||||
except (TypeError, ValueError):
|
||||
precision = int(8)
|
||||
ui["step_size"].setDecimals(precision)
|
||||
ui["step_size"].setValue(10**-precision * 10)
|
||||
|
||||
def _swap_readback_signal_connection(self, slot, old_device, new_device):
|
||||
self.bec_dispatcher.disconnect_slot(slot, MessageEndpoints.device_readback(old_device))
|
||||
|
||||
@@ -45,11 +45,12 @@ class PositionerGroupBox(QGroupBox):
|
||||
|
||||
def _on_position_update(self, pos: float):
|
||||
self.position_update.emit(pos)
|
||||
precision = getattr(self.widget.dev[self.widget.device], "precision", None)
|
||||
if not isinstance(precision, bool) and isinstance(precision, int):
|
||||
self.widget.label = f"{pos:.{precision}f}"
|
||||
else:
|
||||
self.widget.label = f"{pos}"
|
||||
precision = getattr(self.widget.dev[self.widget.device], "precision", 8)
|
||||
try:
|
||||
precision = int(precision)
|
||||
except (TypeError, ValueError):
|
||||
precision = int(8)
|
||||
self.widget.label = f"{pos:.{precision}f}"
|
||||
|
||||
def close(self):
|
||||
self.widget.close()
|
||||
|
||||
@@ -196,7 +196,8 @@ def test_positioner_box_device_without_precision(qtbot, positioner_box):
|
||||
return positioner_box.ui.device_box.title() == dev_name
|
||||
|
||||
qtbot.waitUntil(check_title, timeout=3000)
|
||||
if not isinstance(mock_return, bool) and isinstance(mock_return, int):
|
||||
if isinstance(mock_return, (int, float)):
|
||||
mock_return = int(mock_return)
|
||||
assert positioner_box.ui.step_size.value() == 10**-mock_return * 10
|
||||
else:
|
||||
assert positioner_box.ui.step_size.value() == 10**-8 * 10
|
||||
|
||||
Reference in New Issue
Block a user