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.
This commit is contained in:
ChuckBuilds
2025-04-15 11:31:46 -05:00
parent 97b0b79901
commit 6a796c3794
2 changed files with 27 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ from typing import Dict, Any, List, Tuple
import logging import logging
import math import math
from .weather_icons import WeatherIcons from .weather_icons import WeatherIcons
import os
# Configure logging # Configure logging
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
@@ -129,11 +130,24 @@ class DisplayManager:
self.small_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8) self.small_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
logger.info("Press Start 2P small font loaded successfully") 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: except Exception as e:
logger.error(f"Error in font loading: {e}") logger.error(f"Error in font loading: {e}")
# Fallback to default font # Fallback to default font
self.regular_font = ImageFont.load_default() self.regular_font = ImageFont.load_default()
self.small_font = self.regular_font 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: 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.""" """Draw text on the display with improved clarity."""

View File

@@ -232,12 +232,12 @@ class WeatherManager:
fill=self.COLORS['text']) fill=self.COLORS['text'])
# Draw "time ago" text below condition (using small font) # Draw "time ago" text below condition (using small font)
time_since_update = int((time.time() - self.last_update) / 3600) # hours # time_since_update = int((time.time() - self.last_update) / 3600) # hours
time_text = f"{time_since_update}h" # Even shorter text # 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 # draw.text((icon_x + self.ICON_SIZE['large'] + 1, icon_y + 7), # Reduced from 8
time_text, # time_text,
font=self.display_manager.small_font, # font=self.display_manager.small_font,
fill=self.COLORS['dim']) # Using dimmer color # fill=self.COLORS['dim']) # Using dimmer color
# Draw current temperature on the right (using small font instead of regular) # Draw current temperature on the right (using small font instead of regular)
temp = round(weather_data['main']['temp']) temp = round(weather_data['main']['temp'])
@@ -268,16 +268,16 @@ class WeatherManager:
pressure_text = f"P:{pressure:.1f}in" # Even shorter format pressure_text = f"P:{pressure:.1f}in" # Even shorter format
draw.text((2, y_start), draw.text((2, y_start),
pressure_text, pressure_text,
font=self.display_manager.small_font, font=self.display_manager.extra_small_font,
fill=self.COLORS['dim']) # Using dimmer color fill=self.COLORS['dim'])
# Humidity (shortened format) # Humidity (shortened format)
humidity = weather_data['main']['humidity'] humidity = weather_data['main']['humidity']
humidity_text = f"H:{humidity}%" # Even shorter format humidity_text = f"H:{humidity}%" # Even shorter format
draw.text((2, y_start + spacing), draw.text((2, y_start + spacing),
humidity_text, humidity_text,
font=self.display_manager.small_font, font=self.display_manager.extra_small_font,
fill=self.COLORS['dim']) # Using dimmer color fill=self.COLORS['dim'])
# Wind speed and direction (shortened format) # Wind speed and direction (shortened format)
wind_speed = weather_data['wind']['speed'] 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 wind_text = f"W:{wind_speed:.0f}{wind_dir}" # Even shorter format, removed decimal
draw.text((2, y_start + spacing * 2), draw.text((2, y_start + spacing * 2),
wind_text, wind_text,
font=self.display_manager.small_font, font=self.display_manager.extra_small_font,
fill=self.COLORS['dim']) # Using dimmer color fill=self.COLORS['dim'])
# Update the display # Update the display
self.display_manager.image = image self.display_manager.image = image