添加初始化窗口逻辑以处理首次运行
This commit is contained in:
parent
11e843bff3
commit
9b9499d3f5
|
@ -11,6 +11,7 @@ class Config:
|
||||||
"""
|
"""
|
||||||
base_config = {
|
base_config = {
|
||||||
"theme": "dark",
|
"theme": "dark",
|
||||||
|
"init": False
|
||||||
}
|
}
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -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)
|
|
56
interface/init/__init__.py
Normal file
56
interface/init/__init__.py
Normal file
|
@ -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_())
|
7
interface/init/about.py
Normal file
7
interface/init/about.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from PyQt5.QtWidgets import QWidget
|
||||||
|
|
||||||
|
class AboutWidget(QWidget):
|
||||||
|
def __init__(self, typex="init"):
|
||||||
|
self.init_ui()
|
||||||
|
|
||||||
|
def init_ui()
|
6
main.py
6
main.py
|
@ -30,7 +30,8 @@ class MainWindow(FluentWindow):
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
|
||||||
def init_ui(self):
|
def init_ui(self):
|
||||||
self.w = InitWindow()
|
if not env.config.init:
|
||||||
|
self.w = InitWindow(self)
|
||||||
self.w.show()
|
self.w.show()
|
||||||
# 初始化菜单
|
# 初始化菜单
|
||||||
self.init_menu()
|
self.init_menu()
|
||||||
|
@ -54,12 +55,13 @@ def create_app():
|
||||||
# 设置窗口大小
|
# 设置窗口大小
|
||||||
window.resize(workaera.width(),workaera.height())
|
window.resize(workaera.width(),workaera.height())
|
||||||
# 显示窗口
|
# 显示窗口
|
||||||
window.show()
|
# window.show()
|
||||||
return app
|
return app
|
||||||
|
|
||||||
# 主函数
|
# 主函数
|
||||||
def main():
|
def main():
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|
||||||
# 运行应用程序
|
# 运行应用程序
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user