Exemple #1
0
 def mouse_position_changed(self, x, y, modifiers):
     p = Geometry.IntPoint(x=x, y=y)
     if self.__drag_start is not None and Geometry.distance(p, self.__drag_start) > 2:
         self.__drag_start = None
         on_drag_pressed = self.on_drag_pressed
         if on_drag_pressed:
             on_drag_pressed(x, y, modifiers)
Exemple #2
0
 def mouse_position_changed(self, x, y, modifiers):
     pt = Geometry.IntPoint(y=y, x=x)
     if self.__mouse_pressed_position and Geometry.distance(self.__mouse_pressed_position, pt) > 12:
         on_drag_pressed = self.on_drag_pressed
         if callable(on_drag_pressed):
             self.__mouse_pressed_position = None
             on_drag_pressed()
Exemple #3
0
 def mouse_position_changed(self, x, y, modifiers):
     if self.__mouse_pressed_for_dragging:
         if not self.__mouse_dragging and Geometry.distance(
                 self.__mouse_position, Geometry.IntPoint(y=y, x=x)) > 8:
             self.__mouse_dragging = True
             drag_started = getattr(self.__delegate, "drag_started",
                                    None) if self.__delegate else None
             if callable(drag_started):
                 root_container = self.root_container
                 if root_container:
                     root_container.bypass_request_focus()
                 drag_started(self.__mouse_index, x, y, modifiers)
                 # once a drag starts, mouse release will not be called; call it here instead
                 self.__mouse_released(x, y, modifiers, False)
             # TODO: delete soon. only here for backwards compatibility.
             on_drag_started = getattr(self.__delegate, "on_drag_started",
                                       None) if self.__delegate else None
             if callable(on_drag_started):
                 root_container = self.root_container
                 if root_container:
                     root_container.bypass_request_focus()
                 on_drag_started(self.__mouse_index, x, y, modifiers)
                 # once a drag starts, mouse release will not be called; call it here instead
                 self.__mouse_released(x, y, modifiers, False)
             return True
     return super().mouse_position_changed(x, y, modifiers)
Exemple #4
0
 def mouse_position_changed(self, x, y, modifiers):
     if self.__mouse_pressed:
         if not self.__mouse_dragging and Geometry.distance(self.__mouse_position, Geometry.IntPoint(y=y, x=x)) > 8:
             self.__mouse_dragging = True
             self.__drag_started(self.__mouse_item, x, y, modifiers)
             # once a drag starts, mouse release will not be called; call it here instead
             self.mouse_released(x, y, modifiers)
             return True
     return super().mouse_position_changed(x, y, modifiers)
 def mouse_position_changed(
         self, x: int, y: int,
         modifiers: UserInterface.KeyboardModifiers) -> bool:
     if self.__drag_start is not None and Geometry.distance(
             Geometry.FloatPoint(y, x),
             self.__drag_start.to_float_point()) > 2:
         self.__drag_start = None
         on_drag_pressed = self.on_drag_pressed
         if on_drag_pressed:
             on_drag_pressed(x, y, modifiers)
             return True
     return False
Exemple #6
0
 def mouse_position_changed(self, x, y, modifiers):
     if self.__mouse_pressed_for_dragging:
         if not self.__mouse_dragging and Geometry.distance(self.__mouse_position, Geometry.IntPoint(y=y, x=x)) > 8:
             self.__mouse_dragging = True
             if self.__delegate and self.__delegate.on_drag_started:
                 root_container = self.root_container
                 if root_container:
                     root_container.bypass_request_focus()
                 self.__delegate.on_drag_started(self.__mouse_index, x, y, modifiers)
                 # once a drag starts, mouse release will not be called; call it here instead
                 self.__mouse_released(x, y, modifiers, False)
             return True
     return super().mouse_position_changed(x, y, modifiers)
