Week view: relative start-day offset for non-7-day counts; hide week-only settings elsewhere
Build and push server image / build-and-push (push) Successful in 53s
Build and push server image / build-and-push (push) Successful in 53s
calendar_week_start's fixed-weekday anchor ("start on the most recent
Monday") stops making sense once the view isn't a literal calendar
week, so a non-7-day week view now starts calendar_week_start_offset
days from today instead (0 = starts today, negative/positive = past/
future) -- calendar_week_start still governs at the default 7 days,
unchanged.
Also hides the Calendar tab's week-only fields (days to show, layout,
start offset) unless View is actually set to Week, and further hides
the new start-offset field specifically when Days to show is 7 (where
it has no effect). "Week starts on" stays visible for Month too, since
it actually still applies there.
This commit is contained in:
@@ -642,7 +642,8 @@ def _build_today_tomorrow(events: list[dict], browse_offset: int, orientation: s
|
||||
def _build_week(events: list[dict], browse_offset: int, orientation: str, tz: ZoneInfo,
|
||||
photo_inlay: Image.Image | None, week_start: int, palette_rgb: list | None = None,
|
||||
weather_cities: list[dict] | None = None, weather_units: str = "fahrenheit",
|
||||
days: int = 7, layout: str = "horizontal", tasks: list[dict] | None = None) -> Image.Image:
|
||||
days: int = 7, layout: str = "horizontal", tasks: list[dict] | None = None,
|
||||
start_offset: int = 0) -> Image.Image:
|
||||
"""`days` (2-10, see routers/api_frames.py's clamp) side-by-side
|
||||
columns (layout="horizontal", the original fixed-at-7 behavior
|
||||
generalized) or stacked bands (layout="vertical", reusing
|
||||
@@ -650,7 +651,13 @@ def _build_week(events: list[dict], browse_offset: int, orientation: str, tz: Zo
|
||||
an arbitrary day count instead of a hardcoded 2). `tasks` (see
|
||||
routers/common.py's get_or_refresh_tasks), if not None, takes the
|
||||
LAST slot instead of adding an extra one -- "N days" always means N
|
||||
slots total, whether they're all days or N-1 days plus a task list."""
|
||||
slots total, whether they're all days or N-1 days plus a task list.
|
||||
|
||||
At the default 7 days, the view anchors to week_start (a fixed
|
||||
weekday, "start on the most recent Monday") exactly like before --
|
||||
otherwise "start of the week" doesn't mean much for an arbitrary day
|
||||
count, so it instead starts `start_offset` days from today (0 =
|
||||
today, see routers/api_frames.py's api_config_save)."""
|
||||
logical_w, logical_h = logical_render_size(orientation)
|
||||
img = Image.new("RGB", (logical_w, logical_h), BG)
|
||||
if photo_inlay is not None:
|
||||
@@ -659,8 +666,11 @@ def _build_week(events: list[dict], browse_offset: int, orientation: str, tz: Zo
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
today = datetime.now(tz).date()
|
||||
days_since_start = (today.weekday() - week_start) % 7
|
||||
week_first_day = today - timedelta(days=days_since_start) + timedelta(days=days * browse_offset)
|
||||
if days == 7:
|
||||
days_since_start = (today.weekday() - week_start) % 7
|
||||
week_first_day = today - timedelta(days=days_since_start) + timedelta(days=days * browse_offset)
|
||||
else:
|
||||
week_first_day = today + timedelta(days=start_offset) + timedelta(days=days * browse_offset)
|
||||
day_count = days - 1 if tasks is not None else days
|
||||
owners_seen: list[str] = []
|
||||
|
||||
@@ -802,7 +812,8 @@ def _build(events: list[dict], view: str, browse_offset: int, orientation: str,
|
||||
photo_inlay: Image.Image | None, fetch_summary: str, week_start: int,
|
||||
palette_rgb: list | None = None,
|
||||
weather_cities: list[dict] | None = None, weather_units: str = "fahrenheit",
|
||||
week_days: int = 7, week_layout: str = "horizontal", tasks: list[dict] | None = None) -> Image.Image:
|
||||
week_days: int = 7, week_layout: str = "horizontal", tasks: list[dict] | None = None,
|
||||
week_start_offset: int = 0) -> Image.Image:
|
||||
tz = ZoneInfo(timezone) if timezone else ZoneInfo("UTC")
|
||||
if view == "agenda":
|
||||
img = _build_agenda(events, browse_offset, orientation, tz, photo_inlay, palette_rgb,
|
||||
@@ -812,7 +823,7 @@ def _build(events: list[dict], view: str, browse_offset: int, orientation: str,
|
||||
weather_cities, weather_units)
|
||||
elif view == "week":
|
||||
img = _build_week(events, browse_offset, orientation, tz, photo_inlay, week_start, palette_rgb,
|
||||
weather_cities, weather_units, week_days, week_layout, tasks)
|
||||
weather_cities, weather_units, week_days, week_layout, tasks, week_start_offset)
|
||||
elif view == "month":
|
||||
# Never given weather or tasks -- no room for either at typical
|
||||
# month-cell size, same reasoning that already keeps this view
|
||||
@@ -839,7 +850,7 @@ def render_calendar(events: list[dict], view: str, browse_offset: int, orientati
|
||||
fetch_summary: str = "", manage: dict | None = None, week_start: int = 0,
|
||||
weather_cities: list[dict] | None = None, weather_units: str = "fahrenheit",
|
||||
week_days: int = 7, week_layout: str = "horizontal",
|
||||
tasks: list[dict] | None = None) -> bytes:
|
||||
tasks: list[dict] | None = None, week_start_offset: int = 0) -> bytes:
|
||||
"""Renders one of CALENDAR_VIEWS to the panel's packed format. Always
|
||||
returns exactly EPD_WIDTH*EPD_HEIGHT/2 bytes, same invariant every
|
||||
other renderer honors. weather_cities is routers/common.py's
|
||||
@@ -848,7 +859,7 @@ def render_calendar(events: list[dict], view: str, browse_offset: int, orientati
|
||||
get_or_refresh_tasks()'s cache, or None to omit the task list
|
||||
entirely -- only ever drawn for view == "week", see _build_week."""
|
||||
img = _build(events, view, browse_offset, orientation, timezone, photo_inlay, fetch_summary, week_start,
|
||||
palette_rgb, weather_cities, weather_units, week_days, week_layout, tasks)
|
||||
palette_rgb, weather_cities, weather_units, week_days, week_layout, tasks, week_start_offset)
|
||||
img = _apply_manage_overlay(img, manage)
|
||||
quantized = _quantize(img, palette_rgb, dither_strength=1.0)
|
||||
return _transpose_and_pack(quantized, orientation)
|
||||
@@ -859,12 +870,12 @@ def render_calendar_preview_png(events: list[dict], view: str, browse_offset: in
|
||||
fetch_summary: str = "", manage: dict | None = None, week_start: int = 0,
|
||||
weather_cities: list[dict] | None = None, weather_units: str = "fahrenheit",
|
||||
week_days: int = 7, week_layout: str = "horizontal",
|
||||
tasks: list[dict] | None = None) -> bytes:
|
||||
tasks: list[dict] | None = None, week_start_offset: int = 0) -> bytes:
|
||||
"""Same pipeline as render_calendar, but a normal browser-viewable
|
||||
PNG in logical (upright) orientation -- mirrors
|
||||
image_pipeline.render_preview_png's relationship to render_frame."""
|
||||
img = _build(events, view, browse_offset, orientation, timezone, photo_inlay, fetch_summary, week_start,
|
||||
palette_rgb, weather_cities, weather_units, week_days, week_layout, tasks)
|
||||
palette_rgb, weather_cities, weather_units, week_days, week_layout, tasks, week_start_offset)
|
||||
img = _apply_manage_overlay(img, manage)
|
||||
quantized = _quantize(img, palette_rgb, dither_strength=1.0)
|
||||
buf = io.BytesIO()
|
||||
|
||||
Reference in New Issue
Block a user