新增了手动切换深浅色模式的功能

This commit is contained in:
2025-06-11 00:28:59 +08:00
parent 8d3408aac3
commit 07223f222b
5 changed files with 229 additions and 40 deletions

View File

@ -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__)
@ -352,3 +363,85 @@ class MainWindow(QMainWindow, Ui_Signal_Label):
for path in path_list:
if not path.exists():
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

View File

@ -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 = "导入完成"

1
run.py
View File

@ -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()

View File

@ -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))

View File

@ -24,9 +24,9 @@
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,1,1,1,1,1,1,1,1,1">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="30,1,8">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0,0">
<item>
<widget class="QLabel" name="label">
<property name="font">
@ -44,10 +44,58 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_darkmode">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>深色模式开关</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
@ -90,6 +138,19 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>