Roll out "modern" HTML/CSS render style to every widget except photos
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.
This commit is contained in:
@@ -9,6 +9,8 @@ from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
import pytest
|
||||
|
||||
from app import widgets
|
||||
from app.db import widget_locked
|
||||
from app.models import CalendarWidgetConfig, Frame, Widget
|
||||
@@ -163,3 +165,46 @@ def test_month_view_falls_back_to_agenda_layout_below_small_tier(db_session, mon
|
||||
_stub_fetches(monkeypatch)
|
||||
img = widgets.calendar.render(db_session, frame, widget, 300, 192)
|
||||
assert img.size == (300, 192)
|
||||
|
||||
|
||||
# --- "modern" style (app/calendar_html_render.py) -----------------------
|
||||
# No real browser here -- html_render.render_html_to_image is monkeypatched
|
||||
# to a stub, so these exercise calendar.py's dispatch + calendar_html_
|
||||
# render's own layout/data logic, not Playwright/Chromium itself.
|
||||
|
||||
def _stub_render_html_to_image(monkeypatch):
|
||||
from PIL import Image
|
||||
|
||||
from app import html_render
|
||||
|
||||
monkeypatch.setattr(html_render, "render_html_to_image",
|
||||
lambda html, target_w, target_h: Image.new("RGB", (target_w, target_h), (255, 255, 255)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("view", ["agenda", "today_tomorrow", "week", "month"])
|
||||
def test_render_modern_style_every_view(db_session, monkeypatch, view):
|
||||
"""All four view modes have a modern-style builder (unlike weather's
|
||||
own current/daily-only modern style) -- each must dispatch correctly
|
||||
from calendar.py's render()."""
|
||||
frame, widget = _make_widget(db_session, view=view, render_style="modern")
|
||||
events = [{"summary": "Standup", "start": "2026-07-31T09:00:00+00:00",
|
||||
"end": "2026-07-31T09:30:00+00:00", "all_day": False,
|
||||
"sources": [{"owner_display_name": "Alice", "color_index": None}]}]
|
||||
_stub_fetches(monkeypatch, events=events)
|
||||
_stub_render_html_to_image(monkeypatch)
|
||||
|
||||
img = widgets.calendar.render(db_session, frame, widget, 380, 300)
|
||||
assert img.size == (380, 300)
|
||||
assert img.mode == "RGB"
|
||||
|
||||
|
||||
def test_render_modern_month_falls_back_to_agenda_below_small_tier(db_session, monkeypatch):
|
||||
"""Same "month needs real column width" fallback classic has (see
|
||||
test_month_view_falls_back_to_agenda_layout_below_small_tier above),
|
||||
still honored when render_style is modern."""
|
||||
frame, widget = _make_widget(db_session, view="month", render_style="modern")
|
||||
_stub_fetches(monkeypatch)
|
||||
_stub_render_html_to_image(monkeypatch)
|
||||
|
||||
img = widgets.calendar.render(db_session, frame, widget, 300, 192)
|
||||
assert img.size == (300, 192)
|
||||
|
||||
Reference in New Issue
Block a user