Files
nl-tools/main.py
2025-12-11 10:30:15 +08:00

85 lines
2.0 KiB
Python

"""
奶酪云工具箱 - 主入口
Cheese Cloud Tools - Main Entry
"""
import sys
import os
from pathlib import Path
# 处理打包后的资源路径
def get_resource_path(relative_path):
"""获取资源文件的绝对路径(兼容打包后)"""
if getattr(sys, 'frozen', False):
# 打包后的路径
base_path = Path(sys._MEIPASS)
else:
# 开发时的路径
base_path = Path(__file__).parent
return base_path / relative_path
# 添加项目根目录到路径
if getattr(sys, 'frozen', False):
PROJECT_ROOT = Path(sys._MEIPASS)
else:
PROJECT_ROOT = Path(__file__).parent
sys.path.insert(0, str(PROJECT_ROOT))
from PySide6.QtWidgets import QApplication
from PySide6.QtGui import QFont, QIcon
from core.logger import setup_logging
from core.error_handler import ErrorHandler
from ui.main_window import MainWindow
# Logo 图标路径
LOGO_PATH = get_resource_path("image/生成奶酪商城官方店介绍.png")
def load_stylesheet() -> str:
"""加载样式表"""
style_path = PROJECT_ROOT / "resources" / "style.qss"
if style_path.exists():
with open(style_path, "r", encoding="utf-8") as f:
return f.read()
return ""
def main():
"""主函数"""
# 初始化日志
setup_logging()
# 创建应用
app = QApplication(sys.argv)
app.setApplicationName("奶酪云工具箱")
app.setApplicationVersion("1.0.0")
# 设置应用图标(任务栏图标)
if LOGO_PATH.exists():
app_icon = QIcon(str(LOGO_PATH))
app.setWindowIcon(app_icon)
# 设置默认字体
font = QFont("Microsoft YaHei", 10)
app.setFont(font)
# 初始化全局错误处理
error_handler = ErrorHandler(app)
# 加载样式表
stylesheet = load_stylesheet()
if stylesheet:
app.setStyleSheet(stylesheet)
# 创建主窗口
window = MainWindow()
window.show()
# 运行应用
sys.exit(app.exec())
if __name__ == "__main__":
main()