From 3149a3f9589e36801e42dd0f76df254abfe5b8d9 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 17 Jul 2023 19:19:38 +0200 Subject: [PATCH] setRegion of RegionItem with option to account for log mode --- src/gui_qt/data/point_select.py | 2 +- src/gui_qt/lib/pg_objects.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gui_qt/data/point_select.py b/src/gui_qt/data/point_select.py index 9abfc4f..514ba49 100644 --- a/src/gui_qt/data/point_select.py +++ b/src/gui_qt/data/point_select.py @@ -177,7 +177,7 @@ class PointSelectWidget(QtWidgets.QWidget, Ui_Form): it.setText(f'{pos[0]:.5g} - {pos[1]:.5g}') self.peaktable.blockSignals(False) it_pts.blockSignals(True) - it_pts.setRegion(pos) + it_pts.setRegion(pos, use_log=True) it_pts.blockSignals(False) undo = False diff --git a/src/gui_qt/lib/pg_objects.py b/src/gui_qt/lib/pg_objects.py index f81e28a..9978031 100644 --- a/src/gui_qt/lib/pg_objects.py +++ b/src/gui_qt/lib/pg_objects.py @@ -376,6 +376,8 @@ class RegionItem(LinearRegionItem): def __init__(self, *args, **kwargs): self.mode = kwargs.pop('mode', 'half') + print(args, kwargs) + super().__init__(*args, **kwargs) self.logmode = False @@ -422,6 +424,15 @@ class RegionItem(LinearRegionItem): else: return region + def setRegion(self, region, use_log=False): + if self.logmode and use_log: + region = np.log10(region[0]), np.log10(region[1]) + + if not np.all(np.isfinite(region)): + raise ValueError(f'Invalid region limits ({region[0]}, {region[1]})') + else: + super().setRegion(region) + def boundingRect(self): # overwrite to draw correct rect in logmode