Skip to content

Commit 79b02ad

Browse files
committed
chore: 更新 .gitignore 文件以移除 *.spec 文件
1 parent 94f0a57 commit 79b02ad

6 files changed

Lines changed: 206 additions & 1 deletion

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ wheels/
2626

2727
# PyInstaller
2828
*.manifest
29-
*.spec
3029

3130
# Installer logs
3231
pip-log.txt

app.spec

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
import sys
4+
from pathlib import Path
5+
6+
block_cipher = None
7+
8+
# 读取版本信息
9+
VERSION = Path('VERSION').read_text().strip()
10+
11+
# 应用名称
12+
app_name = '电商图片AI处理工具'
13+
14+
# 图标路径配置
15+
icon_dir = Path('resources/icons')
16+
if sys.platform == 'darwin':
17+
icon_path = icon_dir / 'icon.icns' if (icon_dir / 'icon.icns').exists() else None
18+
elif sys.platform == 'win32':
19+
icon_path = icon_dir / 'icon.ico' if (icon_dir / 'icon.ico').exists() else None
20+
else: # Linux
21+
icon_path = icon_dir / 'icon.png' if (icon_dir / 'icon.png').exists() else None
22+
23+
# 数据文件
24+
datas = [
25+
('src/ui/resources', 'src/ui/resources'), # UI 资源文件
26+
('VERSION', '.'), # 版本文件
27+
]
28+
29+
# 隐藏导入(确保所有依赖被包含)
30+
hiddenimports = [
31+
'PyQt6.QtCore',
32+
'PyQt6.QtGui',
33+
'PyQt6.QtWidgets',
34+
'PIL._tkinter_finder',
35+
'keyring.backends',
36+
'keyring.backends.macOS', # macOS
37+
'keyring.backends.Windows', # Windows
38+
'keyring.backends.SecretService', # Linux
39+
]
40+
41+
# 排除的模块(减小打包体积)
42+
excludes = [
43+
'matplotlib',
44+
'numpy',
45+
'pandas',
46+
'scipy',
47+
'pytest',
48+
'tkinter',
49+
]
50+
51+
a = Analysis(
52+
['src/main.py'],
53+
pathex=[],
54+
binaries=[],
55+
datas=datas,
56+
hiddenimports=hiddenimports,
57+
hookspath=[],
58+
hooksconfig={},
59+
runtime_hooks=[],
60+
excludes=excludes,
61+
win_no_prefer_redirects=False,
62+
win_private_assemblies=False,
63+
cipher=block_cipher,
64+
noarchive=False,
65+
)
66+
67+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
68+
69+
exe = EXE(
70+
pyz,
71+
a.scripts,
72+
[],
73+
exclude_binaries=True,
74+
name=app_name,
75+
debug=False,
76+
bootloader_ignore_signals=False,
77+
strip=False,
78+
upx=True,
79+
console=False, # 不显示控制台窗口
80+
disable_windowed_traceback=False,
81+
argv_emulation=False,
82+
target_arch=None,
83+
codesign_identity=None,
84+
entitlements_file=None,
85+
icon=str(icon_path) if icon_path else None,
86+
)
87+
88+
coll = COLLECT(
89+
exe,
90+
a.binaries,
91+
a.zipfiles,
92+
a.datas,
93+
strip=False,
94+
upx=True,
95+
upx_exclude=[],
96+
name=app_name,
97+
)
98+
99+
# macOS 应用包配置
100+
if sys.platform == 'darwin':
101+
app = BUNDLE(
102+
coll,
103+
name=f'{app_name}.app',
104+
icon=str(icon_path) if icon_path and icon_path.suffix == '.icns' else None,
105+
bundle_identifier='io.jiuling.ecommerce-image-processor',
106+
version=VERSION,
107+
info_plist={
108+
'NSPrincipalClass': 'NSApplication',
109+
'NSHighResolutionCapable': 'True',
110+
'CFBundleShortVersionString': VERSION,
111+
'CFBundleVersion': VERSION,
112+
},
113+
)

resources/icons/icon.icns

168 KB
Binary file not shown.

resources/icons/icon.ico

9.43 KB
Binary file not shown.

resources/icons/icon.png

29.8 KB
Loading

