From 10bec43effcb4dae204d1850da60bc1b0dbb8e3e Mon Sep 17 00:00:00 2001 From: Tiomat85 Date: Wed, 19 Jun 2024 16:48:07 +0100 Subject: [PATCH] Update ImageCanvasItem.py Fixed some more type errors. --- nion/swift/ImageCanvasItem.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nion/swift/ImageCanvasItem.py b/nion/swift/ImageCanvasItem.py index 5ef9b3855..5f25dc751 100644 --- a/nion/swift/ImageCanvasItem.py +++ b/nion/swift/ImageCanvasItem.py @@ -1143,18 +1143,19 @@ def convert_pixel_to_normalised(self, coord: Geometry.IntPoint) -> Geometry.Floa list()) if widget_mapping: mapped = self.map_widget_to_image(coord) - norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(mapped, self.__data_shape)) + norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(mapped), iter(self.__data_shape))) return Geometry.FloatPoint(norm_coord[0], norm_coord[1]) # y,x + return Geometry.FloatPoint(-1, -1) #Apply a zoom factor to the widget, optionally focussed on a specific point - def _apply_fixed_zoom(self, zoom_in: bool, coord: Geometry.IntPoint = None) -> None: + def _apply_fixed_zoom(self, zoom_in: bool, coord: typing.Optional[Geometry.IntPoint]) -> None: if coord: # Coordinate specified, so needing to recenter to that point before we adjust zoom levels widget_mapping = ImageCanvasItemMapping.make(self.__data_shape, self.__composite_canvas_item.canvas_bounds, list()) if widget_mapping: mapped = self.map_widget_to_image(coord) - norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(mapped, self.__data_shape)) - self._set_image_canvas_position(norm_coord) + norm_coord = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(mapped), iter(self.__data_shape))) + self._set_image_canvas_position(Geometry.FloatPoint(norm_coord[0], norm_coord[1])) # ensure that at least half of the image is always visible new_image_norm_center_0 = max(min(norm_coord[0], 1.0), 0.0) @@ -1175,15 +1176,15 @@ def _apply_selection_zoom(self, coord1: Geometry.IntPoint, coord2: Geometry.IntP if widget_mapping: coord1_mapped = self.map_widget_to_image(coord1) coord2_mapped = self.map_widget_to_image(coord2) - norm_coord1 = tuple(ele1 / ele2 for ele1, ele2 in zip(coord1_mapped, self.__data_shape)) - norm_coord2 = tuple(ele1 / ele2 for ele1, ele2 in zip(coord2_mapped, self.__data_shape)) + norm_coord1 = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(coord1_mapped), iter(self.__data_shape))) + norm_coord2 = tuple(ele1 / ele2 for ele1, ele2 in zip(iter(coord2_mapped), iter(self.__data_shape))) - norm_coord = tuple((ele1 + ele2)/2 for ele1, ele2 in zip(norm_coord1, norm_coord2)) - self._set_image_canvas_position(norm_coord) + norm_coord = tuple((ele1 + ele2)/2 for ele1, ele2 in zip(iter(norm_coord1), iter(norm_coord2))) + self._set_image_canvas_position(Geometry.FloatPoint(norm_coord[0], norm_coord[1])) # image now centered on middle of selection, need to calculate new zoom level required # selection size in widget pixels selection_size_screen_space = tuple( - abs(ele1 - ele2) for ele1, ele2 in zip(coord1, coord2)) # y,x + abs(ele1 - ele2) for ele1, ele2 in zip(iter(coord1), iter(coord2))) # y,x widget_width = self.__composite_canvas_item.canvas_bounds.width / self.__image_zoom widget_height = self.__composite_canvas_item.canvas_bounds.height / self.__image_zoom widget_width_factor = widget_width / selection_size_screen_space[1]