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:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,7 +7,6 @@ __pycache__/
|
||||
build/
|
||||
dist/
|
||||
*.spec
|
||||
!dist/*.exe
|
||||
|
||||
# IDE
|
||||
.idea/
|
||||
|
||||
BIN
2alarm.wav
Normal file
BIN
2alarm.wav
Normal file
Binary file not shown.
13
SKILL.md
Normal file
13
SKILL.md
Normal 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
|
||||
17
clean.py
Normal file
17
clean.py
Normal 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文件已生成在当前目录")
|
||||
BIN
countdown.exe
BIN
countdown.exe
Binary file not shown.
30
countdown.py
30
countdown.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user