Update weather_manager.py

changed the way it displays to be more readable
This commit is contained in:
Chuck
2025-04-08 17:57:37 -05:00
parent 9573e4409b
commit eeb8e21564

View File

@@ -170,87 +170,110 @@ class WeatherManager:
if not self.hourly_forecast: if not self.hourly_forecast:
return return
# Update scroll position # Always clear when drawing hourly forecast to prevent ghosting
self.scroll_position = scroll_amount self.display_manager.clear()
# Create the full scrolling text with icons # Calculate base positions
forecasts = [] display_width = self.display_manager.matrix.width
icons = [] display_height = self.display_manager.matrix.height
x_offset = self.display_manager.matrix.width - scroll_amount forecast_width = display_width // 2 # Each forecast takes half the width
icon_size = 16 icon_size = 12 # Slightly smaller icons for better fit
# Create the forecast display
for i, forecast in enumerate(self.hourly_forecast): for i, forecast in enumerate(self.hourly_forecast):
# Add text # Calculate x position with scrolling
forecasts.append(f"{forecast['hour']}\n{forecast['temp']}°F") x_pos = display_width - scroll_amount + (i * forecast_width)
# Calculate icon position # Only draw if the forecast would be visible
icon_x = x_offset + (i * (icon_size * 3)) # Space icons out if x_pos < -forecast_width or x_pos > display_width:
icon_y = 2 # Near top continue
icons.append((forecast['condition'], icon_x, icon_y))
# Join with spacing # Draw icon at top
display_text = " | ".join(forecasts) icon_x = x_pos + (forecast_width - icon_size) // 2
icon_y = 2
# Draw everything self.display_manager.draw_weather_icon(forecast['condition'], icon_x, icon_y, size=icon_size)
self.display_manager.draw_text_with_icons(
display_text, # Draw hour below icon
icons=icons, hour_text = forecast['hour']
x=x_offset, hour_y = icon_y + icon_size + 2
force_clear=force_clear self.display_manager.draw_text(
) hour_text,
x=x_pos + forecast_width // 2, # Center in section
y=hour_y,
small_font=True
)
# Draw temperature at bottom
temp_text = f"{forecast['temp']}°"
temp_y = display_height - 8 # 8 pixels from bottom
self.display_manager.draw_text(
temp_text,
x=x_pos + forecast_width // 2, # Center in section
y=temp_y,
small_font=True
)
# Draw separator line if not last forecast
if i < len(self.hourly_forecast) - 1:
sep_x = x_pos + forecast_width - 1
if 0 <= sep_x <= display_width:
self.display_manager.draw.line(
[(sep_x, 0), (sep_x, display_height)],
fill=(64, 64, 64) # Dim gray line
)
def display_daily_forecast(self, force_clear: bool = False) -> None: def display_daily_forecast(self, force_clear: bool = False) -> None:
"""Display 3-day forecast information.""" """Display 3-day forecast information."""
if not self.daily_forecast: if not self.daily_forecast:
self.get_weather() # This will also update forecasts self.get_weather()
if not self.daily_forecast: if not self.daily_forecast:
return return
# Always clear when drawing daily forecast
self.display_manager.clear()
# Calculate layout parameters # Calculate layout parameters
display_width = self.display_manager.matrix.width display_width = self.display_manager.matrix.width
display_height = self.display_manager.matrix.height display_height = self.display_manager.matrix.height
day_width = display_width // 3 # Divide screen into 3 equal sections section_width = display_width // 3 # Width for each day
icon_size = 16 icon_size = 12 # Smaller icons for better fit
padding = 4 # Padding between elements
# Create text lines and collect icon information
lines = []
icons = []
for i, day in enumerate(self.daily_forecast): for i, day in enumerate(self.daily_forecast):
# Calculate horizontal position for this day # Calculate base x position for this section
x_offset = i * day_width x_base = i * section_width
# Format the day, date, and temperature # Draw day name at top (e.g., "MON")
day_str = day['date'] # Day name (Mon, Tue, etc.) day_text = day['date'].upper()
date_str = day['date_str'] # Date (4/8, 4/9, etc.) self.display_manager.draw_text(
temp_str = f"{day['temp_low']}°F / {day['temp_high']}°F" day_text,
x=x_base + section_width // 2, # Center in section
# Position the text and icon y=2, # Near top
text_x = x_offset + (day_width // 2) # Center text horizontally small_font=True
day_y = padding # Day name at the top )
date_y = day_y + 10 # Date below the day name
temp_y = display_height - padding - 10 # Temperature at the bottom
# Position icon in the middle
icon_x = x_offset + (day_width // 2) - (icon_size // 2)
icon_y = (display_height // 2) - (icon_size // 2)
# Add the formatted lines
lines.append((day_str, text_x, day_y))
lines.append((date_str, text_x, date_y))
lines.append((temp_str, text_x, temp_y))
# Add icon position
icons.append((day['condition'], icon_x, icon_y))
# Draw everything # Draw weather icon in middle
self.display_manager.draw_text_with_icons( icon_x = x_base + (section_width - icon_size) // 2
"", # Empty text as we'll draw lines manually icon_y = (display_height - icon_size) // 2
icons=icons, self.display_manager.draw_weather_icon(
force_clear=force_clear day['condition'],
) icon_x,
icon_y,
# Draw each line of text size=icon_size
for text, x, y in lines: )
self.display_manager.draw_text(text, x=x, y=y, force_clear=False)
# Draw temperature at bottom (e.g., "45°/65°")
temp_text = f"{day['temp_low']}°/{day['temp_high']}°"
self.display_manager.draw_text(
temp_text,
x=x_base + section_width // 2, # Center in section
y=display_height - 8, # 8 pixels from bottom
small_font=True
)
# Draw separator line if not last day
if i < len(self.daily_forecast) - 1:
sep_x = x_base + section_width - 1
self.display_manager.draw.line(
[(sep_x, 0), (sep_x, display_height)],
fill=(64, 64, 64) # Dim gray line
)