From 6a796c37946113821f5f7e3adde58b2b7f141820 Mon Sep 17 00:00:00 2001 From: ChuckBuilds <33324927+ChuckBuilds@users.noreply.github.com> Date: Tue, 15 Apr 2025 11:31:46 -0500 Subject: [PATCH] feat(weather): Adjust layout and use 4x6 font for details Removed "time since update" text. Used 4x6.bdf font for pressure, humidity, and wind speed. --- src/display_manager.py | 16 +++++++++++++++- src/weather_manager.py | 24 ++++++++++++------------ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/display_manager.py b/src/display_manager.py index b0bda9fc..d7b746de 100644 --- a/src/display_manager.py +++ b/src/display_manager.py @@ -5,6 +5,7 @@ from typing import Dict, Any, List, Tuple import logging import math from .weather_icons import WeatherIcons +import os # Configure logging logging.basicConfig(level=logging.INFO) @@ -128,12 +129,25 @@ class DisplayManager: # Use the same font for small text, just at a smaller size self.small_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8) logger.info("Press Start 2P small font loaded successfully") - + + # Add an even smaller font using 4x6.bdf relative to script location + try: + script_dir = os.path.dirname(os.path.abspath(__file__)) + font_path = os.path.join(script_dir, "../assets/fonts/4x6.bdf") + self.extra_small_font = ImageFont.load(font_path) + logger.info(f"4x6.bdf extra small font loaded successfully from {font_path}") + except Exception as font_err: + logger.error(f"Failed to load 4x6.bdf font: {font_err}. Falling back.") + self.extra_small_font = self.regular_font # Use regular as fallback + except Exception as e: logger.error(f"Error in font loading: {e}") # Fallback to default font self.regular_font = ImageFont.load_default() self.small_font = self.regular_font + # Ensure extra_small_font exists even if regular/small fail + if not hasattr(self, 'extra_small_font'): + self.extra_small_font = self.regular_font def draw_text(self, text: str, x: int = None, y: int = None, color: Tuple[int, int, int] = (255, 255, 255), small_font: bool = False) -> None: """Draw text on the display with improved clarity.""" diff --git a/src/weather_manager.py b/src/weather_manager.py index 08e8d288..4242fbdd 100644 --- a/src/weather_manager.py +++ b/src/weather_manager.py @@ -232,12 +232,12 @@ class WeatherManager: fill=self.COLORS['text']) # Draw "time ago" text below condition (using small font) - time_since_update = int((time.time() - self.last_update) / 3600) # hours - time_text = f"{time_since_update}h" # Even shorter text - draw.text((icon_x + self.ICON_SIZE['large'] + 1, icon_y + 7), # Reduced from 8 - time_text, - font=self.display_manager.small_font, - fill=self.COLORS['dim']) # Using dimmer color + # time_since_update = int((time.time() - self.last_update) / 3600) # hours + # time_text = f"{time_since_update}h" # Even shorter text + # draw.text((icon_x + self.ICON_SIZE['large'] + 1, icon_y + 7), # Reduced from 8 + # time_text, + # font=self.display_manager.small_font, + # fill=self.COLORS['dim']) # Using dimmer color # Draw current temperature on the right (using small font instead of regular) temp = round(weather_data['main']['temp']) @@ -268,16 +268,16 @@ class WeatherManager: pressure_text = f"P:{pressure:.1f}in" # Even shorter format draw.text((2, y_start), pressure_text, - font=self.display_manager.small_font, - fill=self.COLORS['dim']) # Using dimmer color + font=self.display_manager.extra_small_font, + fill=self.COLORS['dim']) # Humidity (shortened format) humidity = weather_data['main']['humidity'] humidity_text = f"H:{humidity}%" # Even shorter format draw.text((2, y_start + spacing), humidity_text, - font=self.display_manager.small_font, - fill=self.COLORS['dim']) # Using dimmer color + font=self.display_manager.extra_small_font, + fill=self.COLORS['dim']) # Wind speed and direction (shortened format) wind_speed = weather_data['wind']['speed'] @@ -286,8 +286,8 @@ class WeatherManager: wind_text = f"W:{wind_speed:.0f}{wind_dir}" # Even shorter format, removed decimal draw.text((2, y_start + spacing * 2), wind_text, - font=self.display_manager.small_font, - fill=self.COLORS['dim']) # Using dimmer color + font=self.display_manager.extra_small_font, + fill=self.COLORS['dim']) # Update the display self.display_manager.image = image