Frame.theme (7 presets in app/theme_tokens.py) drives font family, corner radius, drop shadow, and an accent hue for every modern-style widget's header/accent region. Rich accent colors (not just the 6 flat panel inks) are approximated via denser Bayer stippling confined to just that region (html_render.ordered_dither_regions), so icon/text content elsewhere stays exactly as crisp as it is today -- verified directly against real Chromium renders, both in unit tests and via run-server. "classic" is a byte-identical no-visual-change default: weather's header keeps its original fixed blue gradient, tasks/calendar keep their flat THEME_* ink. Themes are purely stylistic -- battery's charge-level color, calendar/ tasks' per-owner event chips, and text's own per-widget font choice are never touched.
56 lines
2.4 KiB
Python
56 lines
2.4 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, WhiteboardWidgetConfig
|
|
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).
|
|
composed = compose_into(source, faces=None, target_w=target_w, target_h=target_h, display_mode="letterbox")
|
|
cfg = db.get(WhiteboardWidgetConfig, widget.id)
|
|
if cfg and cfg.render_style == "modern":
|
|
# Local import: html_render pulls in Playwright, a real headless-
|
|
# Chromium dependency -- every other widget type, and this one's
|
|
# own classic path, should never pay for it.
|
|
from .. import html_render
|
|
|
|
return html_render.build_framed_image(composed, target_w, target_h, frame.palette_rgb, frame.theme,
|
|
"whiteboard")
|
|
return composed
|
|
|
|
|
|
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}
|