From 9b9499d3f51a7e947654b3e6eaf667822df75601 Mon Sep 17 00:00:00 2001 From: moyanj <1561515308@qq.com> Date: Mon, 9 Sep 2024 17:40:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E9=80=BB=E8=BE=91=E4=BB=A5=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=A6=96=E6=AC=A1=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/config.py | 1 + interface/init.py | 14 ---------- interface/init/__init__.py | 56 ++++++++++++++++++++++++++++++++++++++ interface/init/about.py | 7 +++++ main.py | 8 ++++-- 5 files changed, 69 insertions(+), 17 deletions(-) delete mode 100644 interface/init.py create mode 100644 interface/init/__init__.py create mode 100644 interface/init/about.py diff --git a/app/config.py b/app/config.py index 5c8abb7..bdeb9d7 100644 --- a/app/config.py +++ b/app/config.py @@ -11,6 +11,7 @@ class Config: """ base_config = { "theme": "dark", + "init": False } def __init__(self): """ diff --git a/interface/init.py b/interface/init.py deleted file mode 100644 index 439b67e..0000000 --- a/interface/init.py +++ /dev/null @@ -1,14 +0,0 @@ -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication -from qfluentwidgets import MessageBoxBase, SubtitleLabel - -class InitWindow(QWidget): - """ Custom message box """ - - def __init__(self): - super().__init__() - self.layout = QVBoxLayout(self) - self.titleLabel = SubtitleLabel('初始化') - # 将组件添加到布局中 - self.layout.addWidget(self.titleLabel) - - self.setLayout(self.layout) diff --git a/interface/init/__init__.py b/interface/init/__init__.py new file mode 100644 index 0000000..b4a308b --- /dev/null +++ b/interface/init/__init__.py @@ -0,0 +1,56 @@ +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QDesktopWidget +from PyQt5.QtCore import Qt +from qfluentwidgets import PushButton, SubtitleLabel, Theme, setTheme +import app.env as env + +class InitWindow(QWidget): + def __init__(self, main_window): + super().__init__() + self.window = main_window + + if env.config.theme == "dark": + setTheme(Theme.DARK) + # 给窗口添加样式 + self.setStyleSheet("background-color: #2E2E2E;") + else: + setTheme(Theme.LIGHT) + + # 设置窗口大小 + self.resize(800, 600) + + # 设置窗口始终位于最上层 + self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint) + + # 居中显示 + self.center_window() + + # 初始化布局 + self.layout = QVBoxLayout(self) + self.titleLabel = SubtitleLabel('初始化') + self.start_button = PushButton('开始') + self.start_button.clicked.connect(self.run) + self.layout.addWidget(self.start_button) + # 将组件添加到布局中 + self.layout.addWidget(self.titleLabel) + + # 应用布局 + self.setLayout(self.layout) + + def center_window(self): + """将窗口居中显示""" + screen = QDesktopWidget().screenGeometry() + size = self.geometry() + new_left = (screen.width() - size.width()) // 2 + new_top = (screen.height() - size.height()) // 2 + self.move(new_left, new_top) + + def run(self): + self.window.show() + self.close() + +if __name__ == "__main__": + import sys + app = QApplication(sys.argv) + window = InitWindow() + window.show() + sys.exit(app.exec_()) \ No newline at end of file diff --git a/interface/init/about.py b/interface/init/about.py new file mode 100644 index 0000000..b37e224 --- /dev/null +++ b/interface/init/about.py @@ -0,0 +1,7 @@ +from PyQt5.QtWidgets import QWidget + +class AboutWidget(QWidget): + def __init__(self, typex="init"): + self.init_ui() + + def init_ui() \ No newline at end of file diff --git a/main.py b/main.py index d331c2b..5a0db52 100644 --- a/main.py +++ b/main.py @@ -30,8 +30,9 @@ class MainWindow(FluentWindow): self.init_ui() def init_ui(self): - self.w = InitWindow() - self.w.show() + if not env.config.init: + self.w = InitWindow(self) + self.w.show() # 初始化菜单 self.init_menu() @@ -54,12 +55,13 @@ def create_app(): # 设置窗口大小 window.resize(workaera.width(),workaera.height()) # 显示窗口 - window.show() + # window.show() return app # 主函数 def main(): app = create_app() + # 运行应用程序 sys.exit(app.exec_())