device.py's mode-keyed dispatch is replaced by a real compositor: load a frame's widgets, compute pixel rects via app/grid.py, render each through its widget module, and composite with render_panel. Physical NEXT/BACK buttons now execute each frame's assigned FrameButtonAction rows instead of one hardcoded per-mode action. api_frames.py, manage.py, and common.py's build_manage_content are repointed to read/write the frame's widget config rows instead of the old Frame columns, and every settings page (Photos/Calendar/ Whiteboard tabs) now pre-fills its form from the same widget config the write endpoints actually save to -- previously the read and write sides would have silently diverged. The old mode selector and photo-inlay checkbox are removed along with their now-inert wiring; arbitrary widget placement subsumes what the fixed inlay split did. Ships together with Phase 1 (per-type render/action modules) since splitting the read/write cutover across deploys would have left settings changes with no visible effect.
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
"""Whiteboard widget: fetches/renders a Nextcloud Whiteboard (or any
|
|
WebDAV .whiteboard file) into the widget's own region -- the
|
|
widget-system analogue of routers/device.py's old
|
|
_render_whiteboard_mode/_advance_whiteboard_mode/_back_whiteboard_mode.
|
|
|
|
No real "next"/"back" concept for a static board (same as before the
|
|
widget system) -- both buttons map to the same "check now" action, a
|
|
forced re-fetch/re-render bypassing the normal throttle."""
|
|
|
|
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, Widget
|
|
from ..routers.common import get_or_refresh_whiteboard_for_widget
|
|
from ._shared import placeholder_image
|
|
|
|
ACTION_LABELS = {"check_now": "Check for updates"}
|
|
|
|
|
|
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 here -- see app/widgets/photos.py's
|
|
identical note; every widget type's render() shares one call
|
|
signature regardless of which ones actually care."""
|
|
png_bytes = get_or_refresh_whiteboard_for_widget(db, frame, widget)
|
|
if png_bytes is None:
|
|
return placeholder_image(target_w, target_h, ["Whiteboard widget", "not configured yet"])
|
|
|
|
source = Image.open(io.BytesIO(png_bytes)).convert("RGB")
|
|
# letterbox, never cropped: unlike a photo, losing part of a
|
|
# whiteboard to a crop loses actual content, not just some background
|
|
# (see the old _render_whiteboard_mode's identical reasoning).
|
|
return compose_into(source, faces=None, target_w=target_w, target_h=target_h, display_mode="letterbox")
|
|
|
|
|
|
def _check_now(db: Session, frame: Frame, widget: Widget) -> None:
|
|
get_or_refresh_whiteboard_for_widget(db, frame, widget, force=True)
|
|
|
|
|
|
ACTIONS = {"check_now": _check_now}
|