"""Tiny widget-region placeholder image, shared by every widget-type module for the "not configured yet" / "temporarily unavailable" case -- deliberately much simpler than image_pipeline.render_placeholder (no QR code, no full-panel-scale fonts): a widget's own region can be a small fraction of the panel, so its placeholder needs to scale down with it. """ from __future__ import annotations from PIL import Image, ImageDraw, ImageFont _BG = (245, 245, 245) _FG = (90, 90, 90) def placeholder_image(target_w: int, target_h: int, lines: list[str]) -> Image.Image: img = Image.new("RGB", (target_w, target_h), _BG) draw = ImageDraw.Draw(img) font_size = max(10, min(20, target_h // 8)) font = ImageFont.load_default(size=font_size) line_h = font_size + 4 total_h = line_h * len(lines) y = max(4, (target_h - total_h) // 2) for line in lines: bbox = draw.textbbox((0, 0), line, font=font) line_w = bbox[2] - bbox[0] x = max(4, (target_w - line_w) // 2) draw.text((x, y), line, fill=_FG, font=font) y += line_h return img