Merge pull request 'feat: 支持外部加载音频文件,优化打包配置' (#2) from main into master

Reviewed-on: http://192.168.3.32:3000/xiaji/countdown/pulls/2
This commit was merged in pull request #2.
This commit is contained in:
2026-01-22 10:28:57 +08:00
9 changed files with 139 additions and 86 deletions

1
.gitignore vendored
View File

@@ -7,7 +7,6 @@ __pycache__/
build/
dist/
*.spec
!dist/*.exe
# IDE
.idea/

BIN
2alarm.wav Normal file

Binary file not shown.

13
SKILL.md Normal file
View File

@@ -0,0 +1,13 @@
## 元数据
name: pyinstaller个性化打包
description: 打包的时候要求生成为一个exe文件使用ico等等
## 概述
此 Skill 用于给有GUI界面的python代码打包的时候生成一个统一的要求生成一个exe文件去掉控制台窗口使用本目录下的ico文件作为程序的图标。打包时如果之前有打包过的文件dist/build 文件夹),自动覆盖旧文件,不用手动确认,一键打包到底。
## 打包命令示例
python -m PyInstaller --onefile --windowed --icon=图标文件名.ico --name=guba-indicator --exclude-module PyQt5 --exclude-module PyQt5.QtCore --exclude-module PyQt5.QtGui --exclude-module PyQt5.QtWidgets --exclude-module PyQt6 --exclude-module PyQt6.QtCore --exclude-module PyQt6.QtGui --exclude-module PyQt6.QtWidgets python程序名.py
## 清除多余文件
在windows环境下执行clean.py

BIN
alarm.wav

Binary file not shown.

17
clean.py Normal file
View File

@@ -0,0 +1,17 @@
import os
import shutil
import glob
import subprocess
# 2. 清理打包残留文件 等价rd /s /q build + del /f *.spec
print("开始清理打包残留文件...")
# 删除build文件夹
if os.path.exists("build") and os.path.isdir("build"):
shutil.rmtree("build")
# 删除所有.spec文件
spec_files = glob.glob("*.spec")
for spec_file in spec_files:
if os.path.exists(spec_file):
os.remove(spec_file)
print("✅ 打包完成 + 残留文件清理完毕exe文件已生成在当前目录")

Binary file not shown.

View File

@@ -17,6 +17,18 @@ class ConfigDialog(QDialog):
self.init_ui()
def init_ui(self):
self.setStyleSheet("""
QDialog {
background-color: #f5f5f5;
}
QLabel {
color: #333333;
font-size: 14px;
}
QSpinBox, QCheckBox {
padding: 5px;
}
""")
layout = QFormLayout(self)
# 自定义倒计时
@@ -181,11 +193,23 @@ class TimerApp(QWidget):
def setup_audio(self):
self.sound = QSoundEffect()
# 优先从外部目录加载音频文件
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
# exe所在目录
external_path = os.path.dirname(sys.executable)
else:
base_path = os.path.dirname(__file__)
alarm_file = os.path.join(base_path, "alarm.wav")
# 当前工作目录
external_path = os.getcwd()
alarm_file = os.path.join(external_path, "alarm.wav")
if not os.path.exists(alarm_file):
# 外部没有则从打包的临时目录加载
if getattr(sys, 'frozen', False):
alarm_file = os.path.join(sys._MEIPASS, "alarm.wav")
else:
alarm_file = os.path.join(os.path.dirname(__file__), "alarm.wav")
if os.path.exists(alarm_file):
self.sound.setSource(QUrl.fromLocalFile(alarm_file))
self.sound.setLoopCount(3)