-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (67 loc) · 2.49 KB
/
main.py
File metadata and controls
81 lines (67 loc) · 2.49 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
"""
PDF 名册管理生成工具 - 程序入口
"""
import sys
import os
from pathlib import Path
# ============ 诊断:打印环境信息 ============
def _print_diag():
print("=== PDFMC 启动诊断 ===", flush=True)
print(f"frozen={getattr(sys,'frozen',False)}", flush=True)
print(f"MEIPASS={getattr(sys,'_MEIPASS','N/A')}", flush=True)
print(f"executable={sys.executable}", flush=True)
print(f"QT_PLUGIN_PATH={os.environ.get('QT_PLUGIN_PATH','NOT SET')}", flush=True)
try:
from PySide6 import QtCore
print(f"Qt version={QtCore.qVersion()} libraryPaths={QtCore.QCoreApplication.libraryPaths()}", flush=True)
except Exception as e:
print(f"PySide6 import FAILED: {e}", flush=True)
print("=" * 40, flush=True)
if getattr(sys, 'frozen', False):
_print_diag()
# ==========================================
# 添加项目根目录到路径
current_dir = Path(__file__).parent.resolve()
sys.path.insert(0, str(current_dir))
from PySide6.QtWidgets import QApplication
from PySide6.QtCore import Qt
from src.ui.main_window import MainWindow
from config import APP_TITLE, DEFAULT_WORK_DIR, DEFAULT_OUTPUT_DIR
def ensure_directories():
"""确保默认目录存在"""
DEFAULT_WORK_DIR.mkdir(parents=True, exist_ok=True)
DEFAULT_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
def main():
"""主函数"""
# 确保目录存在
ensure_directories()
# 创建应用
app = QApplication(sys.argv)
app.setApplicationName(APP_TITLE)
app.setStyle('Fusion')
# 强制浅色主题(避免 Windows 深色模式下白底白字问题)
from PySide6.QtGui import QPalette, QColor
palette = QPalette()
palette.setColor(QPalette.Window, QColor(240, 240, 240))
palette.setColor(QPalette.WindowText, QColor(0, 0, 0))
palette.setColor(QPalette.Base, QColor(255, 255, 255))
palette.setColor(QPalette.AlternateBase, QColor(245, 245, 245))
palette.setColor(QPalette.Text, QColor(0, 0, 0))
palette.setColor(QPalette.Button, QColor(240, 240, 240))
palette.setColor(QPalette.ButtonText, QColor(0, 0, 0))
palette.setColor(QPalette.Highlight, QColor(0, 120, 212))
palette.setColor(QPalette.HighlightedText, QColor(255, 255, 255))
app.setPalette(palette)
# 创建主窗口
window = MainWindow()
window.show()
# 运行应用
try:
sys.exit(app.exec())
except SystemExit:
# 清理资源
window.close()
del window
del app
if __name__ == '__main__':
main()