fuckwit
This commit is contained in:
42
display.py
42
display.py
@@ -185,36 +185,37 @@ 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, x: int, y: int) -> None:
|
def draw_weather(surface: pygame.Surface, fonts: dict,
|
||||||
|
x: int, y: int, available_w: 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', []))
|
||||||
|
|
||||||
sh = fonts['small'].get_height()
|
th = fonts['tiny'].get_height()
|
||||||
lh = fonts['large'].get_height()
|
|
||||||
|
|
||||||
if not week:
|
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
|
return
|
||||||
|
|
||||||
# Rotate through the 7 days every 4 seconds
|
# 5-day columns
|
||||||
day = week[int(_time.time() / 4) % len(week)]
|
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))
|
# Hourly strip — remaining hours today, two rows (label / temp)
|
||||||
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° …"
|
|
||||||
if hours:
|
if hours:
|
||||||
strip_y = ty + lh + 3 + sh + 8
|
hy = y + 3*(th + 2) + 10
|
||||||
col_w = 52
|
hw = available_w // min(len(hours[:8]), 8)
|
||||||
for i, h in enumerate(hours[:8]):
|
for i, h in enumerate(hours[:8]):
|
||||||
hx = x + i * col_w
|
hx = x + i * hw
|
||||||
surface.blit(fonts['small'].render(h['label'], True, DIM_GRAY), (hx, strip_y))
|
surface.blit(fonts['tiny'].render(h['label'], True, DIM_GRAY), (hx, hy))
|
||||||
surface.blit(fonts['small'].render(f"{h['temp']}°", True, GRAY),
|
surface.blit(fonts['tiny'].render(f"{h['temp']}°", True, GRAY), (hx, hy + th + 1))
|
||||||
(hx, strip_y + sh + 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:
|
||||||
@@ -252,6 +253,7 @@ def main() -> None:
|
|||||||
fonts = {
|
fonts = {
|
||||||
'large': _load_font(38),
|
'large': _load_font(38),
|
||||||
'small': _load_font(13),
|
'small': _load_font(13),
|
||||||
|
'tiny': _load_font(11),
|
||||||
}
|
}
|
||||||
|
|
||||||
face_rx = int(min(W, H) * 0.085)
|
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_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)
|
draw_weather(screen, fonts, weather_x, clock_y, W - 20 - weather_x)
|
||||||
draw_dot(screen, W // 2, dot_y)
|
draw_dot(screen, W // 2, dot_y)
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|||||||
Reference in New Issue
Block a user