You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Curriculum_Design/src/main.py

71 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# main.py
import sys
import traceback
import os
# 添加项目根目录到Python路径
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, project_root)
# 设置Qt平台插件路径 - 优先使用系统Qt插件
system_qt_plugins_path = '/usr/local/opt/qt5/plugins' # macOS Homebrew Qt5路径
venv_qt_plugins_path = os.path.join(project_root, '.venv', 'lib', 'python3.9', 'site-packages', 'PyQt5', 'Qt5', 'plugins')
# 优先检查系统Qt插件路径
if os.path.exists(system_qt_plugins_path):
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = system_qt_plugins_path
elif os.path.exists(venv_qt_plugins_path):
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = venv_qt_plugins_path
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from src.main_window import MainWindow
# 设置高DPI支持必须在QApplication创建之前
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
def main():
"""
应用程序主入口点
- 创建QApplication实例
- 设置应用程序属性
- 创建MainWindow实例
- 显示窗口
- 启动事件循环
- 返回退出码
"""
try:
# 创建QApplication实例
app = QApplication(sys.argv)
# 设置应用程序属性
app.setApplicationName("隐私学习软件")
app.setApplicationVersion("0.1.0")
app.setOrganizationName("MagicWord Team")
# 设置窗口图标(如果存在)
icon_path = os.path.join(project_root, 'resources', 'icons', 'app_icon.png')
if os.path.exists(icon_path):
app.setWindowIcon(QIcon(icon_path))
else:
# 使用默认图标
app.setWindowIcon(QIcon())
# 创建主窗口
window = MainWindow()
window.show()
# 启动事件循环并返回退出码
exit_code = app.exec_()
sys.exit(exit_code)
except Exception as e:
# 打印详细的错误信息
print(f"应用程序发生未捕获的异常: {e}")
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()