Exemple #7
0
 def mouse_position_changed(
         self, x: int, y: int,
         modifiers: UserInterface.KeyboardModifiers) -> bool:
     pt = Geometry.FloatPoint(y=y, x=x)
     mouse_pressed_pos = self.__mouse_pressed_position
     if mouse_pressed_pos and Geometry.distance(
             mouse_pressed_pos.to_float_point(), pt) > 12:
         on_drag_pressed = self.on_drag_pressed
         if callable(on_drag_pressed):
             self.__mouse_pressed_position = None
             on_drag_pressed()
             return True
     return False
Exemple #8
0
 def mouse_position_changed(self, x: int, y: int, modifiers: UserInterface.KeyboardModifiers) -> bool:
     if self.__mouse_pressed_for_dragging and self.__mouse_position and self.__mouse_index is not None:
         mouse_position_f = self.__mouse_position.to_float_point()
         point_f = Geometry.FloatPoint(y=y, x=x)
         if not self.__mouse_dragging and Geometry.distance(mouse_position_f, point_f) > 8:
             self.__mouse_dragging = True
             if self.__delegate:
                 root_container = self.root_container
                 if root_container:
                     root_container.bypass_request_focus()
                 self.__delegate.drag_started(self.__mouse_index, x, y, modifiers)
                 # once a drag starts, mouse release will not be called; call it here instead
                 self.__mouse_released(x, y, modifiers, False)
             return True
     return super().mouse_position_changed(x, y, modifiers)
        def update_context() -> None:
            assert self.__scan_hardware_source_choice
            scan_hardware_source = typing.cast(
                scan_base.ScanHardwareSource,
                self.__scan_hardware_source_choice.hardware_source)
            if not scan_hardware_source:
                clear_scan_context_fields()
                return

            scan_context = scan_hardware_source.scan_context

            scan_context_size = scan_context.size
            exposure_ms = self.__exposure_time_ms_value_model.value or 0.0 if self.__exposure_time_ms_value_model else 0.0
            if scan_context.is_valid and scan_hardware_source.line_scan_enabled and scan_hardware_source.line_scan_vector:
                assert scan_context_size
                calibration = scan_context.calibration
                start = Geometry.FloatPoint.make(
                    scan_hardware_source.line_scan_vector[0])
                end = Geometry.FloatPoint.make(
                    scan_hardware_source.line_scan_vector[1])
                length = int(
                    Geometry.distance(start, end) * scan_context_size.height)
                max_dim = max(scan_context_size.width,
                              scan_context_size.height)
                length_str = calibration.convert_to_calibrated_size_str(
                    length, value_range=(0, max_dim), samples=max_dim)
                line_str = _("Line Scan")
                self.__roi_description.text = f"{line_str} {length_str} ({length} px)"
                scan_str = _("Scan (1D)")
                scan_length = max(self.__scan_width, 1)
                self.__scan_label_widget.text = f"{scan_str} {scan_length} px"
                self.__scan_pixels = scan_length
                self.__scan_specifier.scan_context = copy.deepcopy(
                    scan_context)
                self.__scan_specifier.scan_count = max(self.__scan_count, 1)
                self.__scan_specifier.size = 1, scan_length
                self.__scan_specifier.drift_interval_lines = 0
                self.__scan_specifier.drift_interval_scans = 0
                self.__acquire_button._widget.enabled = True
            elif scan_context.is_valid and scan_hardware_source.subscan_enabled and scan_hardware_source.subscan_region:
                assert scan_context_size
                calibration = scan_context.calibration
                width = scan_hardware_source.subscan_region.width * scan_context_size.width
                height = scan_hardware_source.subscan_region.height * scan_context_size.height
                width_str = calibration.convert_to_calibrated_size_str(
                    width,
                    value_range=(0, scan_context_size.width),
                    samples=scan_context_size.width)
                height_str = calibration.convert_to_calibrated_size_str(
                    height,
                    value_range=(0, scan_context_size.height),
                    samples=scan_context_size.height)
                rect_str = _("Subscan")
                self.__roi_description.text = f"{rect_str} {width_str} x {height_str} ({int(width)} px x {int(height)} px)"
                scan_str = _("Scan (2D)")
                scan_width = self.__scan_width
                scan_height = int(self.__scan_width * height / width)
                drift_lines = scan_hardware_source.calculate_drift_lines(
                    scan_width, exposure_ms /
                    1000) if scan_hardware_source else 0
                drift_str = f" / Drift {drift_lines} lines" if drift_lines > 0 else str(
                )
                drift_scans = scan_hardware_source.calculate_drift_scans()
                drift_str = f" / Drift {drift_scans} scans" if drift_scans > 0 else drift_str
                self.__scan_label_widget.text = f"{scan_str} {scan_width} x {scan_height} px" + drift_str
                self.__scan_pixels = scan_width * scan_height
                self.__scan_specifier.scan_context = copy.deepcopy(
                    scan_context)
                self.__scan_specifier.scan_count = max(self.__scan_count, 1)
                self.__scan_specifier.size = scan_height, scan_width
                self.__scan_specifier.drift_interval_lines = drift_lines
                self.__scan_specifier.drift_interval_scans = drift_scans
                self.__acquire_button._widget.enabled = True
            elif scan_context.is_valid:
                assert scan_context_size
                calibration = scan_context.calibration
                width = scan_context_size.width
                height = scan_context_size.height
                width_str = calibration.convert_to_calibrated_size_str(
                    width,
                    value_range=(0, scan_context_size.width),
                    samples=scan_context_size.width)
                height_str = calibration.convert_to_calibrated_size_str(
                    height,
                    value_range=(0, scan_context_size.height),
                    samples=scan_context_size.height)
                data_str = _("Context Scan")
                self.__roi_description.text = f"{data_str} {width_str} x {height_str} ({int(width)} x {int(height)})"
                scan_str = _("Scan (2D)")
                scan_width = self.__scan_width
                scan_height = int(self.__scan_width * height / width)
                drift_lines = scan_hardware_source.calculate_drift_lines(
                    scan_width, exposure_ms /
                    1000) if scan_hardware_source else 0
                drift_str = f" / Drift {drift_lines} lines" if drift_lines > 0 else str(
                )
                drift_scans = scan_hardware_source.calculate_drift_scans()
                drift_str = f" / Drift {drift_scans} scans" if drift_scans > 0 else drift_str
                self.__scan_label_widget.text = f"{scan_str} {scan_width} x {scan_height} px" + drift_str
                self.__scan_pixels = scan_width * scan_height
                self.__scan_specifier.scan_context = copy.deepcopy(
                    scan_context)
                self.__scan_specifier.scan_count = max(self.__scan_count, 1)
                self.__scan_specifier.size = scan_height, scan_width
                self.__scan_specifier.drift_interval_lines = drift_lines
                self.__scan_specifier.drift_interval_scans = drift_scans
                self.__acquire_button._widget.enabled = True
            else:
                clear_scan_context_fields()

            self.__scan_count_widget.text = Converter.IntegerToStringConverter(
            ).convert(self.__scan_count)

            self.__scan_width_widget.text = Converter.IntegerToStringConverter(
            ).convert(self.__scan_width)

            self.__update_estimate()
