0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

refactor: sync_step_sizes generalised to one function

This commit is contained in:
wyzula-jan
2023-09-05 16:29:30 +02:00
parent aede1988ec
commit 9beaa8f8cf

View File

@ -254,10 +254,14 @@ class MotorApp(QWidget):
def init_ui_motor_control(self) -> None:
"""Initialize the motor control elements"""
# Connect checkbox and spinBoxes
self.checkBox_same_xy.stateChanged.connect(self.sync_step_sizes)
self.spinBox_step_x.valueChanged.connect(self.update_step_size_x)
self.spinBox_step_y.valueChanged.connect(self.update_step_size_y)
# Connect CheckBox stateChanged signal to sync function
self.checkBox_same_xy.stateChanged.connect(
lambda: self.sync_step_sizes(self.spinBox_step_x, self.spinBox_step_y)
)
# TODO remove
# self.spinBox_step_x.valueChanged.connect(self.update_step_size_x)
# self.spinBox_step_y.valueChanged.connect(self.update_step_size_y)
self.toolButton_right.clicked.connect(
lambda: self.move_motor_relative(self.motor_x, "x", 1)
@ -607,25 +611,10 @@ class MotorApp(QWidget):
new_step = old_step * factor
spinBox.setValue(new_step)
# TODO generalise the following functions:
def sync_step_sizes(self):
"""Sync step sizes based on checkbox state."""
def sync_step_sizes(self, spinBox1, spinBox2):
if self.checkBox_same_xy.isChecked():
value = self.spinBox_step_x.value()
self.spinBox_step_y.setValue(value)
def update_step_size_x(self):
"""Update step size for x if checkbox is checked."""
if self.checkBox_same_xy.isChecked():
value = self.spinBox_step_x.value()
self.spinBox_step_y.setValue(value)
def update_step_size_y(self):
"""Update step size for y if checkbox is checked."""
if self.checkBox_same_xy.isChecked():
value = self.spinBox_step_y.value()
self.spinBox_step_x.setValue(value)
value = spinBox1.value()
spinBox2.setValue(value)
@staticmethod
def param_changed(ui_element):