BUGFIX: VFT;

change to src layout
This commit is contained in:
dominik
2022-10-20 17:23:15 +02:00
parent 89ce4bab9f
commit 8d148b639b
445 changed files with 1387 additions and 1920 deletions

View File

View File

@ -0,0 +1,3 @@
from numpy import random

View File

@ -0,0 +1,101 @@
from ..Qt import QtCore, QtWidgets, QtGui
from .._py.eval_expr_dialog import Ui_CalcDialog
class QEvalDialog(QtWidgets.QDialog, Ui_CalcDialog):
do_eval = QtCore.pyqtSignal(list, list, bool)
do_calc = QtCore.pyqtSignal(list, dict)
def __init__(self, mode='c', parent=None):
super().__init__(parent=parent)
self.setupUi(self)
self.namespace = None
self.success = True
self.set_mode(mode)
self.value_lineEdit.setValidator(QtGui.QDoubleValidator())
def set_mode(self, mode: str):
if mode not in ['c', 'e']:
raise ValueError(f'Mode should be "c" or "e", {mode} given')
if mode == 'c':
self.stackedWidget.setCurrentIndex(1)
else:
self.stackedWidget.setCurrentIndex(0)
self.mode = mode
def set_namespace(self, namespace):
self.namespace = namespace
self.namespace_widget.set_namespace(self.namespace)
def add_data(self, data):
self.listWidget.clear()
for set_id, name in data:
item = QtWidgets.QListWidgetItem(name)
item.setData(QtCore.Qt.UserRole, set_id)
item.setFlags(item.flags() ^ QtCore.Qt.ItemIsEditable)
item.setCheckState(QtCore.Qt.Checked)
self.listWidget.addItem(item)
def set_graphs(self, graphs: list):
self.graph_comboBox.clear()
self.graph_comboBox.addItem('New graph', userData='')
for g_id, g_name in graphs:
self.graph_comboBox.addItem(g_name, userData=g_id)
@QtCore.pyqtSlot(str, name='on_namespace_widget_selected')
def add_to_equation(self, string: str):
self.calc_edit.insertPlainText(string + ' ')
def on_buttonBox_clicked(self, bttn):
bttn_role = self.buttonBox.buttonRole(bttn)
if bttn_role == QtWidgets.QDialogButtonBox.ApplyRole:
self.collect_args()
elif bttn_role == QtWidgets.QDialogButtonBox.AcceptRole:
self.collect_args()
if self.success:
self.accept()
else:
self.reject()
def collect_args(self):
cmds = self.calc_edit.toPlainText().strip().split('\n')
if cmds[-1] == '':
# remove last empty line to check
cmds.pop()
if cmds:
if self.mode == 'e':
set_id = []
for i in range(self.listWidget.count()):
item = self.listWidget.item(i)
if item.checkState() == QtCore.Qt.Checked:
set_id.append(item.data(QtCore.Qt.UserRole))
self.do_eval.emit(cmds, set_id, self.overwrite_checkbox.isChecked())
elif self.mode == 'c':
opts = {
'symbol': self.symbol_comboBox.value,
'symbolcolor': self.symcolor_comboBox.value,
'symbolsize': self.symbol_spinBox.value(),
'linestyle': self.linestyle_comboBox.value,
'linecolor': self.linecolor_comboBox.value,
'linewidth': self.line_doubleSpinBox.value(),
'graph': self.graph_comboBox.currentData(),
'dtype': self.dtype_comboBox.currentIndex(),
'name': self.label_lineEdit.text(),
'val': self.value_lineEdit.text()
}
self.do_calc.emit(cmds, opts)
else:
# keine Ahnung, warum man hier landen sollte ...
self.success = False

View File

