tg dialog clean-up
This commit is contained in:
@ -1,31 +1,24 @@
|
||||
import pprint
|
||||
from itertools import cycle
|
||||
|
||||
from numpy import array, nan, isnan
|
||||
from pyqtgraph import mkPen, mkBrush, LegendItem
|
||||
from pyqtgraph import mkPen, mkBrush
|
||||
|
||||
from nmreval.dsc.hodge import tau_hodge
|
||||
from nmreval.lib.colors import Tab10
|
||||
from ..Qt import QtWidgets, QtCore, QtGui
|
||||
from .._py.tnmh_dialog import Ui_Wizard
|
||||
from ..lib.listwidget import QListWidgetSelect
|
||||
from ..Qt import QtWidgets, QtCore
|
||||
from .._py.tnmh_dialog import Ui_DSCEvalDialog
|
||||
from ..lib.pg_objects import PlotItem, RegionItem
|
||||
|
||||
from nmreval.data import DSC, Points
|
||||
|
||||
|
||||
class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
class TgCalculator(QtWidgets.QWizard, Ui_DSCEvalDialog):
|
||||
newData = QtCore.pyqtSignal(dict, str)
|
||||
|
||||
def __init__(self, management, parent=None):
|
||||
super().__init__(parent=parent)
|
||||
|
||||
self.setupUi(self)
|
||||
self.listWidget = QListWidgetSelect(parent=self)
|
||||
self.listWidget.setSelectionMode(self.listWidget.ExtendedSelection)
|
||||
self.listWidget.itemChanged.connect(self.change_visibility)
|
||||
self.setSideWidget(self.listWidget)
|
||||
self.listWidget.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
|
||||
|
||||
self._management = management
|
||||
self._colors = cycle(Tab10)
|
||||
@ -87,8 +80,11 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
|
||||
self.add_sets()
|
||||
|
||||
self.new_graph_tau_check.stateChanged.connect(lambda state: self.new_graph_tau_combo.setEnabled(not bool(state)))
|
||||
self.new_graph_tau_check.stateChanged.connect(lambda state: self.new_graph_tnmh_combo_2.setEnabled(not bool(state)))
|
||||
self.tnmh_graph_check.stateChanged.connect(lambda state: self.tnmh_graph_combo.setEnabled(not bool(state)))
|
||||
self.hodge_graph_check.stateChanged.connect(lambda state: self.hodge_graph_combo.setEnabled(not bool(state)))
|
||||
|
||||
self.next_button.clicked.connect(lambda: self.stackedWidget.setCurrentIndex((self.stackedWidget.currentIndex() + 1) % 3))
|
||||
self.back_button.clicked.connect(lambda: self.stackedWidget.setCurrentIndex((self.stackedWidget.currentIndex() + 2) % 3))
|
||||
|
||||
def __call__(self):
|
||||
self.clear()
|
||||
@ -99,9 +95,13 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
|
||||
def clear(self):
|
||||
self.listWidget.clear()
|
||||
self.tg_tree.clear()
|
||||
self.tnmh_tree.clear()
|
||||
|
||||
for plots in self._plots.values():
|
||||
for val in plots:
|
||||
self.dsc_plot.removeItem(val)
|
||||
self.tnmh_graphics.removeItem(val)
|
||||
|
||||
for key, plt in self._hodge.items():
|
||||
plt[0].setData(x=[], y=[])
|
||||
@ -115,11 +115,13 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
self._lines = {}
|
||||
self._fit = {}
|
||||
|
||||
self.stackedWidget.setCurrentIndex(0)
|
||||
|
||||
def add_sets(self):
|
||||
self.new_graph_tau_combo.clear()
|
||||
for graphs in self._management.graphs.list():
|
||||
self.new_graph_tau_combo.addItem(graphs[1], userData=graphs[0])
|
||||
self.new_graph_tnmh_combo_2.addItem(graphs[1], userData=graphs[0])
|
||||
for w in (self.tnmh_graph_combo, self.hodge_graph_combo):
|
||||
w.clear()
|
||||
for graphs in self._management.graphs.list():
|
||||
w.addItem(graphs[1], userData=graphs[0])
|
||||
|
||||
min_x = 10_000_000
|
||||
max_x = -10_000_000
|
||||
@ -158,11 +160,11 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
self.dsc_plot.addItem(tg_plot)
|
||||
|
||||
fictive_cp = PlotItem(pen=mkPen(c.rgb()))
|
||||
self.graphicsView_3.addItem(fictive_cp)
|
||||
self.tnmh_graphics.addItem(fictive_cp)
|
||||
|
||||
tnmh_fit = PlotItem()
|
||||
tnmh_fit.set_line(style=2, color=c)
|
||||
self.graphicsView_3.addItem(tnmh_fit)
|
||||
self.tnmh_graphics.addItem(tnmh_fit)
|
||||
|
||||
self._plots[key] = (data_plot, tg_plot, glass, liquid, tangent, fictive_cp, tnmh_fit)
|
||||
self._tg_value[key] = {
|
||||
@ -173,7 +175,7 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
# 'fictive': (nan, nan),
|
||||
}
|
||||
|
||||
if self._limitless:
|
||||
if self._limitless and max_x != -10000000 and min_x != 10000000 :
|
||||
dist = max_x - min_x
|
||||
self.limits[0].setRegion((min_x, min_x+min(0.1*dist, 5)))
|
||||
self.limits[1].setRegion((max_x-min(5, 0.1*dist), max_x))
|
||||
@ -205,7 +207,7 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
self._update_tg_plots()
|
||||
|
||||
def _update_tg_plots(self):
|
||||
self.treeWidget.clear()
|
||||
self.tg_tree.clear()
|
||||
for idx in range(self.listWidget.count()):
|
||||
item = self.listWidget.item(idx)
|
||||
|
||||
@ -217,7 +219,7 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
child_item = QtWidgets.QTreeWidgetItem([f'{name.capitalize()}: {pos[0]:.2f} K'])
|
||||
tree_item.addChild(child_item)
|
||||
|
||||
self.treeWidget.addTopLevelItem(tree_item)
|
||||
self.tg_tree.addTopLevelItem(tree_item)
|
||||
|
||||
key = item.data(QtCore.Qt.UserRole)
|
||||
plot = self._plots[key]
|
||||
@ -225,7 +227,7 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
|
||||
plot[1].setData(array(list(self._tg_value[key].values())))
|
||||
|
||||
@QtCore.pyqtSlot(name='on_pushButton_clicked')
|
||||
@QtCore.pyqtSlot(name='on_tg_export_button_clicked')
|
||||
def export_tg(self):
|
||||
ret_dic = {}
|
||||
for key, tg in self._tg_value.items():
|
||||
@ -236,10 +238,9 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
else:
|
||||
tg_pts = None
|
||||
|
||||
line = []
|
||||
if self.tglines_export_check.isChecked():
|
||||
line = self._lines[key]
|
||||
else:
|
||||
line = []
|
||||
line = self._lines.get(key, [])
|
||||
|
||||
ret_dic[key] = (tg_pts, line)
|
||||
|
||||
@ -263,13 +264,13 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
|
||||
return cp
|
||||
|
||||
@QtCore.pyqtSlot(name='on_fit_tnhm_fitbutton_clicked')
|
||||
@QtCore.pyqtSlot(name='on_tnhm_fitbutton_clicked')
|
||||
def make_tnmh(self):
|
||||
baselines = tuple(lim.getRegion() for lim in self.limits)
|
||||
if baselines[0][0] > baselines[1][0]:
|
||||
baselines = baselines[1], baselines[0]
|
||||
|
||||
self.treeWidget_2.clear()
|
||||
self.tnmh_tree.clear()
|
||||
for idx in range(self.listWidget.count()):
|
||||
item = self.listWidget.item(idx)
|
||||
if item.checkState() == QtCore.Qt.Unchecked:
|
||||
@ -295,9 +296,9 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
child_item = QtWidgets.QTreeWidgetItem([values.parameter_string()])
|
||||
tree_item.addChild(child_item)
|
||||
|
||||
self.treeWidget_2.addTopLevelItem(tree_item)
|
||||
self.tnmh_tree.addTopLevelItem(tree_item)
|
||||
|
||||
@QtCore.pyqtSlot(name='on_pushButton_2_clicked')
|
||||
@QtCore.pyqtSlot(name='on_tnmh_export_button_clicked')
|
||||
def export_tnmh(self):
|
||||
ret_dic = {}
|
||||
for idx in range(self.listWidget.count()):
|
||||
@ -306,26 +307,23 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
continue
|
||||
|
||||
key = item.data(QtCore.Qt.UserRole)
|
||||
if self.checkBox_13.isChecked():
|
||||
_, cp = self._dsc[key]
|
||||
else:
|
||||
cp = None
|
||||
|
||||
if self.checkBox_14.isChecked():
|
||||
line = self._fit[key]
|
||||
else:
|
||||
line = None
|
||||
cp = None
|
||||
if self.fictive_export_check.isChecked():
|
||||
_, cp = self._dsc[key]
|
||||
|
||||
line = None
|
||||
|
||||
if self.tnmhfit_export_check.isChecked():
|
||||
line = self._fit.get(key)
|
||||
|
||||
ret_dic[key] = (cp, line)
|
||||
|
||||
if self.new_graph_tnmh_check_2.isChecked():
|
||||
ret_dic['graph'] = ''
|
||||
else:
|
||||
ret_dic['graph'] = self.new_graph_tnmh_combo_2.currentData()
|
||||
ret_dic['graph'] = '' if self.tnmh_graph_check.isChecked() else self.tnmh_graph_combo.currentData()
|
||||
|
||||
self.newData.emit(ret_dic, 'tnmh')
|
||||
|
||||
@QtCore.pyqtSlot(name='on_toolButton_clicked')
|
||||
@QtCore.pyqtSlot(name='on_hodge_button_clicked')
|
||||
def hodge(self):
|
||||
for tg_type, (plot, data, fitplots, fit) in self._hodge.items():
|
||||
|
||||
@ -355,27 +353,21 @@ class TgCalculator(QtWidgets.QWizard, Ui_Wizard):
|
||||
|
||||
self._hodge[tg_type] = (plot, data, fitplots, fit)
|
||||
|
||||
@QtCore.pyqtSlot(name='on_pushButton_4_clicked')
|
||||
@QtCore.pyqtSlot(name='on_export_hodge_button_clicked')
|
||||
def export_hodge(self):
|
||||
ret_dic2 = {}
|
||||
ret_dic = {}
|
||||
|
||||
for cb in (self.checkBox, self.checkBox_4, self.checkBox_6, self.checkBox_5, self.checkBox_7):
|
||||
for cb in (self.onset_check, self.mid_check, self.end_check, self.inflection_check, self.fictive_check):
|
||||
if cb.isChecked():
|
||||
item = cb.text().lower()
|
||||
data = self._hodge.get(item)
|
||||
if data[1] is not None:
|
||||
ret_dic2[item] = data[1]
|
||||
ret_dic[item] = data[1]
|
||||
|
||||
if self.new_graph_tau_check.isChecked():
|
||||
ret_dic2['graph'] = ''
|
||||
else:
|
||||
ret_dic2['graph'] = self.new_graph_tau_combo.currentData()
|
||||
ret_dic['graph'] = '' if self.hodge_graph_check.isChecked() else self.hodge_graph_combo.currentData()
|
||||
|
||||
self.newData.emit(ret_dic2, 'hodge')
|
||||
self.newData.emit(ret_dic, 'hodge')
|
||||
|
||||
def close(self) -> bool:
|
||||
self.clear()
|
||||
return super().close()
|
||||
|
||||
def accept(self) -> None:
|
||||
self.close()
|
||||
|
Reference in New Issue
Block a user