Files
pythonwallpaper/readme.md
T

64 lines
2.1 KiB
Markdown

# 壁纸更换器
从 HTTP API 自动拉取壁纸并设置为 Windows 桌面背景,支持托盘常驻和桌面右键菜单。
## 功能
- 托盘程序常驻,右键菜单手动/自动刷新壁纸
- 桌面右键菜单「刷新壁纸」一键更换
- 支持 API 直接返回图片二进制或 JSON 含图片 URL 两种模式
- 可配置填充方式(填充/适应/拉伸/平铺/居中)
- 可配置缓存目录及最大缓存数量
- 可开关换壁纸后气泡通知
- 单实例运行,重复启动弹窗提示
- 首次运行自动创建配置和目录
## 使用
```powershell
# 运行托盘程序
python main.py
# 右键菜单刷新
python main.py --refresh
# 安装桌面右键菜单(首次需要,从托盘菜单操作)
右键托盘 安装右键菜单
```
## 编译为 .exe
使用 Nuitka 打包:
```powershell
powershell -ExecutionPolicy Bypass -File build.ps1
```
产物:`dist/WallpaperChanger.dist/WallpaperChanger.exe`(独立目录模式,含 exe + 依赖库)
- 双击运行 → 启动托盘
- `WallpaperChanger.exe --refresh` → 拉取并设置壁纸后退出(右键菜单用)
- 首次运行在同目录下自动创建 `config.json``cache/``logs/``assets/`
## 配置
`config.json` 字段说明:
| 路径 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| `api.url` | string | — | 壁纸 API 地址 |
| `api.mode` | string | `direct` | `direct` 返回图片二进制 / `json` 返回 JSON |
| `api.json_image_field` | string | `url` | JSON 模式下图片 URL 的字段名 |
| `api.timeout` | int | `30` | 请求超时秒数 |
| `wallpaper.fill_style` | string | `fill` | `fill`/`fit`/`stretch`/`tile`/`center` |
| `wallpaper.cache_dir` | string | `./cache` | 壁纸缓存目录 |
| `wallpaper.max_cache_files` | int | `10` | 最大缓存文件数 |
| `wallpaper.show_notification` | bool | `true` | 换壁纸后是否弹气泡通知 |
| `auto_refresh.enabled` | bool | `false` | 是否开启定时自动刷新 |
| `auto_refresh.interval_minutes` | int | `10` | 自动刷新间隔分钟数 |
## 依赖
- Python 3.12+
- requests, pystray, Pillow