claude-usage-widget/scripts/make-icon.py
megaproxy 9be856d37c Polish for shipping: robust auto-detect, empty state, real icons, end-user README
- cli_usage::default_command now enumerates WSL distros and probes each for
  claude before falling back; no more hardcoded -d Ubuntu.
- New autodetect_claude_command Tauri command + IPC binding so the UI knows
  whether claude is reachable.
- App.svelte: clear 'Claude Code not found' empty state with install link.
- Real icons: scripts/make-icon.py generates a 1024x1024 source.png; runtime
  produces 32/128/256 PNGs and a multi-resolution .ico. README in icons/
  explains how to regen.
- README rewritten for friends: install / requirements / troubleshooting on
  top; build-from-source moved to bottom.
2026-05-09 14:25:24 +01:00

72 lines
2 KiB
Python

"""
Regenerate src-tauri/icons/source.png — dark rounded square + purple
progress ring + white 'C'. Matches the running widget's visual language.
Run from the project root:
python3 scripts/make-icon.py
pnpm tauri icon src-tauri/icons/source.png # generates ico/icns/etc
"""
import math
import os
import sys
from pathlib import Path
try:
from PIL import Image, ImageDraw, ImageFont
except ImportError:
sys.stderr.write("Pillow not installed: pip install --user Pillow\n")
sys.exit(2)
SIZE = 1024
PAD = 40
RADIUS = 180
RING_PAD = 200
STROKE = 60
PROGRESS = 0.72 # decorative; matches the widget at ~real usage
BG = (22, 24, 32, 255)
TRACK = (255, 255, 255, 26)
ACCENT = (176, 139, 255, 255)
FG = (232, 234, 240, 255)
def main(out: Path) -> None:
img = Image.new("RGBA", (SIZE, SIZE), (0, 0, 0, 0))
draw = ImageDraw.Draw(img)
draw.rounded_rectangle([PAD, PAD, SIZE - PAD, SIZE - PAD], radius=RADIUS, fill=BG)
box = [RING_PAD, RING_PAD, SIZE - RING_PAD, SIZE - RING_PAD]
draw.arc(box, start=0, end=360, fill=TRACK, width=STROKE)
sweep = 360 * PROGRESS
draw.arc(box, start=-90, end=-90 + sweep, fill=ACCENT, width=STROKE)
end_rad = math.radians(-90 + sweep)
cx, cy = SIZE // 2, SIZE // 2
r = (SIZE - 2 * RING_PAD) / 2
ex, ey = cx + r * math.cos(end_rad), cy + r * math.sin(end_rad)
dot = STROKE // 2
draw.ellipse([ex - dot, ey - dot, ex + dot, ey + dot], fill=ACCENT)
try:
font = ImageFont.load_default(size=320)
except Exception:
font = None
if font:
text = "C"
bbox = draw.textbbox((0, 0), text, font=font)
tw = bbox[2] - bbox[0]
th = bbox[3] - bbox[1]
draw.text(((SIZE - tw) / 2 - bbox[0], (SIZE - th) / 2 - bbox[1] - 12),
text, font=font, fill=FG)
out.parent.mkdir(parents=True, exist_ok=True)
img.save(out, "PNG")
print(f"wrote {out} {SIZE}x{SIZE}")
if __name__ == "__main__":
here = Path(__file__).resolve().parent.parent
main(here / "src-tauri" / "icons" / "source.png")