194-fitrange #219

Merged
dominik merged 7 commits from 194-fitrange into master 2024-01-18 18:25:07 +00:00
2 changed files with 27 additions and 9 deletions
Showing only changes of commit 9068ec2b83 - Show all commits

View File

@ -51,13 +51,14 @@ class FitToolbar(QtWidgets.QToolBar):
self.limit_group.triggered.connect(self.change_limit_type) self.limit_group.triggered.connect(self.change_limit_type)
self.region.sigRegionChanged.connect(self.change_labels) self.region.sigRegionChanged.connect(self.change_labels)
self.change_labels()
self.lineedit.textChanged.connect(self.move_region) self.lineedit.textChanged.connect(self.move_region)
self.lineedit2.textChanged.connect(self.move_region) self.lineedit2.textChanged.connect(self.move_region)
@QtCore.pyqtSlot(QtWidgets.QAction) @QtCore.pyqtSlot(QtWidgets.QAction)
def change_limit_type(self, action: QtWidgets.QAction): def change_limit_type(self, action: QtWidgets.QAction):
is_custom = action.text() == 'Custom' is_custom = (action.text() == 'Custom')
for w in [self.label, self.label2, self.lineedit, self.lineedit2]: for w in [self.label, self.label2, self.lineedit, self.lineedit2]:
w.setEnabled(is_custom) w.setEnabled(is_custom)
@ -73,6 +74,24 @@ class FitToolbar(QtWidgets.QToolBar):
self.lineedit2.blockSignals(False) self.lineedit2.blockSignals(False)
def move_region(self): def move_region(self):
r_min = self.lineedit.text() try:
r_max = self.lineedit2.text() r_min = float(self.lineedit.text())
self.region.setRegion((float(r_min), float(r_max)), use_log=True) except ValueError:
r_min = None
try:
r_max = float(self.lineedit2.text())
except ValueError:
r_max = None
if r_min is not None and r_max is not None:
self.region.setRegion((r_min, r_max), use_log=True)
def get_limit(self):
action_text = self.limit_group.checkedAction().text()
return {
'None': 'none',
'Visible x range': 'x',
'Custom': self.region.getRegion(),
}[action_text]

View File

@ -904,17 +904,16 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
@QtCore.pyqtSlot(QtWidgets.QAction) @QtCore.pyqtSlot(QtWidgets.QAction)
def change_fit_limits(self, action: QtWidgets.QAction): def change_fit_limits(self, action: QtWidgets.QAction):
if self.current_graph_widget is None:
return
if action == self.action_custom_range and self.fit_dialog.isVisible(): if action == self.action_custom_range and self.fit_dialog.isVisible():
self.current_graph_widget.add_external(self.fitregion) self.current_graph_widget.add_external(self.fitregion)
else: else:
self.current_graph_widget.remove_external(self.fitregion) self.current_graph_widget.remove_external(self.fitregion)
def start_fit(self, parameter, links, fit_options): def start_fit(self, parameter, links, fit_options):
fit_options['limits'] = { fit_options['limits'] = self.fit_toolbar.get_limit()
self.action_no_range: 'none',
self.action_x_range: 'x',
self.action_custom_range: self.fitregion.getRegion()
}[self.ac_group2.checkedAction()]
fit_options['fit_mode'] = { fit_options['fit_mode'] = {
self.action_lm_fit: 'lsq', self.action_lm_fit: 'lsq',