From a8a7e7550142f359e0adbce10254c2bbfdb3d8e8 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 30 May 2023 17:36:44 +0200 Subject: [PATCH] plot DSC data and baselines --- src/gui_qt/_py/tnmh_dialog.py | 7 ++++++ src/gui_qt/dsc/glass_dialog.py | 42 ++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/gui_qt/_py/tnmh_dialog.py b/src/gui_qt/_py/tnmh_dialog.py index 612f7ec..d1d29e9 100644 --- a/src/gui_qt/_py/tnmh_dialog.py +++ b/src/gui_qt/_py/tnmh_dialog.py @@ -71,6 +71,12 @@ class Ui_Dialog(object): self.lineEdit_4.setSizePolicy(sizePolicy) self.lineEdit_4.setObjectName("lineEdit_4") self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.lineEdit_4) + self.pushButton = QtWidgets.QPushButton(Dialog) + self.pushButton.setObjectName("pushButton") + self.formLayout.setWidget(4, QtWidgets.QFormLayout.SpanningRole, self.pushButton) + self.listWidget_2 = QtWidgets.QListWidget(Dialog) + self.listWidget_2.setObjectName("listWidget_2") + self.formLayout.setWidget(5, QtWidgets.QFormLayout.SpanningRole, self.listWidget_2) self.gridLayout.addLayout(self.formLayout, 0, 1, 1, 1) self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) self.buttonBox.setOrientation(QtCore.Qt.Horizontal) @@ -98,4 +104,5 @@ class Ui_Dialog(object): self.label_2.setText(_translate("Dialog", "β")) self.label_3.setText(_translate("Dialog", "ΔH/R / K")) self.label_4.setText(_translate("Dialog", "x")) + self.pushButton.setText(_translate("Dialog", "PushButton")) from pyqtgraph import PlotWidget diff --git a/src/gui_qt/dsc/glass_dialog.py b/src/gui_qt/dsc/glass_dialog.py index 6956e8a..4d30174 100644 --- a/src/gui_qt/dsc/glass_dialog.py +++ b/src/gui_qt/dsc/glass_dialog.py @@ -13,6 +13,8 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self._management = management self._plots = {} + self._tg_baselines = {} + self.dsc = [] self.limits = RegionItem(), RegionItem() for lim in self.limits: @@ -26,18 +28,54 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): # s.valuesChanged.connect(self.management.shift_scale) def clear(self): + self.dsc = [] self.listWidget.clear() - for k, v in self._plots.items(): + for v in self._plots.values(): self.graphicsView.removeItem(v) + self._plots = {} + + for v in self._tg_baselines.values(): + self.graphicsView.removeItem(v) + self._tg_baselines = {} def add_sets(self): for key, name in self._management.active_sets: data = self._management.data[key] - if not isinstance(data.data, DSC): + if isinstance(data.data, DSC): + self.dsc.append(data) + else: continue item = QtWidgets.QListWidgetItem(name) item.setData(QtCore.Qt.UserRole, key) + self.listWidget.addItem(item) + plot = PlotItem(x=data.x, y=data.y) self.graphicsView.addItem(plot) self._plots[key] = plot + + @QtCore.pyqtSlot(name='on_pushButton_clicked') + def calc_tg(self): + baselines = tuple(lim.getRegion() for lim in self.limits) + if baselines[0][0] > baselines[1][0]: + baselines = baselines[1], baselines[0] + + for idx in range(self.listWidget.count()): + key = self.listWidget.item(idx).data(QtCore.Qt.UserRole) + tg_results, glass, liquid, tangent = self._management[key].data.glass_transition(*baselines) + + lines = [] + for line in (glass, liquid, tangent): + plt = PlotItem(line[:, 0], line[:, 1]) + self.graphicsView.addItem(plt) + lines.append(plt) + self._tg_baselines[key] = lines + + tg_plot = PlotItem(*zip((i for i in tg_results.values()))) + self.graphicsView.addItem(tg_plot) + + def close(self) -> bool: + self.clear() + + return super().close() +