From c508965a289a38b852e1178050e720f1819a413a Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 18 Jan 2024 18:57:56 +0100 Subject: [PATCH] move widget of global parameter --- src/gui_qt/fit/fit_parameter.py | 47 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/gui_qt/fit/fit_parameter.py b/src/gui_qt/fit/fit_parameter.py index 7fd58e7..e470691 100644 --- a/src/gui_qt/fit/fit_parameter.py +++ b/src/gui_qt/fit/fit_parameter.py @@ -62,7 +62,7 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit): self.glob_values = [1] * len(func.params) for k, v in enumerate(func.params): - widgt = ParameterGlobalWidget(label=v, parent=self.scrollwidget) + widgt = ParameterGlobalWidget(name=v, parent=self.scrollwidget) widgt.parameter_pos = k widgt.func_idx = idx try: @@ -290,36 +290,57 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit): return param_len -class ParameterSingleWidget(QtWidgets.QWidget, Ui_FitParameter): +class ParameterSingleWidget(QtWidgets.QWidget): valueChanged = QtCore.pyqtSignal(object) removeSingleValue = QtCore.pyqtSignal() def __init__(self, name: str, parent=None): super().__init__(parent=parent) - self.setupUi(self) + + self._init_ui() self.name = name self.parametername.setText(convert(name)) self.parametername.setToolTip('If this is bold then this parameter is only for this data. ' - 'Otherwise, the general parameter is used and displayed') + 'Otherwise, the general parameter is used and displayed') - self.parameter_line.textChanged.connect(lambda: self.valueChanged.emit(self.value) if self.value is not None else 0) + # self.value_line.setValidator(QtGui.QDoubleValidator()) + self.value_line.textChanged.connect(lambda: self.valueChanged.emit(self.value) if self.value is not None else 0) self.reset_button.clicked.connect(lambda x: self.removeSingleValue.emit()) - self.global_checkbox.setVisible(False) + def _init_ui(self): + layout = QtWidgets.QHBoxLayout(self) + layout.setContentsMargins(2, 2, 2, 2) + layout.setSpacing(2) + + self.parametername = QtWidgets.QLabel(self) + layout.addWidget(self.parametername) + + layout.addSpacerItem(QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)) + + self.value_line = QtWidgets.QLineEdit(self) + self.value_line.textEdited.connect(lambda x: self.show_as_local_parameter(True)) + layout.addWidget(self.value_line) + + self.reset_button = QtWidgets.QToolButton(self) + self.reset_button.setText('Use global') + self.reset_button.clicked.connect(lambda: self.show_as_local_parameter(False)) + layout.addWidget(self.reset_button) + + self.setLayout(layout) @property def value(self) -> float: try: - return float(self.parameter_line.text().replace(',', '.')) + return float(self.value_line.text().replace(',', '.')) except ValueError: return 0.0 @value.setter def value(self, val): # self.value_line.setText(f'{float(val):.5g}') - self.parameter_line.setText(f'{val}') - self.parameter_line.setCursorPosition(0) + self.value_line.setText(f'{val}') + self.value_line.setCursorPosition(0) def show_as_local_parameter(self, is_local: bool): if is_local: @@ -338,21 +359,21 @@ class ParameterGlobalWidget(QtWidgets.QWidget, Ui_FitParameter): state_changed = QtCore.pyqtSignal() replace_single_value = QtCore.pyqtSignal(object) - def __init__(self, label: str = 'Fitparameter', parent=None, fixed: bool = False): + def __init__(self, name: str = 'Fitparameter', parent=None, fixed: bool = False): super().__init__(parent) self.setupUi(self) - self.name = label + self.name = name self.reset_button.setVisible(False) - self.parametername.setText(convert(label) + ' ') + self.parametername.setText(convert(name) + ' ') self.parameter_line.setText('1') self.parameter_line.setMaximumWidth(160) self.lineEdit.setMaximumWidth(100) self.lineEdit_2.setMaximumWidth(100) - self.label_3.setText(f'< {convert(label)} <') + self.label_3.setText(f'< {convert(name)} <') self.checkBox.stateChanged.connect(self.enableBounds) self.global_checkbox.stateChanged.connect(lambda: self.state_changed.emit())