diff --git a/src/nhl_managers.py b/src/nhl_managers.py index 151089a9..d7df0d23 100644 --- a/src/nhl_managers.py +++ b/src/nhl_managers.py @@ -80,10 +80,14 @@ class BaseNHLManager: def _load_and_resize_logo(self, team_abbrev: str) -> Optional[Image.Image]: """Load and resize a team logo, with caching.""" + self.logger.info(f"Loading logo for team: {team_abbrev}") + if team_abbrev in self._logo_cache: + self.logger.info(f"Using cached logo for {team_abbrev}") return self._logo_cache[team_abbrev] logo_path = os.path.join(self.logo_dir, f"{team_abbrev}.png") + self.logger.info(f"Loading logo from path: {logo_path}") try: # Create test logos if they don't exist @@ -102,11 +106,14 @@ class BaseNHLManager: # Add team abbreviation draw.text((8, 8), team_abbrev, fill=(255, 255, 255, 255)) logo.save(logo_path) + self.logger.info(f"Created and saved test logo for {team_abbrev}") logo = Image.open(logo_path) + self.logger.info(f"Opened logo for {team_abbrev}, initial size: {logo.size}, mode: {logo.mode}") # Convert to RGBA if not already if logo.mode != 'RGBA': + self.logger.info(f"Converting {team_abbrev} logo from {logo.mode} to RGBA") logo = logo.convert('RGBA') # Calculate max size based on display dimensions @@ -115,6 +122,7 @@ class BaseNHLManager: # Resize maintaining aspect ratio logo.thumbnail((max_width, max_height), Image.Resampling.LANCZOS) + self.logger.info(f"Resized {team_abbrev} logo to: {logo.size}") # Cache the resized logo self._logo_cache[team_abbrev] = logo @@ -224,23 +232,31 @@ class BaseNHLManager: def _draw_scorebug_layout(self): """Draw the scorebug layout for the current game.""" try: + self.logger.info(f"Drawing scorebug for {self.current_game['away_abbr']} vs {self.current_game['home_abbr']}") + # Create a new black image for the main display - main_img = Image.new('RGB', (self.display_width, self.display_height), 'black') - draw = ImageDraw.Draw(main_img) - + main_img = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 255)) + # Load logos once home_logo = self._load_and_resize_logo(self.current_game["home_abbr"]) away_logo = self._load_and_resize_logo(self.current_game["away_abbr"]) - - # Create separate images for each logo - home_img = Image.new('RGB', (self.display_width, self.display_height), 'black') - away_img = Image.new('RGB', (self.display_width, self.display_height), 'black') + + self.logger.info(f"Home logo loaded: {home_logo is not None}, Away logo loaded: {away_logo is not None}") + if home_logo: + self.logger.info(f"Home logo size: {home_logo.size}, mode: {home_logo.mode}") + if away_logo: + self.logger.info(f"Away logo size: {away_logo.size}, mode: {away_logo.mode}") # 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 - home_img.paste(home_logo, (home_x, home_y), home_logo) + self.logger.info(f"Pasting home logo at ({home_x}, {home_y})") + + # Create a temporary image for the home logo + home_overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) + home_overlay.paste(home_logo, (home_x, home_y), home_logo) + main_img = Image.alpha_composite(main_img, home_overlay) else: self.logger.warning(f"Home logo is None for team {self.current_game['home_abbr']}") @@ -248,14 +264,18 @@ class BaseNHLManager: if away_logo: away_x = self.display_width // 4 - away_logo.width // 2 away_y = self.display_height // 4 - away_logo.height // 2 - away_img.paste(away_logo, (away_x, away_y), away_logo) + self.logger.info(f"Pasting away logo at ({away_x}, {away_y})") + + # Create a temporary image for the away logo + away_overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) + away_overlay.paste(away_logo, (away_x, away_y), away_logo) + main_img = Image.alpha_composite(main_img, away_overlay) else: self.logger.warning(f"Away logo is None for team {self.current_game['away_abbr']}") - # Combine the images - main_img = Image.alpha_composite(main_img.convert('RGBA'), home_img.convert('RGBA')) - main_img = Image.alpha_composite(main_img, away_img.convert('RGBA')) + # Convert to RGB for final display main_img = main_img.convert('RGB') + draw = ImageDraw.Draw(main_img) # Draw scores in the format "AWAY - HOME" home_score = str(self.current_game["home_score"]) @@ -270,7 +290,6 @@ class BaseNHLManager: score_y = 3 * self.display_height // 4 - 10 # Draw the score text - draw = ImageDraw.Draw(main_img) draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255)) # Draw game status (period and time or "FINAL") @@ -284,6 +303,7 @@ class BaseNHLManager: # Display the image self.display_manager.image.paste(main_img, (0, 0)) self.display_manager.update_display() + self.logger.info("Scorebug display completed") except Exception as e: self.logger.error(f"Error displaying game: {e}", exc_info=True)