New app/widgets/ package (photos.py, calendar.py, whiteboard.py, plus the WIDGET_TYPES registry) -- the widget-system analogue of routers/device.py's old RENDERERS/ADVANCE_RENDERERS/BACK_RENDERERS, generalized from "one mode owns the whole panel" to "each widget renders into its own region and responds to named button actions." Each module exposes render(db, frame, widget, target_w, target_h) -> Image.Image (never raises -- a widget's own fetch hiccup falls back to a small placeholder rather than taking the whole panel's render down) and an ACTIONS registry for NEXT/BACK button assignment. Supporting changes needed to give the widget modules something to call, all mechanical/behavior-preserving for every existing caller: - image_pipeline.py: render_panel(regions, ...) generalizes render_frame's tail (paste, enhance once, overlay once, quantize once, pack once) from one photo to N regions -- not a restructuring, since calendar mode's photo-inlay feature already pastes a second composed image onto the canvas before that single shared pipeline runs. - photo_queue.py: advance_forced/back_forced/remove_from_rotation/ get_current take an explicit `frame` param now that `cfg` won't always be the Frame itself once photo-queue state moves to PhotoWidgetConfig -- caught a real latent bug while doing this: get_current was reading refresh_interval_s off `cfg`, but that's a frame-level wake-cadence setting, not something that becomes per-widget, so it now reads that off `frame` explicitly instead. - routers/common.py: list_assets/fetch_source_and_faces take album_id/ display_mode directly instead of a whole Frame (both only ever read that one attribute off it); new get_or_refresh_*_for_widget siblings of the existing calendar/weather/tasks/whiteboard cache helpers, read/ writing the new per-widget config tables -- the Frame-scoped originals are untouched and still what routers/device.py's actual dispatch calls until the Phase 2 cutover. 26 new tests (95 total): render_panel size/placement/orientation coverage, and per-widget-type render/action tests (unconfigured -> placeholder, a fetch failure -> placeholder not a crash, actions mutate the right state). Full suite passes; diff-reviewed to confirm device.py's actual RENDERERS dispatch and the old Frame-scoped get_or_refresh_* bodies are unchanged, so this is safe to deploy on its own despite being step 1 of a two-step cutover (see the project plan on why the *next* step, not this one, has to ship atomically).
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""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
|