Limit daily forecast to 3 days and adjust spacing

This commit is contained in:
ChuckBuilds
2025-04-17 09:10:21 -05:00
parent 8092148adc
commit bfb2f50942

View File

@@ -149,8 +149,8 @@ class WeatherManager:
# Sort data by date to ensure chronological order # Sort data by date to ensure chronological order
sorted_daily_items = sorted(daily_data.items(), key=lambda item: item[1]['date']) sorted_daily_items = sorted(daily_data.items(), key=lambda item: item[1]['date'])
# Filter out today's data and take the next 4 days # Filter out today's data and take the next 3 days
future_days_data = [item for item in sorted_daily_items if item[0] != today_str][:4] future_days_data = [item for item in sorted_daily_items if item[0] != today_str][:3]
for date_str, data in future_days_data: for date_str, data in future_days_data:
temps = data['temps'] temps = data['temps']
@@ -401,39 +401,43 @@ class WeatherManager:
image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height)) image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height))
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
# Calculate layout based on matrix dimensions # Calculate layout based on matrix dimensions for 3 days
days_to_show = min(4, len(self.daily_forecast)) days_to_show = min(3, len(self.daily_forecast)) # Changed from 4 to 3
total_width = self.display_manager.matrix.width if days_to_show == 0:
section_width = total_width // days_to_show # Handle case where there's no forecast data after filtering
padding = max(2, section_width // 6) # Increased padding for more space draw.text((2, 2), "No daily forecast", font=self.display_manager.small_font, fill=self.COLORS['dim'])
else:
for i in range(days_to_show): total_width = self.display_manager.matrix.width
forecast = self.daily_forecast[i] section_width = total_width // days_to_show # Divide by 3 (or fewer if less data)
x = i * section_width + padding padding = max(2, section_width // 6)
center_x = x + (section_width - 2 * padding) // 2
# Draw day name at top for i in range(days_to_show):
day_text = forecast['date'] forecast = self.daily_forecast[i]
day_width = draw.textlength(day_text, font=self.display_manager.small_font) x = i * section_width # No need for padding here, centering handles spacing
draw.text((center_x - day_width // 2, 1), center_x = x + section_width // 2 # Center within the section
day_text,
font=self.display_manager.small_font, # Draw day name at top
fill=self.COLORS['extra_dim']) day_text = forecast['date']
day_width = draw.textlength(day_text, font=self.display_manager.small_font)
# Draw weather icon in middle draw.text((center_x - day_width // 2, 1),
icon_size = self.ICON_SIZE['medium'] day_text,
icon_y = self.display_manager.matrix.height // 3 # Position icon in upper third font=self.display_manager.small_font,
icon_x = center_x - icon_size // 2 fill=self.COLORS['extra_dim'])
WeatherIcons.draw_weather_icon(draw, forecast['condition'], icon_x, icon_y, icon_size)
# Draw weather icon in middle
# Draw high/low temperatures at bottom icon_size = self.ICON_SIZE['medium']
temp_text = f"{forecast['temp_low']}°/{forecast['temp_high']}°" icon_y = self.display_manager.matrix.height // 3 # Position icon in upper third
temp_width = draw.textlength(temp_text, font=self.display_manager.extra_small_font) icon_x = center_x - icon_size // 2
temp_y = self.display_manager.matrix.height - 8 # Position at bottom with small margin WeatherIcons.draw_weather_icon(draw, forecast['condition'], icon_x, icon_y, icon_size)
draw.text((center_x - temp_width // 2, temp_y),
temp_text, # Draw high/low temperatures at bottom
font=self.display_manager.extra_small_font, temp_text = f"{forecast['temp_low']}°/{forecast['temp_high']}°"
fill=self.COLORS['text']) temp_width = draw.textlength(temp_text, font=self.display_manager.extra_small_font)
temp_y = self.display_manager.matrix.height - 8 # Position at bottom with small margin
draw.text((center_x - temp_width // 2, temp_y),
temp_text,
font=self.display_manager.extra_small_font,
fill=self.COLORS['text'])
# Update the display # Update the display
self.display_manager.image = image self.display_manager.image = image