mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Fixed NHL manager display inheritance: removed duplicate display code and properly call base class display method
This commit is contained in:
@@ -446,82 +446,7 @@ class NHLLiveManager(BaseNHLManager):
|
||||
if not self.current_game:
|
||||
logging.warning("[NHL] No game data available to display")
|
||||
return
|
||||
|
||||
try:
|
||||
# Create a new black image
|
||||
img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
# Load and resize logos
|
||||
home_logo = self._load_and_resize_logo(self.current_game["home_abbr"])
|
||||
away_logo = self._load_and_resize_logo(self.current_game["away_abbr"])
|
||||
|
||||
# Draw home team logo (right side)
|
||||
if home_logo:
|
||||
home_x = 3 * self.display_width // 4 - home_logo.width // 2
|
||||
home_y = self.display_height // 4 - home_logo.height // 2
|
||||
temp_img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
temp_draw = ImageDraw.Draw(temp_img)
|
||||
temp_img.paste(home_logo, (home_x, home_y), home_logo)
|
||||
img.paste(temp_img, (0, 0))
|
||||
|
||||
# Draw away team logo (left side)
|
||||
if away_logo:
|
||||
away_x = self.display_width // 4 - away_logo.width // 2
|
||||
away_y = self.display_height // 4 - away_logo.height // 2
|
||||
temp_img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
temp_draw = ImageDraw.Draw(temp_img)
|
||||
temp_img.paste(away_logo, (away_x, away_y), away_logo)
|
||||
img.paste(temp_img, (0, 0))
|
||||
|
||||
# Draw scores in the format "AWAY - HOME"
|
||||
home_score = str(self.current_game["home_score"])
|
||||
away_score = str(self.current_game["away_score"])
|
||||
|
||||
# Format the score string with a hyphen separator
|
||||
score_text = f"{away_score} - {home_score}"
|
||||
|
||||
# Calculate position for the score text (centered at the bottom)
|
||||
score_width = draw.textlength(score_text, font=self.fonts['score'])
|
||||
score_x = (self.display_width - score_width) // 2
|
||||
score_y = 3 * self.display_height // 4 - 10
|
||||
|
||||
# Draw the score text
|
||||
draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255))
|
||||
|
||||
# Format period text (1st, 2nd, 3rd, OT)
|
||||
period = self.current_game.get("period", 1)
|
||||
period_text = ""
|
||||
if period == 1:
|
||||
period_text = "1st"
|
||||
elif period == 2:
|
||||
period_text = "2nd"
|
||||
elif period == 3:
|
||||
period_text = "3rd"
|
||||
elif period > 3:
|
||||
period_text = "OT"
|
||||
|
||||
# Get clock time
|
||||
clock = self.current_game.get("clock", "0:00")
|
||||
|
||||
# Combine period and clock
|
||||
time_text = f"{period_text} {clock}"
|
||||
|
||||
# Calculate position for the time text (centered at the top)
|
||||
time_width = draw.textlength(time_text, font=self.fonts['time'])
|
||||
time_x = (self.display_width - time_width) // 2
|
||||
time_y = 5
|
||||
|
||||
# Draw the time text
|
||||
draw.text((time_x, time_y), time_text, font=self.fonts['time'], fill=(255, 255, 255))
|
||||
|
||||
# Display the image
|
||||
self.display_manager.image.paste(img, (0, 0))
|
||||
self.display_manager.update_display()
|
||||
logging.debug("[NHL] Successfully displayed live game")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"[NHL] Error displaying live game: {e}", exc_info=True)
|
||||
super().display(force_clear) # Call parent class's display method
|
||||
|
||||
class NHLRecentManager(BaseNHLManager):
|
||||
"""Manager for recently completed NHL games."""
|
||||
@@ -600,67 +525,7 @@ class NHLRecentManager(BaseNHLManager):
|
||||
if not self.current_game:
|
||||
logging.warning("[NHL] No recent game data available to display")
|
||||
return
|
||||
|
||||
try:
|
||||
# Create a new black image
|
||||
img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
# Load and resize logos
|
||||
home_logo = self._load_and_resize_logo(self.current_game["home_abbr"])
|
||||
away_logo = self._load_and_resize_logo(self.current_game["away_abbr"])
|
||||
|
||||
# Draw home team logo (right side)
|
||||
if home_logo:
|
||||
home_x = 3 * self.display_width // 4 - home_logo.width // 2
|
||||
home_y = self.display_height // 4 - home_logo.height // 2
|
||||
temp_img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
temp_draw = ImageDraw.Draw(temp_img)
|
||||
temp_img.paste(home_logo, (home_x, home_y), home_logo)
|
||||
img.paste(temp_img, (0, 0))
|
||||
|
||||
# Draw away team logo (left side)
|
||||
if away_logo:
|
||||
away_x = self.display_width // 4 - away_logo.width // 2
|
||||
away_y = self.display_height // 4 - away_logo.height // 2
|
||||
temp_img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
temp_draw = ImageDraw.Draw(temp_img)
|
||||
temp_img.paste(away_logo, (away_x, away_y), away_logo)
|
||||
img.paste(temp_img, (0, 0))
|
||||
|
||||
# Draw scores in the format "AWAY - HOME"
|
||||
home_score = str(self.current_game["home_score"])
|
||||
away_score = str(self.current_game["away_score"])
|
||||
|
||||
# Format the score string with a hyphen separator
|
||||
score_text = f"{away_score} - {home_score}"
|
||||
|
||||
# Calculate position for the score text (centered at the bottom)
|
||||
score_width = draw.textlength(score_text, font=self.fonts['score'])
|
||||
score_x = (self.display_width - score_width) // 2
|
||||
score_y = 3 * self.display_height // 4 - 10
|
||||
|
||||
# Draw the score text
|
||||
draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255))
|
||||
|
||||
# Draw "FINAL" status
|
||||
final_text = "FINAL"
|
||||
|
||||
# Calculate position for the final text (centered in the middle)
|
||||
final_width = draw.textlength(final_text, font=self.fonts['status'])
|
||||
final_x = (self.display_width - final_width) // 2
|
||||
final_y = self.display_height // 2 - 5
|
||||
|
||||
# Draw the final text
|
||||
draw.text((final_x, final_y), final_text, font=self.fonts['status'], fill=(255, 255, 255))
|
||||
|
||||
# Display the image
|
||||
self.display_manager.image.paste(img, (0, 0))
|
||||
self.display_manager.update_display()
|
||||
logging.debug("[NHL] Successfully displayed recent game")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"[NHL] Error displaying recent game: {e}", exc_info=True)
|
||||
super().display(force_clear) # Call parent class's display method
|
||||
|
||||
class NHLUpcomingManager(BaseNHLManager):
|
||||
"""Manager for upcoming NHL games."""
|
||||
@@ -748,62 +613,4 @@ class NHLUpcomingManager(BaseNHLManager):
|
||||
if not self.current_game:
|
||||
logging.warning("[NHL] No upcoming game data available to display")
|
||||
return
|
||||
|
||||
try:
|
||||
# Create a new black image
|
||||
img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
# Load and resize logos
|
||||
home_logo = self._load_and_resize_logo(self.current_game["home_abbr"])
|
||||
away_logo = self._load_and_resize_logo(self.current_game["away_abbr"])
|
||||
|
||||
# Draw home team logo (right side)
|
||||
if home_logo:
|
||||
home_x = 3 * self.display_width // 4 - home_logo.width // 2
|
||||
home_y = self.display_height // 4 - home_logo.height // 2
|
||||
temp_img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
temp_draw = ImageDraw.Draw(temp_img)
|
||||
temp_img.paste(home_logo, (home_x, home_y), home_logo)
|
||||
img.paste(temp_img, (0, 0))
|
||||
|
||||
# Draw away team logo (left side)
|
||||
if away_logo:
|
||||
away_x = self.display_width // 4 - away_logo.width // 2
|
||||
away_y = self.display_height // 4 - away_logo.height // 2
|
||||
temp_img = Image.new('RGB', (self.display_width, self.display_height), 'black')
|
||||
temp_draw = ImageDraw.Draw(temp_img)
|
||||
temp_img.paste(away_logo, (away_x, away_y), away_logo)
|
||||
img.paste(temp_img, (0, 0))
|
||||
|
||||
# Format the game time and date
|
||||
game_time = self.current_game.get("game_time", "")
|
||||
game_date = self.current_game.get("game_date", "")
|
||||
|
||||
# Format the time and date text
|
||||
time_text = f"{game_time}"
|
||||
date_text = f"{game_date}"
|
||||
|
||||
# Calculate position for the time text (centered at the bottom)
|
||||
time_width = draw.textlength(time_text, font=self.fonts['score'])
|
||||
time_x = (self.display_width - time_width) // 2
|
||||
time_y = 3 * self.display_height // 4 - 10
|
||||
|
||||
# Draw the time text
|
||||
draw.text((time_x, time_y), time_text, font=self.fonts['score'], fill=(255, 255, 255))
|
||||
|
||||
# Calculate position for the date text (centered in the middle)
|
||||
date_width = draw.textlength(date_text, font=self.fonts['status'])
|
||||
date_x = (self.display_width - date_width) // 2
|
||||
date_y = self.display_height // 2 - 5
|
||||
|
||||
# Draw the date text
|
||||
draw.text((date_x, date_y), date_text, font=self.fonts['status'], fill=(255, 255, 255))
|
||||
|
||||
# Display the image
|
||||
self.display_manager.image.paste(img, (0, 0))
|
||||
self.display_manager.update_display()
|
||||
logging.debug("[NHL] Successfully displayed upcoming game")
|
||||
|
||||
except Exception as e:
|
||||
logging.error(f"[NHL] Error displaying upcoming game: {e}", exc_info=True)
|
||||
super().display(force_clear) # Call parent class's display method
|
||||
Reference in New Issue
Block a user