Skip to content

Commit

Permalink
Merge pull request #12 from PyMoDAQ/feature/viewer2d_opposite
Browse files Browse the repository at this point in the history
add the opposite button and handle transform with numpy compat
  • Loading branch information
seb5g authored Nov 15, 2024
2 parents a1249a9 + d063dc7 commit afe3494
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/pymodaq_gui/parameter/pymodaq_ptypes/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/pymodaq_gui/plotting/data_viewers/viewer2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit afe3494

Please sign in to comment.