def __init__(self, experiment, **kwargs): """ Instantiate the widget that controls the display on the projector :param experiment: Experiment class with calibrator and display window """ super().__init__(**kwargs) self.experiment = experiment self.calibrator = experiment.calibrator self.container_layout = QVBoxLayout() self.container_layout.setContentsMargins(0, 0, 0, 0) self.widget_proj_viewer = ProjectorViewer( display=experiment.window_display) self.container_layout.addWidget(self.widget_proj_viewer) self.widget_proj_viewer.sig_dim_changed.connect(self.update_size) self.layout_calibrate = QHBoxLayout() self.button_show_calib = QPushButton("Show calibration") self.button_show_calib.clicked.connect(self.toggle_calibration) if isinstance(experiment.calibrator, CircleCalibrator): self.button_calibrate = QPushButton("Calibrate") self.button_calibrate.clicked.connect(self.calibrate) self.layout_calibrate.addWidget(self.button_calibrate) self.label_calibrate = QLabel(self.calibrator.length_to_measure) self.label_calibrate.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.layout_calibrate.addWidget(self.button_show_calib) self.layout_calibrate.addWidget(self.label_calibrate) if isinstance(experiment.calibrator, CircleCalibrator): self.calibrator_px_len = ControlSpin(self.calibrator, "triangle_height") self.layout_calibrate.addWidget(QLabel("calibrator size")) self.layout_calibrate.addWidget(self.calibrator_px_len) self.calibrator_len_spin = ControlSpin(self.calibrator, "length_mm") self.layout_calibrate.addWidget(self.calibrator_len_spin) self.layout_calibrate.setContentsMargins(12, 0, 12, 12) self.container_layout.addLayout(self.layout_calibrate) self.setLayout(self.container_layout)
class ProjectorAndCalibrationWidget(QWidget): """ """ sig_calibrating = pyqtSignal() def __init__(self, experiment, **kwargs): """ Instantiate the widget that controls the display on the projector :param experiment: Experiment class with calibrator and display window """ super().__init__(**kwargs) self.experiment = experiment self.calibrator = experiment.calibrator self.container_layout = QVBoxLayout() self.container_layout.setContentsMargins(0, 0, 0, 0) self.widget_proj_viewer = ProjectorViewer( display=experiment.window_display) self.container_layout.addWidget(self.widget_proj_viewer) self.widget_proj_viewer.sig_dim_changed.connect(self.update_size) self.layout_calibrate = QHBoxLayout() self.button_show_calib = QPushButton("Show calibration") self.button_show_calib.clicked.connect(self.toggle_calibration) if isinstance(experiment.calibrator, CircleCalibrator): self.button_calibrate = QPushButton("Calibrate") self.button_calibrate.clicked.connect(self.calibrate) self.layout_calibrate.addWidget(self.button_calibrate) self.label_calibrate = QLabel(self.calibrator.length_to_measure) self.label_calibrate.setAlignment(Qt.AlignRight | Qt.AlignVCenter) self.layout_calibrate.addWidget(self.button_show_calib) self.layout_calibrate.addWidget(self.label_calibrate) if isinstance(experiment.calibrator, CircleCalibrator): self.calibrator_px_len = ControlSpin(self.calibrator, "triangle_height") self.layout_calibrate.addWidget(QLabel("calibrator size")) self.layout_calibrate.addWidget(self.calibrator_px_len) self.calibrator_len_spin = ControlSpin(self.calibrator, "length_mm") self.layout_calibrate.addWidget(self.calibrator_len_spin) self.layout_calibrate.setContentsMargins(12, 0, 12, 12) self.container_layout.addLayout(self.layout_calibrate) self.setLayout(self.container_layout) def update_size(self, size): self.calibrator.set_pixel_scale(size[0], size[1]) self.calibrator_len_spin.update_display() def toggle_calibration(self): """ """ if isinstance(self.calibrator, CircleCalibrator): _, frame = self.experiment.frame_dispatcher.gui_queue.get() self.widget_proj_viewer.display_calibration_pattern( self.calibrator, frame.shape, frame) self.calibrator.toggle() if self.calibrator.enabled: self.button_show_calib.setText("Hide calibration") else: self.button_show_calib.setText("Show calibration") self.sig_calibrating.emit() self.experiment.window_display.widget_display.update() def calibrate(self): """ """ _, frame = self.experiment.frame_dispatcher.gui_queue.get() try: self.calibrator.find_transform_matrix(frame) self.widget_proj_viewer.display_calibration_pattern( self.calibrator, frame.shape, frame) except CalibrationException: pass