Exemple #10
0
        def update_context() -> None:
            scan_hardware_source = typing.cast(scan_base.ScanHardwareSource, self.__scan_hardware_source_choice.hardware_source)
            scan_context = scan_hardware_source.scan_context

            if scan_context.is_valid and scan_hardware_source.line_scan_enabled and scan_hardware_source.line_scan_vector:
                calibration = scan_context.calibration
                start = Geometry.FloatPoint.make(scan_hardware_source.line_scan_vector[0])
                end = Geometry.FloatPoint.make(scan_hardware_source.line_scan_vector[1])
                length = int(Geometry.distance(start, end) * scan_context.size.height)
                max_dim = max(scan_context.size.width, scan_context.size.height)
                length_str = calibration.convert_to_calibrated_size_str(length, value_range=(0, max_dim), samples=max_dim)
                line_str = _("Line Scan")
                self.__roi_description.text = f"{line_str} {length_str} ({length} px)"
                scan_str = _("Scan (1D)")
                scan_length = max(self.__scan_width, 1)
                self.__scan_label_widget.text = f"{scan_str} {scan_length} px"
                self.__scan_pixels = scan_length
                self.__scan_specifier.scan_context = copy.deepcopy(scan_context)
                self.__scan_specifier.size = 1, scan_length
                self.__scan_specifier.drift_interval_lines = 0
                self.__acquire_button._widget.enabled = True
            elif scan_context.is_valid and scan_hardware_source.subscan_enabled and scan_hardware_source.subscan_region:
                calibration = scan_context.calibration
                width = scan_hardware_source.subscan_region.width * scan_context.size.width
                height = scan_hardware_source.subscan_region.height * scan_context.size.height
                width_str = calibration.convert_to_calibrated_size_str(width, value_range=(0, scan_context.size.width), samples=scan_context.size.width)
                height_str = calibration.convert_to_calibrated_size_str(height, value_range=(0, scan_context.size.height), samples=scan_context.size.height)
                rect_str = _("Subscan")
                self.__roi_description.text = f"{rect_str} {width_str} x {height_str} ({int(width)} px x {int(height)} px)"
                scan_str = _("Scan (2D)")
                scan_width = self.__scan_width
                scan_height = int(self.__scan_width * height / width)
                drift_lines = scan_hardware_source.calculate_drift_lines(scan_width, self.__exposure_time_ms_value_model.value / 1000) if scan_hardware_source else 0
                drift_str = f" / Drift {drift_lines} lines" if drift_lines > 0 else str()
                self.__scan_label_widget.text = f"{scan_str} {scan_width} x {scan_height} px" + drift_str
                self.__scan_pixels = scan_width * scan_height
                self.__scan_specifier.scan_context = copy.deepcopy(scan_context)
                self.__scan_specifier.size = scan_height, scan_width
                self.__scan_specifier.drift_interval_lines = drift_lines
                self.__acquire_button._widget.enabled = True
            elif scan_context.is_valid:
                calibration = scan_context.calibration
                width = scan_context.size.width
                height = scan_context.size.height
                width_str = calibration.convert_to_calibrated_size_str(width, value_range=(0, scan_context.size.width), samples=scan_context.size.width)
                height_str = calibration.convert_to_calibrated_size_str(height, value_range=(0, scan_context.size.height), samples=scan_context.size.height)
                data_str = _("Context Scan")
                self.__roi_description.text = f"{data_str} {width_str} x {height_str} ({int(width)} x {int(height)})"
                scan_str = _("Scan (2D)")
                scan_width = self.__scan_width
                scan_height = int(self.__scan_width * height / width)
                drift_lines = scan_hardware_source.calculate_drift_lines(scan_width, self.__exposure_time_ms_value_model.value / 1000) if scan_hardware_source else 0
                drift_str = f" / Drift {drift_lines} lines" if drift_lines > 0 else str()
                self.__scan_label_widget.text = f"{scan_str} {scan_width} x {scan_height} px" + drift_str
                self.__scan_pixels = scan_width * scan_height
                self.__scan_specifier.scan_context = copy.deepcopy(scan_context)
                self.__scan_specifier.size = scan_height, scan_width
                self.__scan_specifier.drift_interval_lines = drift_lines
                self.__acquire_button._widget.enabled = True
            else:
                self.__roi_description.text = _("Scan context not active")
                self.__scan_label_widget.text = None
                self.__scan_specifier.scan_context = stem_controller.ScanContext()
                self.__scan_specifier.size = None
                self.__scan_specifier.drift_interval_lines = 0
                self.__acquire_button._widget.enabled = self.__acquisition_state == SequenceState.scanning  # focus will be on the SI data, so enable if scanning
                self.__scan_pixels = 0

            self.__scan_width_widget.text = Converter.IntegerToStringConverter().convert(self.__scan_width)

            self.__update_estimate()