diff --git a/display.py b/display.py index f231343..1405c55 100644 --- a/display.py +++ b/display.py @@ -101,6 +101,7 @@ def _fetch_weather(lat: float, lon: float) -> None: hours.append({ 'label': t.strftime('%-I%p').lower(), 'temp': round(hourly['temperature_2m'][i]), + 'desc': _WMO.get(hourly['weather_code'][i], ''), }) with _weather_lock: @@ -185,37 +186,46 @@ 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, available_w: int) -> None: +_WEATHER_COLS = 5 +_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: week = list(_weather.get('week', [])) 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: surface.blit(fonts['tiny'].render('Weather loading…', True, DIM_GRAY), (x, y)) return - # 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))) + # 5-day section + _col(week, + y, + lambda d: 'Today' if d['day'] == 'Today' else d['day'][:3], + lambda d: f"{d['high']}°/{d['low']}°", + lambda d: _trunc(d['desc'])) - # Hourly strip — remaining hours today, two rows (label / temp) + # 5-hour section if hours: - hy = y + 3*(th + 2) + 10 - hw = available_w // min(len(hours[:8]), 8) - for i, h in enumerate(hours[:8]): - 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)) + _col(hours[:_WEATHER_COLS], + y + 3*row + 8, + lambda h: h['label'], + lambda h: f"{h['temp']}°", + lambda h: _trunc(h['desc'])) 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_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 try: @@ -301,7 +311,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, W - 20 - weather_x) + draw_weather(screen, fonts, weather_x, clock_y) draw_dot(screen, W // 2, dot_y) pygame.display.flip()