@ -0,0 +1,81 @@
from ..Qt import QtWidgets, QtCore, QtGui
from .._py.integratederive_dialog import Ui_Dialog
class QDeriveIntegrate(QtWidgets.QDialog, Ui_Dialog):
newValues = QtCore.pyqtSignal(int, dict)
def __init__(self, mode: str, parent=None):
super().__init__(parent=parent)
self.setupUi(self)
self.mode = mode.lower()[0]
if self.mode == 'i':
self.setWindowTitle('Integration dialog')
self.start_lineedit.setValidator(QtGui.QDoubleValidator())
self.stop_lineedit.setValidator(QtGui.QDoubleValidator())
self.ft_comboBox.hide()
elif self.mode == 'd':
self.setWindowTitle('Differentiation dialog')
self.widget.hide()
self.ft_comboBox.hide()
elif self.mode == 'l':
self.setWindowTitle('Logarithmic FT dialog')
self.log_checkbox.hide()
self.widget.hide()
else:
raise ValueError(f'Unknown mode {mode}, use "d", "i", or "l".')
def add_graphs(self, graphs: list):
self.graph_combobox.clear()
for (graph_id, graph_name) in graphs:
self.graph_combobox.addItem(graph_name, userData=graph_id)
def set_sets(self, sets: list):
self.listWidget.clear()
for (set_id, set_name) in sets:
item = QtWidgets.QListWidgetItem(set_name)
item.setData(QtCore.Qt.UserRole, set_id)
item.setCheckState(QtCore.Qt.Checked)
self.listWidget.addItem(item)
@QtCore.pyqtSlot(int, name='on_checkBox_2_stateChanged')
def enable_graph(self, state: int):
self.graph_combobox.setEnabled(state != QtCore.Qt.Checked)
def get_options(self):
opts = {'graph': '' if self.newgraph_checkbox.isChecked() else self.graph_combobox.currentData(),
'mode': self.mode, 'sets': []}
if self.mode == 'i':
start = None
stop = None
if not self.range_checkbox.isChecked():
start = self.start_lineedit.text()
stop = self.stop_lineedit.text()
if start:
start = float(start)
if stop:
stop = float(stop)
opts['limits'] = (start, stop)
if self.mode == 'l':
opts['ft_mode'] = ['cos', 'sin', 'complex'][self.ft_comboBox.currentIndex()]
else:
opts['log'] = self.log_checkbox.isChecked()
for i in range(self.listWidget.count()):
item = self.listWidget.item(i)
if item.checkState() == QtCore.Qt.Checked:
opts['sets'].append(item.data(QtCore.Qt.UserRole))
return opts

View File

