interactive integration; new user-defined fit functions reloads model list; fixed requirements.txt

This commit is contained in:
dominik
2022-11-07 20:44:18 +01:00
parent 47f11a073c
commit a746afadff
17 changed files with 626 additions and 358 deletions

View File

@ -28,22 +28,9 @@ class QFunctionWidget(QtWidgets.QWidget, Ui_Form):
self.setupUi(self)
self._types = []
self.user_functions = {}
self.functions = find_models(models)
try:
self.functions += find_models(config_paths() / 'usermodels.py')
except FileNotFoundError:
pass
for m in self.functions:
try:
m.type
except AttributeError:
m.type = 'Other'
if m.type not in self._types:
self._types.append(m.type)
self.typecomboBox.addItems(sorted(self._types))
self.read_and_load_functions()
self.functree.treeChanged.connect(lambda: self.treeChanged.emit())
self.functree.itemRemoved.connect(self.remove_function)
@ -54,6 +41,44 @@ class QFunctionWidget(QtWidgets.QWidget, Ui_Form):
for i, op_icon in enumerate(self.op_names):
self.operator_combobox.setItemIcon(i, get_icon(op_icon))
def read_and_load_functions(self):
"""
Reads user-defined fit functions from usermodels.py and adds them to list of fit function.
Previous class definitions are replaced.
"""
user_defined = []
try:
user_defined = find_models(config_paths() / 'usermodels.py')
except FileNotFoundError:
pass
for model in user_defined:
name = model.__name__
if name not in self.user_functions:
self.functions.append(model)
self.user_functions[name] = model
else:
idx = self.functions.index(self.user_functions[name])
self.functions[idx] = model
self.user_functions[name] = model
self._types = []
for m in self.functions:
try:
m.type
except AttributeError:
m.type = 'Other'
if m.type not in self._types:
self._types.append(m.type)
self.typecomboBox.blockSignals(True)
self.typecomboBox.clear()
self.typecomboBox.addItems(sorted(self._types))
self.typecomboBox.blockSignals(False)
self.change_group(0)
def __len__(self) -> int:
num = 0
iterator = QtWidgets.QTreeWidgetItemIterator(self.functree)

View File

@ -61,6 +61,8 @@ class QFitDialog(QtWidgets.QWidget, Ui_FitDialog):
self.functionwidget.showFunction.connect(self.show_function_parameter)
self.functionwidget.itemRemoved.connect(self.remove_function)
self.read_and_load_functions = self.functionwidget.read_and_load_functions
@QtCore.pyqtSlot(int, int)
def add_function(self, function_idx: int, function_id: int):
self.show_function_parameter(function_id, function_idx)