Extends weather's experimental Chromium+Jinja2 render style to battery, text, tasks, static image, whiteboard, and calendar (all four view modes -- agenda/today_tomorrow/week/month), and gives the photos widget its own genuinely independent palette + dithering strength. Photos: Frame.photo_palette_rgb/photo_dither_strength (mirroring the existing palette_rgb/dither_strength), with a second "Photos configuration" card in Advanced Configuration. widgets/photos.py's render() quantizes itself against these before returning -- no render_panel changes needed, since photos is the only widget that genuinely needs a different reference palette and can carry that itself, the same way modern-style widgets already self-dither via ordered_dither. Battery/text/tasks/static image/whiteboard: same render_style pattern weather established (render_style column, html_render.py build function, Jinja2 template, dialog toggle). Static image/whiteboard get their first-ever visual chrome (a rounded-corner shadowed card, shared framed_image.html.jinja) since classic draws them with zero frame at all. Fixed the same "preview endpoint bypasses render_style" bug weather originally shipped with, for tasks/static/whiteboard/ calendar's preview endpoints. Calendar: own module (app/calendar_html_render.py, mirroring calendar_render.py's separation from the simpler widgets) covering all four view modes, not just agenda -- reuses calendar_render's own private helpers so event colors/times/weather/month-grid math match classic exactly. Found and fixed two real cross-day layout bugs along the way: a per-day header height that varied based on whether that specific day had a weather entry (misaligning where every other day's event rows started across the week/month grid), and regular-weight small text being fragile under Bayer ordered dithering (out-of-month day numbers degraded into unrecognizable speckle) -- fixed by using bold everywhere and de-emphasizing via size instead of weight/gray, since gray text has the same dithering fragility this project's PIL renderers already avoid for exactly this reason. Migrations 32-38 (Frame's two new columns, then one render_style column per widget config table). 452 tests passing, including new dispatch/ migration coverage per widget type and a dedicated photos test proving photo_palette_rgb produces genuinely independent quantization from the frame's main palette_rgb.
104 lines
3.8 KiB
Python
104 lines
3.8 KiB
Python
"""app.widgets.whiteboard -- unit-level, no HTTP: constructs Widget/
|
|
WhiteboardWidgetConfig rows directly and monkeypatches the underlying
|
|
fetch/render call (get_or_refresh_whiteboard_for_widget, already covered
|
|
against a real WebDAV server + mocked sidecar in
|
|
test_whiteboard_refresh_and_browse.py) rather than re-testing that
|
|
throttle/fetch logic here."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import time
|
|
|
|
from PIL import Image
|
|
|
|
from app import widgets
|
|
from app.models import Frame, Widget, WhiteboardWidgetConfig
|
|
|
|
|
|
def _make_widget(db_session, render_style="classic") -> tuple[Frame, Widget]:
|
|
frame = db_session.get(Frame, 1)
|
|
widget = Widget(frame_id=frame.id, widget_type="whiteboard", x=0, y=0, w=8, h=5,
|
|
sort_order=0, created_at=time.time())
|
|
db_session.add(widget)
|
|
db_session.flush()
|
|
db_session.add(WhiteboardWidgetConfig(widget_id=widget.id, url="https://example.com/board.whiteboard",
|
|
render_style=render_style))
|
|
db_session.commit()
|
|
return frame, widget
|
|
|
|
|
|
def _tiny_png() -> bytes:
|
|
buf = io.BytesIO()
|
|
Image.new("RGB", (40, 20), (10, 20, 30)).save(buf, format="PNG")
|
|
return buf.getvalue()
|
|
|
|
|
|
def test_render_unconfigured_widget_returns_correctly_sized_placeholder(db_session):
|
|
frame = db_session.get(Frame, 1)
|
|
widget = Widget(frame_id=frame.id, widget_type="whiteboard", x=0, y=0, w=8, h=5,
|
|
sort_order=0, created_at=time.time())
|
|
db_session.add(widget)
|
|
db_session.flush()
|
|
db_session.add(WhiteboardWidgetConfig(widget_id=widget.id)) # no url/user_id set
|
|
db_session.commit()
|
|
|
|
img = widgets.whiteboard.render(db_session, frame, widget, 300, 200)
|
|
assert img.size == (300, 200)
|
|
|
|
|
|
def test_render_configured_widget_composes_the_fetched_png(db_session, monkeypatch):
|
|
frame, widget = _make_widget(db_session)
|
|
png = _tiny_png()
|
|
monkeypatch.setattr(widgets.whiteboard, "get_or_refresh_whiteboard_for_widget",
|
|
lambda db, frame, widget, force=False: png)
|
|
|
|
img = widgets.whiteboard.render(db_session, frame, widget, 300, 200)
|
|
assert img.size == (300, 200)
|
|
assert img.mode == "RGB"
|
|
|
|
|
|
def test_render_falls_back_to_placeholder_when_nothing_cached_yet(db_session, monkeypatch):
|
|
frame, widget = _make_widget(db_session)
|
|
monkeypatch.setattr(widgets.whiteboard, "get_or_refresh_whiteboard_for_widget",
|
|
lambda db, frame, widget, force=False: None)
|
|
|
|
img = widgets.whiteboard.render(db_session, frame, widget, 300, 200)
|
|
assert img.size == (300, 200)
|
|
|
|
|
|
def test_check_now_action_forces_a_refetch(db_session, monkeypatch):
|
|
frame, widget = _make_widget(db_session)
|
|
calls = []
|
|
|
|
def fake_refresh(db, frame, widget, force=False):
|
|
calls.append(force)
|
|
return _tiny_png()
|
|
|
|
monkeypatch.setattr(widgets.whiteboard, "get_or_refresh_whiteboard_for_widget", fake_refresh)
|
|
widgets.whiteboard.ACTIONS["check_now"](db_session, frame, widget)
|
|
assert calls == [True]
|
|
|
|
|
|
def test_both_buttons_map_to_check_now():
|
|
"""No real "next"/"back" concept for a static board -- both physical
|
|
buttons mean the same thing for a whiteboard widget."""
|
|
assert set(widgets.whiteboard.ACTIONS) == {"check_now"}
|
|
|
|
|
|
def test_render_modern_style(db_session, monkeypatch):
|
|
from app import html_render
|
|
|
|
frame, widget = _make_widget(db_session, render_style="modern")
|
|
monkeypatch.setattr(widgets.whiteboard, "get_or_refresh_whiteboard_for_widget",
|
|
lambda db, frame, widget: _tiny_png())
|
|
|
|
def _stub(html, target_w, target_h):
|
|
return Image.new("RGB", (target_w, target_h), (255, 255, 255))
|
|
|
|
monkeypatch.setattr(html_render, "render_html_to_image", _stub)
|
|
|
|
img = widgets.whiteboard.render(db_session, frame, widget, 300, 200)
|
|
assert img.size == (300, 200)
|
|
assert img.mode == "RGB"
|