Skip to content

Commit

Permalink
prevent constant update of scan coordinate preview
Browse files Browse the repository at this point in the history
before this (1) set_live_scan_coordinates will be called even if
the stage is not moving (2) set_live_scan_coordinates can happen
too frequently - problematic for big scan area coverage
  • Loading branch information
hongquanli committed Jan 4, 2025
1 parent 24b89c8 commit d413eb1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion software/control/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3074,6 +3074,12 @@ def __init__(
self.eta_seconds = 0
self.is_current_acquisition_widget = False
self.parent = self.multipointController.parent

# TODO (hl): these along with update_live_coordinates need to move out of this class
self._last_update_time = 0
self._last_x_mm = None
self._last_y_mm = None

self.add_components()
self.setFrameStyle(QFrame.Panel | QFrame.Raised)
self.set_default_scan_size()
Expand Down Expand Up @@ -3637,14 +3643,21 @@ def update_well_coordinates(self, selected):
self.scanCoordinates.clear_regions()

def update_live_coordinates(self, pos: squid.abc.Pos):
if hasattr(self.parent, "recordTabWidget") and self.parent.recordTabWidget.currentWidget() != self:
return
x_mm = pos.x_mm
y_mm = pos.y_mm
if hasattr(self.parent, "recordTabWidget") and self.parent.recordTabWidget.currentWidget() != self:
# Check if x_mm or y_mm has changed
position_changed = (x_mm != self._last_x_mm) or (y_mm != self._last_y_mm)
if not position_changed or time.time() - self._last_update_time < 0.5:
return
scan_size_mm = self.entry_scan_size.value()
overlap_percent = self.entry_overlap.value()
shape = self.combobox_shape.currentText()
self.scanCoordinates.set_live_scan_coordinates(x_mm, y_mm, scan_size_mm, overlap_percent, shape)
self._last_update_time = time.time()
self._last_x_mm = x_mm
self._last_y_mm = y_mm

def toggle_acquisition(self, pressed):
if not self.base_path_is_set:
Expand Down

0 comments on commit d413eb1

Please sign in to comment.