Files
Paperwall/screens/clock.py
T
Honey 132e133b1d All screens: drop gray text, matching the Journey fix
The epd4in0e panel's palette has no gray at all (just black/white/
yellow/red/blue/green -- see epd4in0e.py's putpalette), so any gray
RGB fill gets Floyd-Steinberg dithered into a black/white checkerboard
across the whole glyph body. At the small font sizes most of these
screens use (Navidrome's artist/album/genre/source lines, Departures'
direction/platform columns, Weather's description/forecast labels,
Clock's date line, the placeholder messages), that reads as blurry,
half-rendered text -- same root cause already fixed in Journey.

Switched every gray fill/outline to solid black across navidrome.py,
weather.py, departures.py, clock.py, and picture.py. Left the
intentionally-faint row-divider hairlines (228,228,228) alone --
those are meant to almost disappear, not readable text. Removed
departures.py's now-unused MUTED constant.
2026-07-23 11:56:24 +02:00

56 lines
1.9 KiB
Python

"""Simple full-screen clock."""
import time
from PIL import Image, ImageDraw
from screens.base import Screen
from screens.render_utils import load_font, text_width
LINE_GAP = 0.04 # fraction of min(width, height) between the time and date lines
WEEKDAYS_DE = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"]
MONTHS_DE = [
"Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember",
]
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 = f"{WEEKDAYS_DE[now.tm_wday]}, {now.tm_mday}. {MONTHS_DE[now.tm_mon - 1]}"
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