@ -0,0 +1,91 @@
from ..Qt import QtCore, QtWidgets, QtGui
from .._py.interpol_dialog import Ui_Dialog
class InterpolDialog(QtWidgets.QDialog, Ui_Dialog):
new_data = QtCore.pyqtSignal(list, str, bool, bool, tuple, str)
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setupUi(self)
self.src_widget.hide()
validator = QtGui.QDoubleValidator()
self.start_lineEdit.setValidator(validator)
self.stop_lineEdit.setValidator(validator)
self.step_lineEdit.setValidator(QtGui.QIntValidator())
self._data = {}
@QtCore.pyqtSlot(int, name='on_xaxis_comboBox_currentIndexChanged')
def change_x_source(self, idx: int):
self.src_widget.setVisible(idx == 1)
self.sampling_widget.setVisible(idx != 1)
def set_data(self, data, current_gid):
self.graph_combobox.blockSignals(True)
self._data = {}
for (gid, graph_name), sets in data.items():
self.graph_combobox.addItem(graph_name, userData=gid)
self.dest_combobox.addItem(graph_name, userData=gid)
if gid == current_gid:
self.make_list(sets)
self._data[gid] = sets
self.graph_combobox.blockSignals(False)
self.change_graph(0)
def make_list(self, current_sets):
for sid, set_name in current_sets:
item = QtWidgets.QListWidgetItem(set_name)
item.setData(QtCore.Qt.UserRole, sid)
item.setCheckState(QtCore.Qt.Checked)
self.listWidget.addItem(item)
@QtCore.pyqtSlot(int, name='on_graph_combobox_currentIndexChanged')
def change_graph(self, idx: int):
self.set_combobox.clear()
gid = self.graph_combobox.itemData(idx, QtCore.Qt.UserRole)
if gid is not None:
for set_key, set_name in self._data[gid]:
self.set_combobox.addItem(set_name, userData=set_key)
def collect_parameter(self):
xlog = self.xlog_checkBox.isChecked()
ylog = self.ylog_checkBox.isChecked()
mode = self.interp_comboBox.currentText().lower()
if self.xaxis_comboBox.currentIndex() == 0:
try:
start = float(self.start_lineEdit.text())
stop = float(self.stop_lineEdit.text())
step = int(self.step_lineEdit.text())
except ValueError:
QtWidgets.QMessageBox.warning(self, 'Invalid axis', 'Values for axis are invalid or missing.')
return False
loggy = self.logspace_checkBox.isChecked()
if loggy and ((start <= 0) or (stop <= 0)):
QtWidgets.QMessageBox.warning(self, 'Invalid axis', 'Logarithmic axis cannot contain negative values.')
return False
x_src = (start, stop, step, loggy)
else:
x_src = (self.set_combobox.currentData(QtCore.Qt.UserRole),)
dest_graph = self.dest_combobox.currentData(QtCore.Qt.UserRole)
use_data = []
for i in range(self.listWidget.count()):
item = self.listWidget.item(i)
if item.checkState() == QtCore.Qt.Checked:
use_data.append(item.data(QtCore.Qt.UserRole))
self.new_data.emit(use_data, mode, xlog, ylog, x_src, dest_graph)
return True
def accept(self):
success = self.collect_parameter()
if success:
super().accept()

View File

@ -0,0 +1,113 @@
from nmreval.distributions import ColeDavidson, HavriliakNegami, KWW, LogGaussian
from ..Qt import QtWidgets, QtCore
from .._py.meandialog import Ui_calc_means_dialog
from ..lib.forms import Widget
class QMeanTimes(QtWidgets.QDialog, Ui_calc_means_dialog):
newValues = QtCore.pyqtSignal(tuple, dict, str)
def __init__(self, tree: dict, parent=None):
super().__init__(parent=parent)
self.setupUi(self)
self._tree = tree
self.distributions = [ColeDavidson, HavriliakNegami, KWW, LogGaussian]
for s in self.distributions:
self.dist_combobox.addItem(s.name)
self.update_graphs(self._tree)
self.change_distribution(0)
self.dist_combobox.currentIndexChanged.connect(self.change_distribution)
self.from_combobox.currentIndexChanged.connect(lambda idx: self.calculate_means())
self.to_combobox.currentIndexChanged.connect(lambda idx: self.calculate_means())
def update_graphs(self, graph: dict):
graph_id = self.graph_combobox.currentData(QtCore.Qt.UserRole)
self.graph_combobox.clear()
for key, (name, _) in graph.items():
self.graph_combobox.addItem(name, userData=key)
if graph_id is not None:
self.graph_combobox.setCurrentIndex(self.graph_combobox.findData(graph_id, QtCore.Qt.UserRole))
else:
self.graph_combobox.setCurrentIndex(0)
@QtCore.pyqtSlot(int)
def change_distribution(self, idx):
dist = self.distributions[idx]
while self.verticalLayout.count():
item = self.verticalLayout.takeAt(0)
item.widget().deleteLater()
for i, p in enumerate([r'\tau'] + dist.parameter):
w = Widget(p, self._tree, collapsing=True, parent=self)
w.valueChanged.connect(lambda: self.calculate_means())
self.verticalLayout.addWidget(w)
self.calculate_means()
def calculate_means(self):
parameter = []
for i in range(self.verticalLayout.count()):
w = self.verticalLayout.itemAt(i).widget()
try:
parameter.append(float(w.lineEdit.text()))
except ValueError:
parameter = None
break
if parameter is not None:
dist, direction = self.get_conversions()
self.label.setText(f'{self.to_combobox.currentText()}: '
f'{dist.convert(*parameter, **direction):.8g}')
@QtCore.pyqtSlot()
def get_parameter(self):
parameter = []
for i in range(self.verticalLayout.count()):
w = self.verticalLayout.itemAt(i).widget()
p = w.value
if p is not None:
parameter.append(p)
else:
QtWidgets.QMessageBox.warning(self, 'Invalid input',
f'Invalid input for parameter {w.label.text()}')
return
dist, direction = self.get_conversions()
graph_destination = ''
if not self.checkBox.isChecked():
graph_destination = self.graph_combobox.currentData()
self.newValues.emit((dist, parameter), direction, graph_destination)
def get_conversions(self):
mode = ['raw', 'peak', 'mean', 'logmean']
mode_to = mode[self.to_combobox.currentIndex()]
mode_from = mode[self.from_combobox.currentIndex()]
dist = self.distributions[self.dist_combobox.currentIndex()]
return dist, {'from_': mode_from, 'to_': mode_to}
@QtCore.pyqtSlot(QtWidgets.QAbstractButton, name='on_buttonBox_clicked')
def button_clicked(self, bttn: QtWidgets.QAbstractButton):
role = self.buttonBox.buttonRole(bttn)
if role == QtWidgets.QDialogButtonBox.RejectRole:
self.close()
elif role == QtWidgets.QDialogButtonBox.AcceptRole:
self.get_parameter()
self.close()
elif role == QtWidgets.QDialogButtonBox.ApplyRole:
self.get_parameter()
else:
print('Unknown role')

