diff --git a/components.py b/components.py index cc87d69..2c72f1b 100644 --- a/components.py +++ b/components.py @@ -66,13 +66,30 @@ def scaled_frame(frame: QPixmap): def get_res(relative_path): """获取资源路径""" + # 优先检查系统安装路径 + enji_resources = os.environ.get("ENJI_RESOURCES") + if enji_resources: + system_path = os.path.join(enji_resources, relative_path) + if os.path.exists(system_path): + return system_path + + # PyInstaller 打包路径 if hasattr(sys, "_MEIPASS"): base_path = sys._MEIPASS elif getattr(sys, "frozen", False): base_path = os.path.dirname(sys.executable) else: base_path = os.path.dirname(__file__) - return os.path.join(base_path, relative_path) + + resource_path = os.path.join(base_path, relative_path) + + # 如果在开发环境,尝试在项目根目录查找 + if not os.path.exists(resource_path): + alt_path = os.path.join(os.path.dirname(base_path), relative_path) + if os.path.exists(alt_path): + return alt_path + + return resource_path class Color: diff --git a/main.py b/main.py index 08dfae9..2b1ab1f 100644 --- a/main.py +++ b/main.py @@ -9,12 +9,21 @@ from PySide6.QtWidgets import QApplication, QWidget -def notify(title: str, body: str, image=None, buttons=None): +def notify(title: str, body: str, image=None, icon=None, buttons=None): """Linux 桌面通知,使用 notify-send 替代 win11toast""" try: cmd = ["notify-send", "--app-name=胭脂"] + + # 处理图标参数 + icon_path = None if image and isinstance(image, dict) and "src" in image: - cmd += ["--icon", image["src"]] + icon_path = image["src"] + elif icon and isinstance(icon, str): + icon_path = icon + + if icon_path: + cmd += ["--icon", icon_path] + # 将按钮链接附加到通知正文 extra = "" if buttons: @@ -54,18 +63,42 @@ def __init__(self): init_scale() # 初始化字体 - self.font_id1 = QFontDatabase.addApplicationFont( - get_res("resources/mogihaPen.ttf") - ) - self.font_family1 = QFontDatabase.applicationFontFamilies(self.font_id1)[0] - self.font1 = QFont(self.font_family1) - self.setFont(self.font1) + font_path1 = get_res("resources/mogihaPen.ttf") + print(f"[调试] 尝试加载字体1: {font_path1}") + self.font_id1 = QFontDatabase.addApplicationFont(font_path1) + if self.font_id1 == -1: + print(f"[警告] 无法加载字体: {font_path1},字体 ID 为 -1") + self.font1 = QFont() + self.font_family1 = self.font1.family() + else: + font_families1 = QFontDatabase.applicationFontFamilies(self.font_id1) + if font_families1: + self.font_family1 = font_families1[0] + self.font1 = QFont(self.font_family1) + self.setFont(self.font1) + print(f"[成功] 加载字体1: {self.font_family1}") + else: + print(f"[警告] 无法获取字体族: {font_path1}") + self.font1 = QFont() + self.font_family1 = self.font1.family() - self.font_id2 = QFontDatabase.addApplicationFont( - get_res("resources/AkazukiPOP_subset.otf") - ) - self.font_family2 = QFontDatabase.applicationFontFamilies(self.font_id2)[0] - self.font2 = QFont(self.font_family2) + font_path2 = get_res("resources/AkazukiPOP_subset.otf") + print(f"[调试] 尝试加载字体2: {font_path2}") + self.font_id2 = QFontDatabase.addApplicationFont(font_path2) + if self.font_id2 == -1: + print(f"[警告] 无法加载字体: {font_path2},字体 ID 为 -1") + self.font2 = QFont() + self.font_family2 = self.font2.family() + else: + font_families2 = QFontDatabase.applicationFontFamilies(self.font_id2) + if font_families2: + self.font_family2 = font_families2[0] + self.font2 = QFont(self.font_family2) + print(f"[成功] 加载字体2: {self.font_family2}") + else: + print(f"[警告] 无法获取字体族: {font_path2}") + self.font2 = QFont() + self.font_family2 = self.font2.family() # 初始化音乐 self.player = QMediaPlayer() diff --git a/pyproject.toml b/pyproject.toml index 64730b8..ab55bb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,11 +5,23 @@ description = "一个使用PySide6仿照《胭脂》制作的动画程序" readme = "README.md" requires-python = ">=3.13" dependencies = [ - "pyinstaller>=6.14.2", "pyside6>=6.9.1", - # win11toast 已移除(Windows 专属),通知改用系统 notify-send ] +[project.scripts] +enji = "main:main" + +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +py-modules = ["main", "components", "cover"] + +[tool.setuptools.packages.find] +where = ["."] +include = ["*"] + [[tool.uv.index]] -url = "https://pypi.tuna.tsinghua.edu.cn/simple" -default = true +url = "https://pypi.tuna.tsinghua.edu.cn/simple/" +default = true \ No newline at end of file