setRegion of RegionItem with option to account for log mode

This commit is contained in:
Dominik Demuth 2023-07-17 19:19:38 +02:00
parent 3321d85203
commit 3149a3f958
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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