mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 13:23:00 +00:00
Update weather_manager.py
changed the way it displays to be more readable
This commit is contained in:
@@ -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
|
||||||
|
self.display_manager.draw_weather_icon(forecast['condition'], icon_x, icon_y, size=icon_size)
|
||||||
|
|
||||||
# Draw everything
|
# Draw hour below icon
|
||||||
self.display_manager.draw_text_with_icons(
|
hour_text = forecast['hour']
|
||||||
display_text,
|
hour_y = icon_y + icon_size + 2
|
||||||
icons=icons,
|
self.display_manager.draw_text(
|
||||||
x=x_offset,
|
hour_text,
|
||||||
force_clear=force_clear
|
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
|
||||||
|
y=2, # Near top
|
||||||
|
small_font=True
|
||||||
|
)
|
||||||
|
|
||||||
# Position the text and icon
|
# Draw weather icon in middle
|
||||||
text_x = x_offset + (day_width // 2) # Center text horizontally
|
icon_x = x_base + (section_width - icon_size) // 2
|
||||||
day_y = padding # Day name at the top
|
icon_y = (display_height - icon_size) // 2
|
||||||
date_y = day_y + 10 # Date below the day name
|
self.display_manager.draw_weather_icon(
|
||||||
temp_y = display_height - padding - 10 # Temperature at the bottom
|
day['condition'],
|
||||||
|
icon_x,
|
||||||
|
icon_y,
|
||||||
|
size=icon_size
|
||||||
|
)
|
||||||
|
|
||||||
# Position icon in the middle
|
# Draw temperature at bottom (e.g., "45°/65°")
|
||||||
icon_x = x_offset + (day_width // 2) - (icon_size // 2)
|
temp_text = f"{day['temp_low']}°/{day['temp_high']}°"
|
||||||
icon_y = (display_height // 2) - (icon_size // 2)
|
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
|
||||||
|
)
|
||||||
|
|
||||||
# Add the formatted lines
|
# Draw separator line if not last day
|
||||||
lines.append((day_str, text_x, day_y))
|
if i < len(self.daily_forecast) - 1:
|
||||||
lines.append((date_str, text_x, date_y))
|
sep_x = x_base + section_width - 1
|
||||||
lines.append((temp_str, text_x, temp_y))
|
self.display_manager.draw.line(
|
||||||
|
[(sep_x, 0), (sep_x, display_height)],
|
||||||
# Add icon position
|
fill=(64, 64, 64) # Dim gray line
|
||||||
icons.append((day['condition'], icon_x, icon_y))
|
)
|
||||||
|
|
||||||
# Draw everything
|
|
||||||
self.display_manager.draw_text_with_icons(
|
|
||||||
"", # Empty text as we'll draw lines manually
|
|
||||||
icons=icons,
|
|
||||||
force_clear=force_clear
|
|
||||||
)
|
|
||||||
|
|
||||||
# Draw each line of text
|
|
||||||
for text, x, y in lines:
|
|
||||||
self.display_manager.draw_text(text, x=x, y=y, force_clear=False)
|
|
||||||
Reference in New Issue
Block a user