Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
59 changes: 46 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 14 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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