mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 13:02:59 +00:00
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:
@@ -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."""
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user