Skip to content

Commit

Permalink
if the status of one axis changes make the other AxisControlWidgets u…
Browse files Browse the repository at this point in the history
…pdate
  • Loading branch information
rocco8773 committed Oct 22, 2024
1 parent 1151aa1 commit 4f2599f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bapsf_motion/gui/configure/motion_group_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import logging
import warnings

from PySide6.QtCore import Qt, Signal, Slot, QSize
from PySide6.QtGui import QDoubleValidator
Expand Down Expand Up @@ -41,6 +42,7 @@ class AxisControlWidget(QWidget):
axisUnlinked = Signal()
movementStarted = Signal(int)
movementStopped = Signal(int)
axisStatusChanged = Signal()

def __init__(self, parent=None):
super().__init__(parent)
Expand Down Expand Up @@ -257,6 +259,7 @@ 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.status_changed.connect(self.axisStatusChanged.emit)
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)
Expand All @@ -268,6 +271,7 @@ 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.status_changed.connect(self.axisStatusChanged.emit)
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(
Expand All @@ -289,6 +293,7 @@ def closeEvent(self, event):

if isinstance(self.axis, Axis):
self.axis.motor.status_changed.disconnect(self._update_display_of_axis_status)
self.axis.motor.status_changed.disconnect(self.axisStatusChanged.emit)
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(
Expand Down Expand Up @@ -503,6 +508,7 @@ def link_motion_group(self, mg):
acw.link_axis(self.mg, ii)
acw.movementStarted.connect(self._drive_movement_started)
acw.movementStopped.connect(self._drive_movement_finished)
acw.axisStatusChanged.connect(self._update_all_axis_displays)
acw.show()

self.setEnabled(not self._mg.terminated)
Expand All @@ -512,12 +518,28 @@ def unlink_motion_group(self):
visible = True if ii == 0 else False

acw.unlink_axis()

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=RuntimeWarning)
acw.movementStarted.disconnect(self._drive_movement_started)
acw.movementStopped.disconnect(self._drive_movement_finished)
acw.axisStatusChanged.disconnect(self._update_all_axis_displays)

acw.setVisible(visible)

# self.mg.terminate(delay_loop_stop=True)
self._mg = None
self.setEnabled(False)

def _update_all_axis_displays(self):
for acw in self._axis_control_widgets:
if acw.isHidden():
continue
elif acw.axis.is_moving:
continue

acw._update_display_of_axis_status()

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

0 comments on commit 4f2599f

Please sign in to comment.