Skip to content

Commit

Permalink
Merge pull request #184 from czbiohub-sf/calibration_thread
Browse files Browse the repository at this point in the history
adding the calibration qt_thread
  • Loading branch information
edyoshikun authored Jan 5, 2024
2 parents 858b5e7 + 74de070 commit e6203c6
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions copylot/assemblies/photom/demo/photom_calibration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
import yaml
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyQt5.QtWidgets import (
QApplication,
QMainWindow,
Expand All @@ -26,7 +26,7 @@
from copylot.assemblies.photom.utils.qt_utils import DoubleSlider
import numpy as np
from copylot.assemblies.photom.photom import PhotomAssembly
from typing import Tuple
from typing import Any, Tuple

# DEMO_MODE = True
DEMO_MODE = False
Expand Down Expand Up @@ -131,7 +131,6 @@ def initialize_UI(self):
self.setLayout(layout)

def update_mirror_x(self, value):
print(f'updating mirror x to {value}')
self.mirror.position_x = value
# Update the QLabel with the new X value
self.mirror_x_label.setText(f"X: {value}")
Expand Down Expand Up @@ -167,6 +166,10 @@ def __init__(
self.photom_window_pos = photom_window_pos
self._current_mirror_idx = 0

self.calibration_thread = CalibrationThread(
self.photom_assembly, self._current_mirror_idx
)

if DEMO_MODE:
self.demo_window = demo_window

Expand Down Expand Up @@ -302,14 +305,11 @@ def calibrate(self):
print(f'Calibrating mirror: {self._current_mirror_idx}')
else:
self.photom_assembly._calibrating = True
self.photom_assembly.calibrate(
self._current_mirror_idx,
rectangle_size_xy=[0.002, 0.002],
center=[0.000, 0.000],
)
self.calibration_thread.start()

def cancel_calibration(self):
self.photom_assembly._calibrating = False

# Implement your cancel calibration function here
print("Canceling calibration...")
# Hide the "Done Calibration" button
Expand Down Expand Up @@ -400,6 +400,23 @@ def display_rectangle(self):
self.photom_window.switch_to_calibration_scene()


class CalibrationThread(QThread):
finished = pyqtSignal()

def __init__(self, photom_assembly, current_mirror_idx):
super().__init__()
self.photom_assembly = photom_assembly
self.current_mirror_idx = current_mirror_idx

def run(self):
self.photom_assembly.calibrate(
self.current_mirror_idx,
rectangle_size_xy=[0.002, 0.002],
center=[0.000, 0.000],
)
self.finished.emit()


class LaserMarkerWindow(QMainWindow):
def __init__(
self,
Expand Down

0 comments on commit e6203c6

Please sign in to comment.