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