View File

@ -0,0 +1,19 @@
from ..Qt import QtWidgets
from .._py.skipdialog import Ui_SkipDialog
class QSkipDialog(QtWidgets.QDialog, Ui_SkipDialog):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setupUi(self)
def on_spinBox_valueChanged(self, val: int):
self.offset_spinbox.setMaximum(int(val)-1)
def get_arguments(self):
return {
'offset': int(self.offset_spinbox.value()),
'step': int(self.step_spinbox.value()),
'copy': self.delete_button.isChecked(),
'invert': self.invert_check.isChecked()
}

47
src/gui_qt/math/smooth.py Normal file
View File

@ -0,0 +1,47 @@
from ..Qt import QtWidgets, QtCore
from .._py.smoothdialog import Ui_SmoothDialog
class QSmooth(QtWidgets.QDialog, Ui_SmoothDialog):
newValues = QtCore.pyqtSignal(int, dict)
def __init__(self, parent=None):
super().__init__(parent=parent)
self.setupUi(self)
self.on_comboBox_currentIndexChanged(0)
@QtCore.pyqtSlot(int, name='on_comboBox_currentIndexChanged')
def change_mode(self, idx: int):
if idx == 2:
self.widget.show()
self.widget_2.hide()
elif idx == 3:
self.widget.show()
self.widget_2.show()
else:
self.widget.hide()
self.widget_2.hide()
def accept(self):
para = {'logx': self.x_checkBox.isChecked(),
'logy': self.y_checkBox.isChecked()}
npoints = self.frac_spinBox.value()
idx = self.comboBox.currentIndex()
# this order must match the combobox
para['mode'] = ['mean', 'savgol', 'loess', 'median', 'std', 'var', 'max', 'min', 'sum'][idx]
if idx == 2:
para['deg'] = self.polynom_spinBox.value()
if idx == 3:
para['deg'] = self.polynom_spinBox.value()
para['it'] = self.iter_spinBox.value()
self.newValues.emit(npoints, para)
super().accept()
def close(self):
self.disconnect()
super().close()