This commit is contained in:
David Rice
2026-04-16 19:38:03 +01:00
parent bf62a8dd8d
commit 4dc34aead8

View File

@@ -185,36 +185,37 @@ def draw_clock(surface: pygame.Surface, fonts: dict, x: int, y: int) -> None:
# ── Weather panel ─────────────────────────────────────────────────────────────
def draw_weather(surface: pygame.Surface, fonts: dict, x: int, y: int) -> None:
def draw_weather(surface: pygame.Surface, fonts: dict,
x: int, y: int, available_w: int) -> None:
with _weather_lock:
week = list(_weather.get('week', []))
hours = list(_weather.get('hours', []))
sh = fonts['small'].get_height()
lh = fonts['large'].get_height()
th = fonts['tiny'].get_height()
if not week:
surface.blit(fonts['small'].render('Weather loading…', True, DIM_GRAY), (x, y))
surface.blit(fonts['tiny'].render('Weather loading…', True, DIM_GRAY), (x, y))
return
# Rotate through the 7 days every 4 seconds
day = week[int(_time.time() / 4) % len(week)]
# 5-day columns
days = week[:5]
col_w = available_w // len(days)
for i, day in enumerate(days):
cx = x + i * col_w
label = 'Today' if i == 0 else day['day'][:3]
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)))
surface.blit(fonts['small'].render(f"{day['day']} {day['date']}", True, GRAY), (x, y))
t_surf = fonts['large'].render(f"{day['high']}° / {day['low']}°", True, WHITE)
ty = y + sh + 4
surface.blit(t_surf, (x, ty))
surface.blit(fonts['small'].render(day['desc'], True, GRAY), (x, ty + lh + 3))
# Hourly strip for today — next 8 hours, displayed as "2pm 14° 3pm 13° …"
# Hourly strip — remaining hours today, two rows (label / temp)
if hours:
strip_y = ty + lh + 3 + sh + 8
col_w = 52
hy = y + 3*(th + 2) + 10
hw = available_w // min(len(hours[:8]), 8)
for i, h in enumerate(hours[:8]):
hx = x + i * col_w
surface.blit(fonts['small'].render(h['label'], True, DIM_GRAY), (hx, strip_y))
surface.blit(fonts['small'].render(f"{h['temp']}°", True, GRAY),
(hx, strip_y + sh + 1))
hx = x + i * hw
surface.blit(fonts['tiny'].render(h['label'], True, DIM_GRAY), (hx, hy))
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:
@@ -252,6 +253,7 @@ def main() -> None:
fonts = {
'large': _load_font(38),
'small': _load_font(13),
'tiny': _load_font(11),
}
face_rx = int(min(W, H) * 0.085)
@@ -299,7 +301,7 @@ def main() -> None:
draw_wireframe_face(screen, face_cx, face_cy, face_rx, face_ry)
draw_clock(screen, fonts, 20, clock_y)
draw_weather(screen, fonts, weather_x, clock_y)
draw_weather(screen, fonts, weather_x, clock_y, W - 20 - weather_x)
draw_dot(screen, W // 2, dot_y)
pygame.display.flip()