- forecast_days now defaults to 5 (was 3) across default_settings(),
check()'s fallback, and the settings form's pre-selected option.
- New show_date setting (on by default): weekday + date in the same
"Samstag, 25. Juli" format Clock already used. Combined with the
city name into one header line above the icon/temp block when both
are on ("Münster · Samstag, 25. Juli"), each independently
toggleable.
- Moved the weekday/month name lists and the "Weekday, D. Month"
formatting out of clock.py into render_utils.format_date_de(), so
Weather reuses the exact same formatting instead of a second copy
that could drift.
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""Simple full-screen clock."""
|
|
|
|
import time
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
from screens.base import Screen
|
|
from screens.render_utils import format_date_de, load_font, text_width
|
|
|
|
LINE_GAP = 0.04 # fraction of min(width, height) between the time and date lines
|
|
|
|
|
|
class ClockScreen(Screen):
|
|
id = "clock"
|
|
display_name = "Clock"
|
|
poll_interval = 30
|
|
|
|
def check(self, settings: dict):
|
|
return time.strftime("%H:%M")
|
|
|
|
def render(self, state, settings: dict, resolution: tuple[int, int]) -> Image.Image:
|
|
width, height = resolution
|
|
image = Image.new("RGB", (width, height), "white")
|
|
draw = ImageDraw.Draw(image)
|
|
|
|
now = time.localtime()
|
|
time_str = state or time.strftime("%H:%M", now)
|
|
date_str = format_date_de(now)
|
|
|
|
scale = min(width, height)
|
|
time_font = load_font(size=int(scale * 0.32), bold=True)
|
|
date_font = load_font(size=int(scale * 0.06))
|
|
gap = int(scale * LINE_GAP)
|
|
|
|
time_left, time_top, time_right, time_bottom = draw.textbbox((0, 0), time_str, font=time_font)
|
|
time_h = time_bottom - time_top
|
|
date_left, date_top, date_right, date_bottom = draw.textbbox((0, 0), date_str, font=date_font)
|
|
date_h = date_bottom - date_top
|
|
|
|
block_h = time_h + gap + date_h
|
|
block_top = (height - block_h) / 2
|
|
|
|
tw = time_right - time_left
|
|
draw.text(((width - tw) / 2, block_top - time_top), time_str, font=time_font, fill="black")
|
|
|
|
dw = date_right - date_left
|
|
draw.text(((width - dw) / 2, block_top + time_h + gap - date_top), date_str, font=date_font, fill="black")
|
|
|
|
return image
|