-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
97 lines (79 loc) · 3.06 KB
/
Copy pathmain.py
File metadata and controls
97 lines (79 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
"""
项目管理系统主程序
集成真实加载进度的启动界面
"""
import sys
import os
import traceback
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QTimer
def setup_global_exception_handler():
"""设置全局异常处理器"""
def handle_exception(exc_type, exc_value, exc_traceback):
"""全局异常处理函数"""
# 避免处理KeyboardInterrupt
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
# 记录异常到日志(如果可能)
try:
from Lib.logger import setup_logging
logger = setup_logging()
logger.critical("未捕获的异常", exc_info=(exc_type, exc_value, exc_traceback))
except:
# 如果日志系统不可用,输出到控制台
print(f"❌ 严重错误: {exc_type.__name__}: {exc_value}")
traceback.print_exception(exc_type, exc_value, exc_traceback)
sys.excepthook = handle_exception
def main():
"""主程序入口"""
# 设置全局异常处理
setup_global_exception_handler()
# 创建应用程序(必须最先创建)
app = QApplication(sys.argv)
# 创建全局变量保存主窗口引用,避免被垃圾回收
main_window = None
# 显示启动画面(使用真实加载)
from Gui.splash_screen import SplashScreen, RealLoadingWorker
splash = SplashScreen(use_real_loading=True)
splash.show()
# 创建真实的加载器
real_loader = RealLoadingWorker()
# 连接信号
real_loader.progress_signal.connect(splash.update_progress)
def on_loading_finished():
"""加载完成后创建并显示主窗口"""
nonlocal main_window
try:
# 在主线程中创建主窗口
from Gui.init_ui import MainWindow
main_window = MainWindow()
def delayed_show():
"""延迟显示主窗口"""
splash.close() # 关闭启动画面
main_window.show() # 显示主界面
main_window.raise_() # 确保主窗口在前台
main_window.activateWindow() # 激活窗口
print("✅ 主界面已显示")
# 延迟一点时间,确保加载动画完成
QTimer.singleShot(500, delayed_show)
except Exception as e:
print(f"❌ 创建主窗口失败: {e}")
import traceback
traceback.print_exc()
splash.close()
sys.exit(1)
# 只连接 finished_signal,移除重复的 main_window_ready 连接
real_loader.finished_signal.connect(on_loading_finished)
# 开始真实加载
real_loader.start()
# 运行应用程序
return app.exec_()
if __name__ == "__main__":
try:
exit_code = main()
sys.exit(exit_code)
except Exception as e:
print(f"❌ 程序启动失败: {e}")
sys.exit(1)