"""Programmatische Icon-Generierung via Pillow.""" from PIL import Image, ImageDraw from whisper_local.tray._tray import AppState _STATE_COLORS: dict[AppState, tuple[int, int, int]] = { AppState.WAITING: (150, 150, 150), AppState.RECORDING: (220, 50, 50), AppState.TRANSCRIBING: (220, 180, 0), } def create_icon(state: AppState, size: int = 64) -> Image.Image: """Erzeugt ein Mikrofon-Icon in der Farbe des übergebenen Zustands.""" color = _STATE_COLORS[state] img = Image.new("RGBA", (size, size), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) cx = size // 2 bw = max(4, size // 6) # Hälfte der Körperbreite top = size // 8 mid = size // 2 # Mikrofon-Körper (abgerundetes Rechteck) draw.rounded_rectangle( [cx - bw, top, cx + bw, mid + bw], radius=bw, fill=color, ) # Bogen (Stativ-Bogen) arc_r = size // 4 arc_top = mid lw = max(2, size // 20) draw.arc( [cx - arc_r, arc_top, cx + arc_r, arc_top + arc_r], start=0, end=180, fill=color, width=lw, ) # Stiel pole_top = arc_top + arc_r // 2 pole_bot = size - size // 8 draw.line([cx, pole_top, cx, pole_bot], fill=color, width=lw) # Sockel base = size // 5 draw.line([cx - base, pole_bot, cx + base, pole_bot], fill=color, width=lw) return img