Skip to content

Commit

Permalink
disable configuration controls while the probe drive is moving
Browse files Browse the repository at this point in the history
  • Loading branch information
rocco8773 committed Oct 22, 2024
1 parent ab38ef9 commit 1151aa1
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion bapsf_motion/gui/configure/motion_group_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
class AxisControlWidget(QWidget):
axisLinked = Signal()
axisUnlinked = Signal()
movementStarted = Signal(int)
movementStopped = Signal(int)

def __init__(self, parent=None):
super().__init__(parent)
Expand Down Expand Up @@ -255,6 +257,8 @@ def link_axis(self, mg: MotionGroup, ax_index: int):

self.axis_name_label.setText(self.axis.name)
self.axis.motor.status_changed.connect(self._update_display_of_axis_status)
self.axis.motor.movement_started.connect(self._emit_movement_started)
self.axis.motor.movement_finished.connect(self._emit_movement_finished)
self.axis.motor.movement_finished.connect(self._update_display_of_axis_status)
self._update_display_of_axis_status()

Expand All @@ -264,6 +268,8 @@ def unlink_axis(self):
if self.axis is not None:
# self.axis.terminate(delay_loop_stop=True)
self.axis.motor.status_changed.disconnect(self._update_display_of_axis_status)
self.axis.motor.movement_started.connect(self._emit_movement_started)
self.axis.motor.movement_finished.connect(self._emit_movement_finished)
self.axis.motor.movement_finished.disconnect(
self._update_display_of_axis_status
)
Expand All @@ -272,12 +278,29 @@ def unlink_axis(self):
self._axis_index = None
self.axisUnlinked.emit()

def _emit_movement_started(self):
self.movementStarted.emit(self.axis_index)

def _emit_movement_finished(self):
self.movementStopped.emit(self.axis_index)

def closeEvent(self, event):
self.logger.info("Closing AxisControlWidget")

if isinstance(self.axis, Axis):
self.axis.motor.status_changed.disconnect(self._update_display_of_axis_status)
self.axis.motor.movement_started.connect(self._emit_movement_started)
self.axis.motor.movement_finished.connect(self._emit_movement_finished)
self.axis.motor.movement_finished.disconnect(
self._update_display_of_axis_status
)

event.accept()


class DriveControlWidget(QWidget):
movementStarted = Signal()
movementStopped = Signal()

def __init__(self, parent=None):
super().__init__(parent)
Expand Down Expand Up @@ -478,6 +501,8 @@ def link_motion_group(self, mg):
for ii, ax in enumerate(self.mg.drive.axes):
acw = self._axis_control_widgets[ii]
acw.link_axis(self.mg, ii)
acw.movementStarted.connect(self._drive_movement_started)
acw.movementStopped.connect(self._drive_movement_finished)
acw.show()

self.setEnabled(not self._mg.terminated)
Expand All @@ -493,6 +518,20 @@ def unlink_motion_group(self):
self._mg = None
self.setEnabled(False)

@Slot(int)
def _drive_movement_started(self, axis_index):
self.movementStarted.emit()

@Slot(int)
def _drive_movement_finished(self, axis_index):
if not isinstance(self.mg, MotionGroup) or not isinstance(self.mg.drive, Drive):
return

is_moving = [ax.is_moving for ax in self.mg.drive.axes]
is_moving[axis_index] = False
if not any(is_moving):
self.movementStopped.emit()

def closeEvent(self, event):
self.logger.info("Closing DriveControlWidget")
event.accept()
Expand Down Expand Up @@ -535,7 +574,6 @@ def __init__(
"ips": deployed_ips,
}


self._logger = gui_logger

self._mg = None
Expand Down Expand Up @@ -755,6 +793,9 @@ def _connect_signals(self):
self._transform_dropdown_new_selection
)

self.drive_control_widget.movementStarted.connect(self.disable_config_controls)
self.drive_control_widget.movementStopped.connect(self.enable_config_controls)

self.done_btn.clicked.connect(self.return_and_close)
self.discard_btn.clicked.connect(self.close)

Expand Down Expand Up @@ -1628,6 +1669,26 @@ def _transform_dropdown_new_selection(self, index):

self._change_transform(tr_default_config)

def disable_config_controls(self):
self.drive_dropdown.setEnabled(False)
self.drive_btn.setEnabled(False)

self.mb_dropdown.setEnabled(False)
self.mb_btn.setEnabled(False)

self.transform_dropdown.setEnabled(False)
self.transform_btn.setEnabled(False)

def enable_config_controls(self):
self.drive_dropdown.setEnabled(True)
self.drive_btn.setEnabled(True)

self.mb_dropdown.setEnabled(True)
self.mb_btn.setEnabled(True)

self.transform_dropdown.setEnabled(True)
self.transform_btn.setEnabled(True)

def return_and_close(self):
config = _deepcopy_dict(self.mg.config)
index = -1 if self._mg_index is None else self._mg_index
Expand Down

0 comments on commit 1151aa1

Please sign in to comment.