milb font error handling

This commit is contained in:
ChuckBuilds
2025-08-14 13:39:48 -05:00
parent 18145edbf1
commit ef82610a06

View File

@@ -336,10 +336,8 @@ class BaseMiLBManager:
date_font = getattr(self.display_manager, 'small_font', None)
time_font = getattr(self.display_manager, 'small_font', None)
if date_font is None or time_font is None:
script_dir = os.path.dirname(os.path.abspath(__file__))
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
date_font = ImageFont.truetype(ps2p, 8)
time_font = ImageFont.truetype(ps2p, 8)
date_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
time_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
self.logger.debug(f"[MiLB] Fonts prepared successfully")
except Exception as e:
self.logger.error(f"[MiLB] Failed to prepare fonts: {e}")
@@ -405,9 +403,11 @@ class BaseMiLBManager:
away_score = str(game_data['away_score'])
home_score = str(game_data['home_score'])
score_text = f"{away_score}-{home_score}"
script_dir = os.path.dirname(os.path.abspath(__file__))
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
score_font = ImageFont.truetype(ps2p, 12)
try:
score_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 12)
except IOError:
self.logger.warning("[MiLB] Could not load PressStart2P font, using default")
score_font = ImageFont.load_default()
# Calculate position for the score text
score_width = draw.textlength(score_text, font=score_font)
@@ -419,10 +419,7 @@ class BaseMiLBManager:
# Draw records for upcoming and recent games
if self.show_records and game_data['status'] in ['status_scheduled', 'status_final', 'final', 'completed']:
try:
# Resolve 4x6 font via absolute path
script_dir = os.path.dirname(os.path.abspath(__file__))
font_4x6 = os.path.abspath(os.path.join(script_dir, "../assets/fonts/4x6-font.ttf"))
record_font = ImageFont.truetype(font_4x6, 6)
record_font = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
except IOError:
record_font = ImageFont.load_default()