2024-09-08 15:25:21 +08:00
|
|
|
from PyQt5.QtWidgets import QApplication
|
|
|
|
from qfluentwidgets import FluentWindow, Theme, setTheme
|
|
|
|
from qfluentwidgets import FluentIcon as FIF
|
2024-09-08 19:53:00 +08:00
|
|
|
|
2024-09-08 15:48:25 +08:00
|
|
|
from interface.main import MainWidget
|
|
|
|
from interface.setting import SettingWidget
|
2024-09-09 11:30:20 +08:00
|
|
|
from interface.init import InitWindow
|
2024-09-09 13:29:53 +08:00
|
|
|
import app.env as env
|
2024-09-08 19:53:00 +08:00
|
|
|
import sys
|
2024-09-08 15:25:21 +08:00
|
|
|
|
2024-09-08 19:53:00 +08:00
|
|
|
# 主窗口类
|
2024-09-08 15:25:21 +08:00
|
|
|
class MainWindow(FluentWindow):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2024-09-08 15:48:25 +08:00
|
|
|
|
2024-09-08 19:53:00 +08:00
|
|
|
# 设置窗口标题
|
2024-09-08 15:25:21 +08:00
|
|
|
self.setWindowTitle("HoYoCenter")
|
2024-09-08 19:53:00 +08:00
|
|
|
|
2024-09-09 15:55:45 +08:00
|
|
|
if env.config.theme == "dark":
|
|
|
|
setTheme(Theme.DARK)
|
|
|
|
else:
|
2024-09-09 16:10:46 +08:00
|
|
|
setTheme(Theme.LIGHT)
|
2024-09-08 19:53:00 +08:00
|
|
|
|
|
|
|
# 定义id和对象映射
|
2024-09-08 15:48:25 +08:00
|
|
|
self.id2obj = {
|
|
|
|
"主页": [MainWidget(), FIF.HOME],
|
|
|
|
"设置": [SettingWidget(), FIF.SETTING]
|
|
|
|
}
|
2024-09-08 19:53:00 +08:00
|
|
|
# 初始化UI
|
2024-09-08 15:25:21 +08:00
|
|
|
self.init_ui()
|
|
|
|
|
|
|
|
def init_ui(self):
|
2024-09-09 11:30:20 +08:00
|
|
|
self.w = InitWindow()
|
|
|
|
self.w.show()
|
2024-09-08 19:53:00 +08:00
|
|
|
# 初始化菜单
|
2024-09-08 15:25:21 +08:00
|
|
|
self.init_menu()
|
|
|
|
|
2024-09-08 19:53:00 +08:00
|
|
|
# 初始化菜单
|
2024-09-08 15:25:21 +08:00
|
|
|
def init_menu(self):
|
2024-09-08 19:53:00 +08:00
|
|
|
# 设置导航栏展开宽度
|
2024-09-08 15:25:21 +08:00
|
|
|
self.navigationInterface.setExpandWidth(150)
|
2024-09-08 19:53:00 +08:00
|
|
|
# 遍历id和对象映射
|
2024-09-08 15:25:21 +08:00
|
|
|
for name, obj in self.id2obj.items():
|
2024-09-08 19:53:00 +08:00
|
|
|
# 设置对象名称
|
2024-09-08 15:48:25 +08:00
|
|
|
obj[0].setObjectName(name)
|
2024-09-08 19:53:00 +08:00
|
|
|
# 添加子界面
|
2024-09-08 15:48:25 +08:00
|
|
|
self.addSubInterface(obj[0], obj[1], name)
|
2024-09-08 15:25:21 +08:00
|
|
|
|
2024-09-08 19:53:00 +08:00
|
|
|
# 创建应用程序
|
2024-09-08 15:25:21 +08:00
|
|
|
def create_app():
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
window = MainWindow()
|
2024-09-08 19:53:00 +08:00
|
|
|
workaera = app.primaryScreen().availableGeometry()
|
|
|
|
# 设置窗口大小
|
|
|
|
window.resize(workaera.width(),workaera.height())
|
|
|
|
# 显示窗口
|
2024-09-08 15:25:21 +08:00
|
|
|
window.show()
|
|
|
|
return app
|
|
|
|
|
2024-09-08 19:53:00 +08:00
|
|
|
# 主函数
|
2024-09-08 15:25:21 +08:00
|
|
|
def main():
|
|
|
|
app = create_app()
|
2024-09-08 19:53:00 +08:00
|
|
|
# 运行应用程序
|
2024-09-08 15:25:21 +08:00
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
2024-09-08 19:53:00 +08:00
|
|
|
# 如果是主程序运行
|
2024-09-08 15:25:21 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|