From 988d2ccbdaeee9443508803afe73f72d6395b3a8 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 13 Jun 2023 20:28:37 +0200 Subject: [PATCH] minor cleanup --- src/gui_qt/_py/tnmh_dialog.py | 161 ++++++++++++-------- src/gui_qt/dsc/glass_dialog.py | 39 +++-- src/gui_qt/main/mainwindow.py | 8 +- src/resources/_ui/tnmh_dialog.ui | 244 +++++++++++++++++++------------ 4 files changed, 280 insertions(+), 172 deletions(-) diff --git a/src/gui_qt/_py/tnmh_dialog.py b/src/gui_qt/_py/tnmh_dialog.py index 9ca5174..63fcb7c 100644 --- a/src/gui_qt/_py/tnmh_dialog.py +++ b/src/gui_qt/_py/tnmh_dialog.py @@ -17,6 +17,49 @@ class Ui_Dialog(object): Dialog.resize(1042, 683) self.gridLayout = QtWidgets.QGridLayout(Dialog) self.gridLayout.setObjectName("gridLayout") + self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) + self.buttonBox.setOrientation(QtCore.Qt.Horizontal) + self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok|QtWidgets.QDialogButtonBox.Save) + self.buttonBox.setObjectName("buttonBox") + self.gridLayout.addWidget(self.buttonBox, 3, 1, 1, 1) + self.verticalLayout = QtWidgets.QVBoxLayout() + self.verticalLayout.setObjectName("verticalLayout") + self.listWidget = QtWidgets.QListWidget(Dialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth()) + self.listWidget.setSizePolicy(sizePolicy) + self.listWidget.setObjectName("listWidget") + self.verticalLayout.addWidget(self.listWidget) + self.label = QtWidgets.QLabel(Dialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) + self.label.setSizePolicy(sizePolicy) + self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) + self.label.setObjectName("label") + self.verticalLayout.addWidget(self.label) + self.tg_value_label = QtWidgets.QLabel(Dialog) + self.tg_value_label.setObjectName("tg_value_label") + self.verticalLayout.addWidget(self.tg_value_label) + self.label_4 = QtWidgets.QLabel(Dialog) + self.label_4.setObjectName("label_4") + self.verticalLayout.addWidget(self.label_4) + self.label_5 = QtWidgets.QLabel(Dialog) + self.label_5.setText("") + self.label_5.setObjectName("label_5") + self.verticalLayout.addWidget(self.label_5) + self.gridLayout.addLayout(self.verticalLayout, 0, 0, 3, 1) + self.dsc_plot = PlotWidget(Dialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.dsc_plot.sizePolicy().hasHeightForWidth()) + self.dsc_plot.setSizePolicy(sizePolicy) + self.dsc_plot.setObjectName("dsc_plot") + self.gridLayout.addWidget(self.dsc_plot, 0, 1, 1, 1) self.stackedWidget = QtWidgets.QStackedWidget(Dialog) self.stackedWidget.setFrameShape(QtWidgets.QFrame.StyledPanel) self.stackedWidget.setFrameShadow(QtWidgets.QFrame.Raised) @@ -25,27 +68,43 @@ class Ui_Dialog(object): self.stackedWidgetPage1.setObjectName("stackedWidgetPage1") self.gridLayout_3 = QtWidgets.QGridLayout(self.stackedWidgetPage1) self.gridLayout_3.setObjectName("gridLayout_3") - self.checkBox = QtWidgets.QCheckBox(self.stackedWidgetPage1) - self.checkBox.setObjectName("checkBox") - self.gridLayout_3.addWidget(self.checkBox, 1, 1, 1, 1) - self.checkBox_2 = QtWidgets.QCheckBox(self.stackedWidgetPage1) - self.checkBox_2.setText("") - self.checkBox_2.setObjectName("checkBox_2") - self.gridLayout_3.addWidget(self.checkBox_2, 2, 1, 1, 1) - self.pushButton = QtWidgets.QPushButton(self.stackedWidgetPage1) - self.pushButton.setObjectName("pushButton") - self.gridLayout_3.addWidget(self.pushButton, 0, 1, 1, 1) - self.comboBox_2 = CheckCombobox(self.stackedWidgetPage1) - self.comboBox_2.setObjectName("comboBox_2") - self.gridLayout_3.addWidget(self.comboBox_2, 3, 1, 1, 1) - self.graphicsView_3 = PlotWidget(self.stackedWidgetPage1) + self.hodge_selection = CheckCombobox(self.stackedWidgetPage1) + self.hodge_selection.setObjectName("hodge_selection") + self.hodge_selection.addItem("") + self.hodge_selection.addItem("") + self.hodge_selection.addItem("") + self.hodge_selection.addItem("") + self.gridLayout_3.addWidget(self.hodge_selection, 4, 2, 1, 1) + self.tau_plot = PlotWidget(self.stackedWidgetPage1) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.graphicsView_3.sizePolicy().hasHeightForWidth()) - self.graphicsView_3.setSizePolicy(sizePolicy) - self.graphicsView_3.setObjectName("graphicsView_3") - self.gridLayout_3.addWidget(self.graphicsView_3, 0, 0, 4, 1) + sizePolicy.setHeightForWidth(self.tau_plot.sizePolicy().hasHeightForWidth()) + self.tau_plot.setSizePolicy(sizePolicy) + self.tau_plot.setObjectName("tau_plot") + self.gridLayout_3.addWidget(self.tau_plot, 0, 0, 7, 1) + self.tg_export_check = QtWidgets.QCheckBox(self.stackedWidgetPage1) + self.tg_export_check.setObjectName("tg_export_check") + self.gridLayout_3.addWidget(self.tg_export_check, 2, 1, 1, 1) + self.tglines_export_check = QtWidgets.QCheckBox(self.stackedWidgetPage1) + self.tglines_export_check.setObjectName("tglines_export_check") + self.gridLayout_3.addWidget(self.tglines_export_check, 2, 2, 1, 1) + spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) + self.gridLayout_3.addItem(spacerItem, 6, 2, 1, 1) + self.new_graph_tau_combo = QtWidgets.QComboBox(self.stackedWidgetPage1) + self.new_graph_tau_combo.setObjectName("new_graph_tau_combo") + self.gridLayout_3.addWidget(self.new_graph_tau_combo, 5, 2, 1, 1) + self.label_6 = QtWidgets.QLabel(self.stackedWidgetPage1) + self.label_6.setObjectName("label_6") + self.gridLayout_3.addWidget(self.label_6, 4, 1, 1, 1) + self.new_graph_tau_check = QtWidgets.QCheckBox(self.stackedWidgetPage1) + self.new_graph_tau_check.setObjectName("new_graph_tau_check") + self.gridLayout_3.addWidget(self.new_graph_tau_check, 5, 1, 1, 1) + self.line = QtWidgets.QFrame(self.stackedWidgetPage1) + self.line.setFrameShape(QtWidgets.QFrame.HLine) + self.line.setFrameShadow(QtWidgets.QFrame.Sunken) + self.line.setObjectName("line") + self.gridLayout_3.addWidget(self.line, 3, 1, 1, 2) self.stackedWidget.addWidget(self.stackedWidgetPage1) self.page = QtWidgets.QWidget() self.page.setObjectName("page") @@ -75,50 +134,15 @@ class Ui_Dialog(object): self.graphicsView_2.setObjectName("graphicsView_2") self.gridLayout_2.addWidget(self.graphicsView_2, 0, 0, 3, 1) self.stackedWidget.addWidget(self.page) - self.gridLayout.addWidget(self.stackedWidget, 1, 1, 1, 1) - self.buttonBox = QtWidgets.QDialogButtonBox(Dialog) - self.buttonBox.setOrientation(QtCore.Qt.Horizontal) - self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) - self.buttonBox.setObjectName("buttonBox") - self.gridLayout.addWidget(self.buttonBox, 2, 1, 1, 1) - self.graphicsView = PlotWidget(Dialog) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) + self.gridLayout.addWidget(self.stackedWidget, 2, 1, 1, 1) + self.calctg_button = QtWidgets.QPushButton(Dialog) + sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth()) - self.graphicsView.setSizePolicy(sizePolicy) - self.graphicsView.setObjectName("graphicsView") - self.gridLayout.addWidget(self.graphicsView, 0, 1, 1, 1) - self.verticalLayout = QtWidgets.QVBoxLayout() - self.verticalLayout.setObjectName("verticalLayout") - self.listWidget = QtWidgets.QListWidget(Dialog) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Expanding) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth()) - self.listWidget.setSizePolicy(sizePolicy) - self.listWidget.setObjectName("listWidget") - self.verticalLayout.addWidget(self.listWidget) - self.label = QtWidgets.QLabel(Dialog) - sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth()) - self.label.setSizePolicy(sizePolicy) - self.label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop) - self.label.setObjectName("label") - self.verticalLayout.addWidget(self.label) - self.label_3 = QtWidgets.QLabel(Dialog) - self.label_3.setObjectName("label_3") - self.verticalLayout.addWidget(self.label_3) - self.label_4 = QtWidgets.QLabel(Dialog) - self.label_4.setObjectName("label_4") - self.verticalLayout.addWidget(self.label_4) - self.label_5 = QtWidgets.QLabel(Dialog) - self.label_5.setText("") - self.label_5.setObjectName("label_5") - self.verticalLayout.addWidget(self.label_5) - self.gridLayout.addLayout(self.verticalLayout, 0, 0, 2, 1) + sizePolicy.setHeightForWidth(self.calctg_button.sizePolicy().hasHeightForWidth()) + self.calctg_button.setSizePolicy(sizePolicy) + self.calctg_button.setObjectName("calctg_button") + self.gridLayout.addWidget(self.calctg_button, 1, 1, 1, 1) self.retranslateUi(Dialog) self.stackedWidget.setCurrentIndex(0) @@ -129,8 +153,17 @@ class Ui_Dialog(object): def retranslateUi(self, Dialog): _translate = QtCore.QCoreApplication.translate Dialog.setWindowTitle(_translate("Dialog", "SImba, everything the light touches is our kingdom")) - self.checkBox.setText(_translate("Dialog", "Export lines")) - self.pushButton.setText(_translate("Dialog", "Calculate Tg")) + self.label.setText(_translate("Dialog", "

Tg values:

")) + self.tg_value_label.setText(_translate("Dialog", "TextLabel")) + self.label_4.setText(_translate("Dialog", "

TNMH parameter:

")) + self.hodge_selection.setItemText(0, _translate("Dialog", "Onset")) + self.hodge_selection.setItemText(1, _translate("Dialog", "Midpoint")) + self.hodge_selection.setItemText(2, _translate("Dialog", "End")) + self.hodge_selection.setItemText(3, _translate("Dialog", "Inflection")) + self.tg_export_check.setText(_translate("Dialog", "Export Tg")) + self.tglines_export_check.setText(_translate("Dialog", "Export lines")) + self.label_6.setText(_translate("Dialog", "Hodge:")) + self.new_graph_tau_check.setText(_translate("Dialog", "New graph")) self.pushButton_2.setText(_translate("Dialog", "Fictive Cp")) self.label_2.setText(_translate("Dialog", "Tg for TNMH")) self.comboBox.setItemText(0, _translate("Dialog", "Fictive")) @@ -139,8 +172,6 @@ class Ui_Dialog(object): self.comboBox.setItemText(3, _translate("Dialog", "End")) self.comboBox.setItemText(4, _translate("Dialog", "Inflection")) self.pushButton_3.setText(_translate("Dialog", "Fit TNMH model")) - self.label.setText(_translate("Dialog", "

Tg values:

")) - self.label_3.setText(_translate("Dialog", "TextLabel")) - self.label_4.setText(_translate("Dialog", "

TNMH parameter:

")) + self.calctg_button.setText(_translate("Dialog", "Calculate Tg")) from ..lib.forms import CheckCombobox from pyqtgraph import PlotWidget diff --git a/src/gui_qt/dsc/glass_dialog.py b/src/gui_qt/dsc/glass_dialog.py index 28bcc75..470c304 100644 --- a/src/gui_qt/dsc/glass_dialog.py +++ b/src/gui_qt/dsc/glass_dialog.py @@ -29,33 +29,42 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): 'mid': PlotItem(x=[], y=[], pen=None, symbol='s', symbolBrush=Tab10.TabOrange.rgb(), name='Midpoint'), 'end': PlotItem(x=[], y=[], pen=None, symbol='t', symbolBrush=Tab10.TabGreen.rgb(), name='End'), 'inflection': PlotItem(x=[], y=[], pen=None, symbol='d', symbolBrush=Tab10.TabRed.rgb(), name='Inflection'), - 'fictive': PlotItem(x=[], y=[], pen=None, symbol='t1', symbolBrush=Tab10.TabPurple.rgb(), name='Fictive'), + # 'fictive': PlotItem(x=[], y=[], pen=None, symbol='t1', symbolBrush=Tab10.TabPurple.rgb(), name='Fictive'), # 'TNMH': PlotItem(x=[], y=[], pen=None, symbol='star', symbolBrush=Tab10.TabPurple.rgb(), name='TNMH'), } + self.tau_plot.getPlotItem().addLegend() for plt in self._hodge_plots.values(): - self.graphicsView_3.addItem(plt) + self.tau_plot.addItem(plt) + self.tau_plot.setLogMode(y=True) self.limits = RegionItem(), RegionItem() for lim in self.limits: - self.graphicsView.addItem(lim) + self.dsc_plot.addItem(lim) self._limitless = True self.add_sets() self.listWidget.itemClicked.connect(self.show_tg_values) - for x in 'abc': - self.comboBox_2.addItem(x) + # for x in self._hodge_plots: + # self.hodge_selection.addItem(x) def __call__(self): + print('call') self.clear() + self._colors = cycle(Tab10) self.add_sets() + for g in self._management.graphs.list(): + print(g) + + return self + def clear(self): self.listWidget.clear() for plots in self._plots.values(): for val in plots: - self.graphicsView.removeItem(val) + self.dsc_plot.removeItem(val) self.graphicsView_2.removeItem(val) for plt in self._hodge_plots.values(): @@ -65,6 +74,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self._plots = {} self._tg_value = {} self._fit = {} + self.gra def add_sets(self): min_x = 10_000_000 @@ -86,22 +96,22 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self._dsc[key] = (data, None) data_plot = PlotItem(x=data.x, y=data.y, pen=mkPen(c.rgb())) - self.graphicsView.addItem(data_plot) + self.dsc_plot.addItem(data_plot) glass = PlotItem() glass.set_line(style=2, color=c) - self.graphicsView.addItem(glass) + self.dsc_plot.addItem(glass) liquid = PlotItem() liquid.set_line(style=2, color=c) - self.graphicsView.addItem(liquid) + self.dsc_plot.addItem(liquid) tangent = PlotItem() tangent.set_line(style=2, color=c) - self.graphicsView.addItem(tangent) + self.dsc_plot.addItem(tangent) tg_plot = PlotItem(pen=None, symbolBrush=c.rgb(), symbol='o') - self.graphicsView.addItem(tg_plot) + self.dsc_plot.addItem(tg_plot) fictive_cp = PlotItem(pen=mkPen(c.rgb())) self.graphicsView_2.addItem(fictive_cp) @@ -111,7 +121,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self.graphicsView_2.addItem(tnmh_fit) self._plots[key] = (data_plot, tg_plot, glass, liquid, tangent, fictive_cp, tnmh_fit) - self._tg_value[key] = {'onset': (nan, nan), 'mid': (nan, nan), 'end': (nan, nan), 'inflection': (nan, nan), 'fictive': (nan, nan)} + self._tg_value[key] = {'onset': (nan, nan), 'mid': (nan, nan), 'end': (nan, nan), 'inflection': (nan, nan)} # , 'fictive': (nan, nan)} if self._limitless: dist = max_x - min_x @@ -119,7 +129,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): self.limits[1].setRegion((max_x-min(5, 0.1*dist), max_x)) self._limitless = False - @QtCore.pyqtSlot(name='on_pushButton_clicked') + @QtCore.pyqtSlot(name='on_calctg_button_clicked') def calc_tg(self): baselines = tuple(lim.getRegion() for lim in self.limits) if baselines[0][0] > baselines[1][0]: @@ -148,7 +158,7 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): if values is not None: label = '\n'.join((f'{name.capitalize()}: {pos[0]:.2f} K' for name, pos in values.items())) - self.label_3.setText(label) + self.tg_value_label.setText(label) fit = self._fit.get(item.data(QtCore.Qt.UserRole)) if fit is not None: @@ -241,4 +251,3 @@ class TgCalculator(QtWidgets.QDialog, Ui_Dialog): def close(self) -> bool: self.clear() return super().close() - diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index f1a4431..3e0a406 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -57,6 +57,7 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.fitpreview = [] self._fit_plot_id = None self.savefitdialog = None + self._tg_dialog = None self.eval = None self.editor = None @@ -1083,5 +1084,8 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): @QtCore.pyqtSlot(name='on_actionTNMH_model_triggered') def show_tg_dialog(self): - dialog = TgCalculator(self.management, parent=self) - dialog.show() + if self._tg_dialog is None: + self._tg_dialog = TgCalculator(self.management, parent=self) + else: + self._tg_dialog() + self._tg_dialog.show() diff --git a/src/resources/_ui/tnmh_dialog.ui b/src/resources/_ui/tnmh_dialog.ui index 6d43351..8273241 100644 --- a/src/resources/_ui/tnmh_dialog.ui +++ b/src/resources/_ui/tnmh_dialog.ui @@ -14,7 +14,78 @@ SImba, everything the light touches is our kingdom - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Save + + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-weight:600;">Tg values:</span></p></body></html> + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + TextLabel + + + + + + + <html><head/><body><p><span style=" font-weight:600;">TNMH parameter:</span></p></body></html> + + + + + + + + + + + + + + + + + 0 + 0 + + + + + QFrame::StyledPanel @@ -25,34 +96,34 @@ 0 - + - - - - Export lines - + + + + + Onset + + + + + Midpoint + + + + + End + + + + + Inflection + + - - - - - - - - - - - Calculate Tg - - - - - - - - + + 0 @@ -61,6 +132,57 @@ + + + + Export Tg + + + + + + + Export lines + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Hodge: + + + + + + + New graph + + + + + + + Qt::Horizontal + + + @@ -126,77 +248,19 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - + + - + 0 0 + + Calculate Tg + - - - - - - - 0 - 0 - - - - - - - - - 0 - 0 - - - - <html><head/><body><p><span style=" font-weight:600;">Tg values:</span></p></body></html> - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - - - TextLabel - - - - - - - <html><head/><body><p><span style=" font-weight:600;">TNMH parameter:</span></p></body></html> - - - - - - - - - - - -