From 07223f222b710f434bbde9dde1c8a6502c6ebaa3 Mon Sep 17 00:00:00 2001 From: Yorusora Date: Wed, 11 Jun 2025 00:28:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=B7=B1=E6=B5=85=E8=89=B2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func/Module_mainwindow.py | 97 +++++++++++++++++++++++++++- func/utils/Constants.py | 2 + run.py | 1 - ui/MainWindow/MainWindow_menu.py | 104 ++++++++++++++++++++----------- ui/MainWindow/MainWindow_menu.ui | 65 ++++++++++++++++++- 5 files changed, 229 insertions(+), 40 deletions(-) diff --git a/func/Module_mainwindow.py b/func/Module_mainwindow.py index 4c916de..8cdc416 100644 --- a/func/Module_mainwindow.py +++ b/func/Module_mainwindow.py @@ -1,6 +1,8 @@ from pathlib import Path +from traceback import format_exc -from PySide6.QtWidgets import QMainWindow, QMessageBox, QFileDialog +from PySide6.QtCore import Qt +from PySide6.QtWidgets import QMainWindow, QMessageBox, QFileDialog, QApplication, QWidget from PySide6.QtGui import QGuiApplication from matplotlib import use from yaml import dump, load, FullLoader @@ -112,7 +114,16 @@ class MainWindow(QMainWindow, Ui_Signal_Label): PublicFunc.__styleAllButton__(self, ButtonState) + try: + if QApplication.styleHints().colorScheme() == Qt.ColorScheme.Dark: + self.ui.checkBox_darkmode.setChecked(True) + else: + self.ui.checkBox_darkmode.setChecked(False) + except Exception as e: + PublicFunc.msgbox_output(self, Constants.MAINWINDOW_GET_DARKMODE_FAILURE + "。" + format_exc(), Constants.TIPS_TYPE_ERROR) + # 绑定槽函数 + self.ui.checkBox_darkmode.stateChanged.connect(self.set_dark_mode_status) self.ui.pushButton_open.clicked.connect(self.__slot_btn_open__) self.ui.pushButton_approximately_align.clicked.connect(self.__slot_btn_approximately_align__) self.ui.pushButton_preprocess_BCG.clicked.connect(self.__slot_btn_preprocess__) @@ -351,4 +362,86 @@ class MainWindow(QMainWindow, Ui_Signal_Label): for path in path_list: if not path.exists(): - path.mkdir(parents=True, exist_ok=True) \ No newline at end of file + path.mkdir(parents=True, exist_ok=True) + + def set_dark_mode_status(self): + try: + if self.ui.checkBox_darkmode.isChecked(): + QApplication.styleHints().setColorScheme(Qt.ColorScheme.Dark) + else: + QApplication.styleHints().setColorScheme(Qt.ColorScheme.Light) + except Exception as e: + PublicFunc.msgbox_output(self, Constants.MAINWINDOW_DARKMODE_FAILURE + "。" + format_exc(), Constants.MSGBOX_TYPE_ERROR) + return + + try: + MainWindow.update_widget_style(self) + except RuntimeError: + pass + try: + if self.approximately_align is not None: + MainWindow.update_widget_style(self.approximately_align) + except RuntimeError: + pass + try: + if self.preprocess is not None: + MainWindow.update_widget_style(self.preprocess) + except RuntimeError: + pass + try: + if self.detect_Jpeak is not None: + MainWindow.update_widget_style(self.detect_Jpeak) + except RuntimeError: + pass + try: + if self.detect_Rpeak is not None: + MainWindow.update_widget_style(self.detect_Rpeak) + except RuntimeError: + pass + try: + if self.label_check is not None: + MainWindow.update_widget_style(self.label_check) + except RuntimeError: + pass + try: + if self.precisely_align is not None: + MainWindow.update_widget_style(self.precisely_align) + except RuntimeError: + pass + try: + if self.cut_PSG is not None: + MainWindow.update_widget_style(self.cut_PSG) + except RuntimeError: + pass + try: + if self.artifact_label is not None: + MainWindow.update_widget_style(self.artifact_label) + except RuntimeError: + pass + try: + if self.bcg_quality_label is not None: + MainWindow.update_widget_style(self.bcg_quality_label) + except RuntimeError: + pass + try: + if self.resp_quality_label is not None: + MainWindow.update_widget_style(self.resp_quality_label) + except RuntimeError: + pass + try: + if self.SA_label is not None: + MainWindow.update_widget_style(self.SA_label) + except RuntimeError: + pass + + @staticmethod + def update_widget_style(mainWindow): + all_widgets = mainWindow.centralWidget().findChildren(QWidget) + # 迭代所有部件 + for widget in all_widgets: + try: + widget.style().unpolish(widget) + widget.style().polish(widget) + widget.update() + except TypeError: + pass \ No newline at end of file diff --git a/func/utils/Constants.py b/func/utils/Constants.py index 3885939..1e96ac1 100644 --- a/func/utils/Constants.py +++ b/func/utils/Constants.py @@ -14,6 +14,8 @@ class Constants: MAINWINDOW_ROOT_PATH_NOT_EXIST: str = "根目录路径输入错误" MAINWINDOW_SAMPID_EMPTY: str = "样本ID为空" MAINWINDOW_MSGBOX_TITLE: str = "消息" + MAINWINDOW_GET_DARKMODE_FAILURE: str = "获取深浅色状态失败,不影响标注工作,可忽略" + MAINWINDOW_DARKMODE_FAILURE: str = "切换深浅色模式失败,不影响标注工作,可忽略" INPUTTING_DATA: str = "正在导入数据" INPUT_FINISHED: str = "导入完成" diff --git a/run.py b/run.py index 496db60..5e30e71 100644 --- a/run.py +++ b/run.py @@ -39,7 +39,6 @@ if __name__ == '__main__': QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough) app = QApplication(argv) - # app.styleHints().setColorScheme(Qt.ColorScheme.Light) # 强制使用浅色模式 app.setStyle("Fusion") mainWindow = MainWindow() mainWindow.show() diff --git a/ui/MainWindow/MainWindow_menu.py b/ui/MainWindow/MainWindow_menu.py index 104c18a..0889f3d 100644 --- a/ui/MainWindow/MainWindow_menu.py +++ b/ui/MainWindow/MainWindow_menu.py @@ -15,10 +15,10 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) -from PySide6.QtWidgets import (QApplication, QComboBox, QGridLayout, QHBoxLayout, - QLabel, QMainWindow, QPlainTextEdit, QPushButton, - QSizePolicy, QSpacerItem, QStatusBar, QVBoxLayout, - QWidget) +from PySide6.QtWidgets import (QApplication, QCheckBox, QComboBox, QGridLayout, + QHBoxLayout, QLabel, QMainWindow, QPlainTextEdit, + QPushButton, QSizePolicy, QSpacerItem, QStatusBar, + QVBoxLayout, QWidget) class Ui_Signal_Label(object): def setupUi(self, Signal_Label): @@ -51,12 +51,38 @@ class Ui_Signal_Label(object): self.plainTextEdit_root_path = QPlainTextEdit(self.centralwidget) self.plainTextEdit_root_path.setObjectName(u"plainTextEdit_root_path") self.plainTextEdit_root_path.setEnabled(False) + sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) + sizePolicy1.setHorizontalStretch(0) + sizePolicy1.setVerticalStretch(0) + sizePolicy1.setHeightForWidth(self.plainTextEdit_root_path.sizePolicy().hasHeightForWidth()) + self.plainTextEdit_root_path.setSizePolicy(sizePolicy1) self.verticalLayout_3.addWidget(self.plainTextEdit_root_path) + self.horizontalLayout_5 = QHBoxLayout() + self.horizontalLayout_5.setObjectName(u"horizontalLayout_5") + self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) + + self.horizontalLayout_5.addItem(self.horizontalSpacer) + + self.checkBox_darkmode = QCheckBox(self.centralwidget) + self.checkBox_darkmode.setObjectName(u"checkBox_darkmode") + font1 = QFont() + font1.setPointSize(12) + self.checkBox_darkmode.setFont(font1) + + self.horizontalLayout_5.addWidget(self.checkBox_darkmode) + + + self.verticalLayout_3.addLayout(self.horizontalLayout_5) + self.horizontalLayout.addLayout(self.verticalLayout_3) + self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum) + + self.horizontalLayout.addItem(self.horizontalSpacer_2) + self.verticalLayout_2 = QVBoxLayout() self.verticalLayout_2.setObjectName(u"verticalLayout_2") self.verticalSpacer = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding) @@ -71,25 +97,32 @@ class Ui_Signal_Label(object): self.pushButton_open = QPushButton(self.centralwidget) self.pushButton_open.setObjectName(u"pushButton_open") - sizePolicy1 = QSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Preferred) - sizePolicy1.setHorizontalStretch(0) - sizePolicy1.setVerticalStretch(0) - sizePolicy1.setHeightForWidth(self.pushButton_open.sizePolicy().hasHeightForWidth()) - self.pushButton_open.setSizePolicy(sizePolicy1) + sizePolicy2 = QSizePolicy(QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Preferred) + sizePolicy2.setHorizontalStretch(0) + sizePolicy2.setVerticalStretch(0) + sizePolicy2.setHeightForWidth(self.pushButton_open.sizePolicy().hasHeightForWidth()) + self.pushButton_open.setSizePolicy(sizePolicy2) self.pushButton_open.setFont(font) self.verticalLayout_2.addWidget(self.pushButton_open) + self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding) + + self.verticalLayout_2.addItem(self.verticalSpacer_2) + self.horizontalLayout.addLayout(self.verticalLayout_2) + self.horizontalLayout.setStretch(0, 30) + self.horizontalLayout.setStretch(1, 1) + self.horizontalLayout.setStretch(2, 8) self.verticalLayout.addLayout(self.horizontalLayout) self.pushButton_approximately_align = QPushButton(self.centralwidget) self.pushButton_approximately_align.setObjectName(u"pushButton_approximately_align") - sizePolicy1.setHeightForWidth(self.pushButton_approximately_align.sizePolicy().hasHeightForWidth()) - self.pushButton_approximately_align.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_approximately_align.sizePolicy().hasHeightForWidth()) + self.pushButton_approximately_align.setSizePolicy(sizePolicy2) self.pushButton_approximately_align.setFont(font) self.verticalLayout.addWidget(self.pushButton_approximately_align) @@ -98,16 +131,16 @@ class Ui_Signal_Label(object): self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") self.pushButton_preprocess_BCG = QPushButton(self.centralwidget) self.pushButton_preprocess_BCG.setObjectName(u"pushButton_preprocess_BCG") - sizePolicy1.setHeightForWidth(self.pushButton_preprocess_BCG.sizePolicy().hasHeightForWidth()) - self.pushButton_preprocess_BCG.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_preprocess_BCG.sizePolicy().hasHeightForWidth()) + self.pushButton_preprocess_BCG.setSizePolicy(sizePolicy2) self.pushButton_preprocess_BCG.setFont(font) self.horizontalLayout_2.addWidget(self.pushButton_preprocess_BCG) self.pushButton_preprocess_ECG = QPushButton(self.centralwidget) self.pushButton_preprocess_ECG.setObjectName(u"pushButton_preprocess_ECG") - sizePolicy1.setHeightForWidth(self.pushButton_preprocess_ECG.sizePolicy().hasHeightForWidth()) - self.pushButton_preprocess_ECG.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_preprocess_ECG.sizePolicy().hasHeightForWidth()) + self.pushButton_preprocess_ECG.setSizePolicy(sizePolicy2) self.pushButton_preprocess_ECG.setFont(font) self.horizontalLayout_2.addWidget(self.pushButton_preprocess_ECG) @@ -119,16 +152,16 @@ class Ui_Signal_Label(object): self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") self.pushButton_detect_Jpeak = QPushButton(self.centralwidget) self.pushButton_detect_Jpeak.setObjectName(u"pushButton_detect_Jpeak") - sizePolicy1.setHeightForWidth(self.pushButton_detect_Jpeak.sizePolicy().hasHeightForWidth()) - self.pushButton_detect_Jpeak.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_detect_Jpeak.sizePolicy().hasHeightForWidth()) + self.pushButton_detect_Jpeak.setSizePolicy(sizePolicy2) self.pushButton_detect_Jpeak.setFont(font) self.horizontalLayout_3.addWidget(self.pushButton_detect_Jpeak) self.pushButton_detect_Rpeak = QPushButton(self.centralwidget) self.pushButton_detect_Rpeak.setObjectName(u"pushButton_detect_Rpeak") - sizePolicy1.setHeightForWidth(self.pushButton_detect_Rpeak.sizePolicy().hasHeightForWidth()) - self.pushButton_detect_Rpeak.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_detect_Rpeak.sizePolicy().hasHeightForWidth()) + self.pushButton_detect_Rpeak.setSizePolicy(sizePolicy2) self.pushButton_detect_Rpeak.setFont(font) self.horizontalLayout_3.addWidget(self.pushButton_detect_Rpeak) @@ -140,16 +173,16 @@ class Ui_Signal_Label(object): self.horizontalLayout_6.setObjectName(u"horizontalLayout_6") self.pushButton_label_check_BCG = QPushButton(self.centralwidget) self.pushButton_label_check_BCG.setObjectName(u"pushButton_label_check_BCG") - sizePolicy1.setHeightForWidth(self.pushButton_label_check_BCG.sizePolicy().hasHeightForWidth()) - self.pushButton_label_check_BCG.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_label_check_BCG.sizePolicy().hasHeightForWidth()) + self.pushButton_label_check_BCG.setSizePolicy(sizePolicy2) self.pushButton_label_check_BCG.setFont(font) self.horizontalLayout_6.addWidget(self.pushButton_label_check_BCG) self.pushButton_label_check_ECG = QPushButton(self.centralwidget) self.pushButton_label_check_ECG.setObjectName(u"pushButton_label_check_ECG") - sizePolicy1.setHeightForWidth(self.pushButton_label_check_ECG.sizePolicy().hasHeightForWidth()) - self.pushButton_label_check_ECG.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_label_check_ECG.sizePolicy().hasHeightForWidth()) + self.pushButton_label_check_ECG.setSizePolicy(sizePolicy2) self.pushButton_label_check_ECG.setFont(font) self.horizontalLayout_6.addWidget(self.pushButton_label_check_ECG) @@ -161,16 +194,16 @@ class Ui_Signal_Label(object): self.horizontalLayout_4.setObjectName(u"horizontalLayout_4") self.pushButton_precisely_align = QPushButton(self.centralwidget) self.pushButton_precisely_align.setObjectName(u"pushButton_precisely_align") - sizePolicy1.setHeightForWidth(self.pushButton_precisely_align.sizePolicy().hasHeightForWidth()) - self.pushButton_precisely_align.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_precisely_align.sizePolicy().hasHeightForWidth()) + self.pushButton_precisely_align.setSizePolicy(sizePolicy2) self.pushButton_precisely_align.setFont(font) self.horizontalLayout_4.addWidget(self.pushButton_precisely_align) self.pushButton_cut_PSG = QPushButton(self.centralwidget) self.pushButton_cut_PSG.setObjectName(u"pushButton_cut_PSG") - sizePolicy1.setHeightForWidth(self.pushButton_cut_PSG.sizePolicy().hasHeightForWidth()) - self.pushButton_cut_PSG.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_cut_PSG.sizePolicy().hasHeightForWidth()) + self.pushButton_cut_PSG.setSizePolicy(sizePolicy2) self.pushButton_cut_PSG.setFont(font) self.horizontalLayout_4.addWidget(self.pushButton_cut_PSG) @@ -182,32 +215,32 @@ class Ui_Signal_Label(object): self.pushButton_artifact_label = QPushButton(self.centralwidget) self.pushButton_artifact_label.setObjectName(u"pushButton_artifact_label") - sizePolicy1.setHeightForWidth(self.pushButton_artifact_label.sizePolicy().hasHeightForWidth()) - self.pushButton_artifact_label.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_artifact_label.sizePolicy().hasHeightForWidth()) + self.pushButton_artifact_label.setSizePolicy(sizePolicy2) self.pushButton_artifact_label.setFont(font) self.verticalLayout.addWidget(self.pushButton_artifact_label) self.pushButton_bcg_quality_label = QPushButton(self.centralwidget) self.pushButton_bcg_quality_label.setObjectName(u"pushButton_bcg_quality_label") - sizePolicy1.setHeightForWidth(self.pushButton_bcg_quality_label.sizePolicy().hasHeightForWidth()) - self.pushButton_bcg_quality_label.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_bcg_quality_label.sizePolicy().hasHeightForWidth()) + self.pushButton_bcg_quality_label.setSizePolicy(sizePolicy2) self.pushButton_bcg_quality_label.setFont(font) self.verticalLayout.addWidget(self.pushButton_bcg_quality_label) self.pushButton_resp_quality_label = QPushButton(self.centralwidget) self.pushButton_resp_quality_label.setObjectName(u"pushButton_resp_quality_label") - sizePolicy1.setHeightForWidth(self.pushButton_resp_quality_label.sizePolicy().hasHeightForWidth()) - self.pushButton_resp_quality_label.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_resp_quality_label.sizePolicy().hasHeightForWidth()) + self.pushButton_resp_quality_label.setSizePolicy(sizePolicy2) self.pushButton_resp_quality_label.setFont(font) self.verticalLayout.addWidget(self.pushButton_resp_quality_label) self.pushButton_SA_label = QPushButton(self.centralwidget) self.pushButton_SA_label.setObjectName(u"pushButton_SA_label") - sizePolicy1.setHeightForWidth(self.pushButton_SA_label.sizePolicy().hasHeightForWidth()) - self.pushButton_SA_label.setSizePolicy(sizePolicy1) + sizePolicy2.setHeightForWidth(self.pushButton_SA_label.sizePolicy().hasHeightForWidth()) + self.pushButton_SA_label.setSizePolicy(sizePolicy2) self.pushButton_SA_label.setFont(font) self.verticalLayout.addWidget(self.pushButton_SA_label) @@ -238,6 +271,7 @@ class Ui_Signal_Label(object): def retranslateUi(self, Signal_Label): Signal_Label.setWindowTitle(QCoreApplication.translate("Signal_Label", u"Signal_Label", None)) self.label.setText(QCoreApplication.translate("Signal_Label", u"\u6570\u636e\u6839\u76ee\u5f55\uff1a", None)) + self.checkBox_darkmode.setText(QCoreApplication.translate("Signal_Label", u"\u6df1\u8272\u6a21\u5f0f\u5f00\u5173", None)) self.pushButton_open.setText(QCoreApplication.translate("Signal_Label", u"\u6253\u5f00", None)) self.pushButton_approximately_align.setText(QCoreApplication.translate("Signal_Label", u"\u6570\u636e\u7c97\u540c\u6b65", None)) self.pushButton_preprocess_BCG.setText(QCoreApplication.translate("Signal_Label", u"BCG\u7684\u9884\u5904\u7406", None)) diff --git a/ui/MainWindow/MainWindow_menu.ui b/ui/MainWindow/MainWindow_menu.ui index 5445f16..c7f57ca 100644 --- a/ui/MainWindow/MainWindow_menu.ui +++ b/ui/MainWindow/MainWindow_menu.ui @@ -24,9 +24,9 @@ - + - + @@ -44,10 +44,58 @@ false + + + 0 + 0 + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + + + + 12 + + + + 深色模式开关 + + + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + @@ -90,6 +138,19 @@ + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + +