From 0c274ecbe07ada9ebb8a961b2637540ed41d7783 Mon Sep 17 00:00:00 2001 From: DLmaster Date: Sun, 16 Mar 2025 00:22:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E5=88=9D=E6=AD=A5=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=85=AC=E5=91=8A=E7=95=8C=E9=9D=A2=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/ui/Widget.py | 98 ++++++++++++++++++++++++++++++++++++++++++- app/ui/main_window.py | 4 +- app/ui/setting.py | 5 +-- 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/app/ui/Widget.py b/app/ui/Widget.py index 315d18f..9a2eef8 100644 --- a/app/ui/Widget.py +++ b/app/ui/Widget.py @@ -25,7 +25,14 @@ v4.2 作者:DLmaster_361 """ -from PySide6.QtWidgets import QWidget, QWidget, QLabel, QHBoxLayout, QSizePolicy +from PySide6.QtWidgets import ( + QWidget, + QWidget, + QLabel, + QHBoxLayout, + QVBoxLayout, + QSizePolicy, +) from PySide6.QtCore import Qt, QTime, QTimer, QEvent, QSize from PySide6.QtGui import QIcon, QPixmap, QPainter, QPainterPath from qfluentwidgets import ( @@ -54,12 +61,18 @@ from qfluentwidgets import ( ExpandSettingCard, ToolButton, PushButton, + PrimaryPushButton, ProgressRing, + TextBrowser, + HeaderCardWidget, ) from qfluentwidgets.common.overload import singledispatchmethod import os +import re +import markdown from urllib.parse import urlparse -from typing import Optional, Union, List +from functools import partial +from typing import Optional, Union, List, Dict from app.services import Crypto @@ -155,6 +168,87 @@ class ProgressRingMessageBox(MessageBoxBase): self.timer.deleteLater() +class NoticeMessageBox(MessageBoxBase): + """公告对话框""" + + def __init__(self, parent, content: Dict[str, str]): + super().__init__(parent) + + self.index = self.NoticeIndexCard(content, self) + self.text = TextBrowser(self) + self.text.setOpenExternalLinks(True) + self.button = PrimaryPushButton("确认", self) + + self.buttonGroup.hide() + + self.v_layout = QVBoxLayout() + self.v_layout.addWidget(self.text) + self.v_layout.addWidget(self.button) + + self.h_layout = QHBoxLayout() + self.h_layout.addWidget(self.index) + self.h_layout.addLayout(self.v_layout) + self.h_layout.setStretch(0, 1) + self.h_layout.setStretch(1, 3) + + # 将组件添加到布局中 + self.viewLayout.addLayout(self.h_layout) + self.widget.setFixedSize(800, 600) + + self.index.index_changed.connect(self.__update_text) + self.button.clicked.connect(self.yesButton.click) + self.index.index_cards[0].clicked.emit() + + def __update_text(self, text: str): + + html = markdown.markdown(text).replace("\n", "") + html = re.sub( + r"(.*?)", + r"\1", + html, + ) + html = re.sub(r"
  • (.*?)

  • ", r"

    \1

    ", html) + html = re.sub(r"", r"\1", html) + + self.text.setHtml(html) + + class NoticeIndexCard(HeaderCardWidget): + + index_changed = Signal(str) + + def __init__(self, content: Dict[str, str], parent=None): + super().__init__(parent) + self.setTitle("公告") + + self.Layout = QVBoxLayout() + self.viewLayout.addLayout(self.Layout) + self.viewLayout.setContentsMargins(3, 0, 3, 3) + + self.index_cards: List[QuantifiedItemCard] = [] + + if content: + self.index_cards.append(QuantifiedItemCard(["ALL", ""])) + self.index_cards[-1].clicked.connect( + lambda: self.index_changed.emit( + "\n---\n".join( + [str(_) for _ in content.values() if isinstance(_, str)] + ) + ) + ) + self.Layout.addWidget(self.index_cards[-1]) + else: + self.Layout.addWidget(QuantifiedItemCard(["暂无公告", ""])) + for index, text in content.items(): + + self.index_cards.append(QuantifiedItemCard([index, ""])) + self.index_cards[-1].clicked.connect( + partial(self.index_changed.emit, text) + ) + self.Layout.addWidget(self.index_cards[-1]) + + self.Layout.addStretch(1) + + class LineEditSettingCard(SettingCard): """Setting card with LineEdit""" diff --git a/app/ui/main_window.py b/app/ui/main_window.py index ecf32ab..3bbba97 100644 --- a/app/ui/main_window.py +++ b/app/ui/main_window.py @@ -210,12 +210,12 @@ class AUTO_MAA(MSFluentWindow): """切换主题""" setTheme(Theme.AUTO, lazy=True) - QTimer.singleShot(100, lambda: setTheme(Theme.AUTO, lazy=True)) + QTimer.singleShot(500, lambda: setTheme(Theme.AUTO, lazy=True)) # 云母特效启用时需要增加重试机制 if self.isMicaEffectEnabled(): QTimer.singleShot( - 100, + 500, lambda: self.windowEffect.setMicaEffect(self.winId(), isDarkTheme()), ) diff --git a/app/ui/setting.py b/app/ui/setting.py index 9b70124..9e29325 100644 --- a/app/ui/setting.py +++ b/app/ui/setting.py @@ -62,6 +62,7 @@ from .Widget import ( LineEditSettingCard, PasswordLineEditSettingCard, UrlListSettingCard, + NoticeMessageBox, ) @@ -465,9 +466,7 @@ class Setting(QWidget): and datetime.strptime(notice["time"], "%Y-%m-%d %H:%M") > time_local ): - choice = Dialog("公告", notice["content"], self) - choice.cancelButton.hide() - choice.buttonLayout.insertStretch(1) + choice = NoticeMessageBox(self.window(), notice["notice_dict"]) if choice.exec(): with (Config.app_path / "resources/notice.json").open( mode="w", encoding="utf-8"