scripts/generate_icons.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# 图标生成脚本
4+
# 从源 PNG 图片生成各平台所需的图标文件
5+
6+
set -e
7+
8+
# 颜色输出
9+
GREEN='\033[0;32m'
10+
YELLOW='\033[1;33m'
11+
RED='\033[0;31m'
12+
NC='\033[0m'
13+
14+
print_success() { echo -e "${GREEN}$1${NC}"; }
15+
print_info() { echo -e "${YELLOW}ℹ️ $1${NC}"; }
16+
print_error() { echo -e "${RED}$1${NC}"; }
17+
18+
# 获取脚本所在目录的父目录(项目根目录)
19+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20+
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
21+
cd "$PROJECT_ROOT"
22+
23+
# 检查参数
24+
if [ $# -eq 0 ]; then
25+
print_error "请提供源图片文件路径"
26+
echo "用法: $0 <源图片.png>"
27+
echo "示例: $0 ~/Desktop/icon.png"
28+
exit 1
29+
fi
30+
31+
SOURCE_IMAGE="$1"
32+
33+
# 检查源文件是否存在
34+
if [ ! -f "$SOURCE_IMAGE" ]; then
35+
print_error "文件不存在: $SOURCE_IMAGE"
36+
exit 1
37+
fi
38+
39+
print_info "源图片: $SOURCE_IMAGE"
40+
41+
# 创建图标目录
42+
ICON_DIR="resources/icons"
43+
mkdir -p "$ICON_DIR"
44+
45+
# 生成 macOS 图标 (.icns)
46+
print_info "生成 macOS 图标 (.icns)..."
47+
48+
# 创建临时图标集
49+
ICONSET_DIR="icon.iconset"
50+
mkdir -p "$ICONSET_DIR"
51+
52+
# 生成各种尺寸
53+
sips -z 16 16 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_16x16.png" > /dev/null 2>&1
54+
sips -z 32 32 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_16x16@2x.png" > /dev/null 2>&1
55+
sips -z 32 32 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_32x32.png" > /dev/null 2>&1
56+
sips -z 64 64 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_32x32@2x.png" > /dev/null 2>&1
57+
sips -z 128 128 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_128x128.png" > /dev/null 2>&1
58+
sips -z 256 256 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_128x128@2x.png" > /dev/null 2>&1
59+
sips -z 256 256 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_256x256.png" > /dev/null 2>&1
60+
sips -z 512 512 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_256x256@2x.png" > /dev/null 2>&1
61+
sips -z 512 512 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_512x512.png" > /dev/null 2>&1
62+
sips -z 1024 1024 "$SOURCE_IMAGE" --out "$ICONSET_DIR/icon_512x512@2x.png" > /dev/null 2>&1
63+
64+
# 生成 .icns
65+
iconutil -c icns "$ICONSET_DIR" -o "$ICON_DIR/icon.icns"
66+
rm -rf "$ICONSET_DIR"
67+
print_success "macOS 图标已生成: $ICON_DIR/icon.icns"
68+
69+
# 生成 Windows 图标 (.ico)
70+
print_info "生成 Windows 图标 (.ico)..."
71+
72+
# 检查 ImageMagick 是否安装
73+
if command -v convert &> /dev/null; then
74+
convert "$SOURCE_IMAGE" -define icon:auto-resize=256,128,64,48,32,16 "$ICON_DIR/icon.ico"
75+
print_success "Windows 图标已生成: $ICON_DIR/icon.ico"
76+
else
77+
print_info "未安装 ImageMagick,跳过 .ico 生成"
78+
print_info "安装方法: brew install imagemagick"
79+
print_info "或使用在线工具: https://cloudconvert.com/png-to-ico"
80+
fi
81+
82+
# 复制 Linux 图标 (PNG)
83+
print_info "生成 Linux 图标 (.png)..."
84+
cp "$SOURCE_IMAGE" "$ICON_DIR/icon.png"
85+
print_success "Linux 图标已生成: $ICON_DIR/icon.png"
86+
87+
echo ""
88+
print_success "🎉 所有图标已生成完成!"
89+
echo ""
90+
echo "生成的文件:"
91+
ls -lh "$ICON_DIR/"
92+
echo ""
93+
print_info "现在可以运行 pyinstaller app.spec 打包应用了"

0 commit comments

Comments
 (0)