A new widget type showing a single user-uploaded image with no live upstream to poll -- decoded once at upload time (PDF's first page via pypdfium2, BSD-3-Clause/Apache-2.0, no copyleft exposure) into plain RGB PNG bytes, then composed per a crop/stretch/letterbox display mode like the photos widget.
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
"""Static image widget: shows whatever image the user last uploaded
|
|
(routers/api_widgets.py's api_widget_static_upload already decoded
|
|
PNG/JPEG/GIF/PDF/etc. into plain RGB PNG bytes at upload time, see
|
|
app/image_upload.py and models.StaticWidgetConfig) -- no live upstream
|
|
to fetch, so render() is just a decode + compose_into, the simplest of
|
|
every widget type's render().
|
|
|
|
No button actions -- there's nothing to advance/back/check for a fixed
|
|
uploaded image."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
|
|
from PIL import Image
|
|
from sqlalchemy.orm import Session
|
|
|
|
from ..image_pipeline import compose_into
|
|
from ..models import Frame, StaticWidgetConfig, Widget
|
|
from ._shared import placeholder_image
|
|
|
|
ACTIONS: dict = {}
|
|
ACTION_LABELS: dict[str, str] = {}
|
|
|
|
|
|
def render(db: Session, frame: Frame, widget: Widget, target_w: int, target_h: int,
|
|
is_normal_wake: bool = True) -> Image.Image:
|
|
"""is_normal_wake is unused -- see app/widgets/whiteboard.py's
|
|
identical note; every widget type's render() shares one call
|
|
signature regardless of which ones actually care."""
|
|
cfg = db.get(StaticWidgetConfig, widget.id)
|
|
if not cfg.image:
|
|
return placeholder_image(target_w, target_h, ["Static image widget", "not configured yet"])
|
|
source = Image.open(io.BytesIO(cfg.image)).convert("RGB")
|
|
return compose_into(source, faces=None, target_w=target_w, target_h=target_h, display_mode=cfg.display_mode)
|