From d063dc7fc73a11ac4874f00ec31f35655db5ce5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Weber?= Date: Fri, 15 Nov 2024 13:36:49 +0100 Subject: [PATCH] add the opposite button and handle transform with numpy compat --- .../parameter/pymodaq_ptypes/__init__.py | 4 ++-- .../plotting/data_viewers/viewer2D.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/pymodaq_gui/parameter/pymodaq_ptypes/__init__.py b/src/pymodaq_gui/parameter/pymodaq_ptypes/__init__.py index d5dbdaf2..1b5fe303 100644 --- a/src/pymodaq_gui/parameter/pymodaq_ptypes/__init__.py +++ b/src/pymodaq_gui/parameter/pymodaq_ptypes/__init__.py @@ -1,5 +1,5 @@ -from pyqtgraph.parametertree.parameterTypes.basetypes import (SimpleParameter, GroupParameter, - GroupParameterItem) +from pyqtgraph.parametertree.parameterTypes.basetypes import ( + SimpleParameter, GroupParameter, GroupParameterItem) # to be imported from elsewhere from .bool import BoolPushParameter from .pixmap import PixmapParameter, PixmapCheckParameter from .slide import SliderSpinBox, SliderParameter diff --git a/src/pymodaq_gui/plotting/data_viewers/viewer2D.py b/src/pymodaq_gui/plotting/data_viewers/viewer2D.py index cf439b64..d20ac2f2 100644 --- a/src/pymodaq_gui/plotting/data_viewers/viewer2D.py +++ b/src/pymodaq_gui/plotting/data_viewers/viewer2D.py @@ -465,6 +465,8 @@ def setup_actions(self): tip='Flip the image left/right', checkable=True) self.add_action('rotate', 'Rotate', 'rotation2', tip='Rotate the image', checkable=True) + self.add_action('opposite', 'Opposite', 'remove', + tip='Take the opposite of the image', checkable=True) self.add_action('legend', 'Legend', 'RGB', tip='Show the legend', checkable=True) @@ -866,18 +868,19 @@ def set_image_transform(self) -> DataRaw: self.view.set_action_visible('flip_lr', data.distribution != 'spread') self.view.set_action_visible('rotate', data.distribution != 'spread') if data.distribution != 'spread': - for ind_data in range(len(data)): - data.data[ind_data] = self.transform_image(data.data[ind_data]) + data = self.transform_image(data) return data - def transform_image(self, data): + def transform_image(self, dwa: DataWithAxes): if self.view.is_action_checked('flip_ud'): - data = np.flipud(data) + dwa = np.flipud(dwa) if self.view.is_action_checked('flip_lr'): - data = np.fliplr(data) + dwa = np.fliplr(dwa) if self.view.is_action_checked('rotate'): - data = np.flipud(np.transpose(data)) - return data + dwa = np.flipud(np.transpose(dwa)) + if self.view.is_action_checked('opposite'): + dwa = -dwa + return dwa def set_visible_items(self): for key in IMAGE_TYPES: @@ -918,6 +921,7 @@ def prepare_connect_ui(self): self.view.connect_action('flip_lr', slot=self.update_data) self.view.connect_action('rotate', slot=self.update_data) self.view.connect_action('autolevels', slot=self.update_data) + self.view.connect_action('opposite', slot=self.update_data) self.view.connect_action('isocurve', slot=self.update_data) self.view.histogrammer.gradient_changed.connect(lambda: setattr(self, '_is_gradient_manually_set', True))