This commit is contained in:
David Rice
2026-04-16 19:44:48 +01:00
parent 4dc34aead8
commit 77fb25bdd9

View File

@@ -101,6 +101,7 @@ def _fetch_weather(lat: float, lon: float) -> None:
hours.append({ hours.append({
'label': t.strftime('%-I%p').lower(), 'label': t.strftime('%-I%p').lower(),
'temp': round(hourly['temperature_2m'][i]), 'temp': round(hourly['temperature_2m'][i]),
'desc': _WMO.get(hourly['weather_code'][i], ''),
}) })
with _weather_lock: with _weather_lock:
@@ -185,37 +186,46 @@ def draw_clock(surface: pygame.Surface, fonts: dict, x: int, y: int) -> None:
# ── Weather panel ───────────────────────────────────────────────────────────── # ── Weather panel ─────────────────────────────────────────────────────────────
def draw_weather(surface: pygame.Surface, fonts: dict, _WEATHER_COLS = 5
x: int, y: int, available_w: int) -> None: _WEATHER_COL_W = 66 # px per column — 5 cols = 330px total
def draw_weather(surface: pygame.Surface, fonts: dict, x: int, y: int) -> None:
with _weather_lock: with _weather_lock:
week = list(_weather.get('week', [])) week = list(_weather.get('week', []))
hours = list(_weather.get('hours', [])) hours = list(_weather.get('hours', []))
th = fonts['tiny'].get_height() th = fonts['tiny'].get_height()
row = th + 2
def _trunc(s, n=11):
return s if len(s) <= n else s[:n-1] + ''
def _col(items, start_y, label_fn, row2_fn, row3_fn):
for i, item in enumerate(items[:_WEATHER_COLS]):
cx = x + i * _WEATHER_COL_W
surface.blit(fonts['tiny'].render(label_fn(item), True, GRAY), (cx, start_y))
surface.blit(fonts['tiny'].render(row2_fn(item), True, WHITE), (cx, start_y + row))
surface.blit(fonts['tiny'].render(row3_fn(item), True, DIM_GRAY), (cx, start_y + 2*row))
if not week: if not week:
surface.blit(fonts['tiny'].render('Weather loading…', True, DIM_GRAY), (x, y)) surface.blit(fonts['tiny'].render('Weather loading…', True, DIM_GRAY), (x, y))
return return
# 5-day columns # 5-day section
days = week[:5] _col(week,
col_w = available_w // len(days) y,
for i, day in enumerate(days): lambda d: 'Today' if d['day'] == 'Today' else d['day'][:3],
cx = x + i * col_w lambda d: f"{d['high']}°/{d['low']}°",
label = 'Today' if i == 0 else day['day'][:3] lambda d: _trunc(d['desc']))
desc = day['desc'] if len(day['desc']) <= 13 else day['desc'][:12] + ''
surface.blit(fonts['tiny'].render(label, True, GRAY), (cx, y))
surface.blit(fonts['tiny'].render(f"{day['high']}°/{day['low']}°", True, WHITE), (cx, y + th + 2))
surface.blit(fonts['tiny'].render(desc, True, DIM_GRAY), (cx, y + 2*(th + 2)))
# Hourly strip — remaining hours today, two rows (label / temp) # 5-hour section
if hours: if hours:
hy = y + 3*(th + 2) + 10 _col(hours[:_WEATHER_COLS],
hw = available_w // min(len(hours[:8]), 8) y + 3*row + 8,
for i, h in enumerate(hours[:8]): lambda h: h['label'],
hx = x + i * hw lambda h: f"{h['temp']}°",
surface.blit(fonts['tiny'].render(h['label'], True, DIM_GRAY), (hx, hy)) lambda h: _trunc(h['desc']))
surface.blit(fonts['tiny'].render(f"{h['temp']}°", True, GRAY), (hx, hy + th + 1))
def draw_dot(surface: pygame.Surface, cx: int, y: int, radius: int = 9) -> None: def draw_dot(surface: pygame.Surface, cx: int, y: int, radius: int = 9) -> None:
@@ -264,7 +274,7 @@ def main() -> None:
clock_block_h = fonts['small'].get_height() + 4 + fonts['large'].get_height() clock_block_h = fonts['small'].get_height() + 4 + fonts['large'].get_height()
clock_y = face_cy - clock_block_h // 2 clock_y = face_cy - clock_block_h // 2
weather_x = face_cx + face_rx + 30 weather_x = W - _WEATHER_COLS * _WEATHER_COL_W - 15
# Resolve postcode and start weather thread # Resolve postcode and start weather thread
try: try:
@@ -301,7 +311,7 @@ def main() -> None:
draw_wireframe_face(screen, face_cx, face_cy, face_rx, face_ry) draw_wireframe_face(screen, face_cx, face_cy, face_rx, face_ry)
draw_clock(screen, fonts, 20, clock_y) draw_clock(screen, fonts, 20, clock_y)
draw_weather(screen, fonts, weather_x, clock_y, W - 20 - weather_x) draw_weather(screen, fonts, weather_x, clock_y)
draw_dot(screen, W // 2, dot_y) draw_dot(screen, W // 2, dot_y)
pygame.display.flip() pygame.display.flip()