mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
loading fonts va absolute paths
This commit is contained in:
@@ -98,11 +98,9 @@ class DisplayManager:
|
|||||||
self.draw = ImageDraw.Draw(self.image)
|
self.draw = ImageDraw.Draw(self.image)
|
||||||
logger.info(f"Image canvas created with dimensions: {self.matrix.width}x{self.matrix.height}")
|
logger.info(f"Image canvas created with dimensions: {self.matrix.width}x{self.matrix.height}")
|
||||||
|
|
||||||
# Initialize font with Press Start 2P using an absolute path so services don't fall back
|
# Initialize font with Press Start 2P
|
||||||
try:
|
try:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
self.font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
ps2p_path = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
|
||||||
self.font = ImageFont.truetype(ps2p_path, 8)
|
|
||||||
logger.info("Initial Press Start 2P font loaded successfully")
|
logger.info("Initial Press Start 2P font loaded successfully")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to load initial font: {e}")
|
logger.error(f"Failed to load initial font: {e}")
|
||||||
@@ -292,21 +290,17 @@ class DisplayManager:
|
|||||||
def _load_fonts(self):
|
def _load_fonts(self):
|
||||||
"""Load fonts with proper error handling."""
|
"""Load fonts with proper error handling."""
|
||||||
try:
|
try:
|
||||||
# Load Press Start 2P font using absolute path to avoid fallback when run under systemd
|
# Load Press Start 2P font
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
self.regular_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
ps2p_path = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
|
||||||
self.regular_font = ImageFont.truetype(ps2p_path, 8)
|
|
||||||
logger.info("Press Start 2P font loaded successfully")
|
logger.info("Press Start 2P font loaded successfully")
|
||||||
|
|
||||||
# Use the same font for small text (currently same size; adjust size here if needed)
|
# Use the same font for small text (currently same size; adjust size here if needed)
|
||||||
self.small_font = ImageFont.truetype(ps2p_path, 8)
|
self.small_font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
logger.info("Press Start 2P small font loaded successfully")
|
logger.info("Press Start 2P small font loaded successfully")
|
||||||
|
|
||||||
# Load 5x7 BDF font for calendar events
|
# Load 5x7 BDF font for calendar events
|
||||||
try:
|
try:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
self.calendar_font_path = "assets/fonts/5x7.bdf"
|
||||||
relative_font_path = os.path.join(script_dir, "../assets/fonts/5x7.bdf")
|
|
||||||
self.calendar_font_path = os.path.abspath(relative_font_path)
|
|
||||||
logger.info(f"Attempting to load 5x7 font from: {self.calendar_font_path}")
|
logger.info(f"Attempting to load 5x7 font from: {self.calendar_font_path}")
|
||||||
|
|
||||||
if not os.path.exists(self.calendar_font_path):
|
if not os.path.exists(self.calendar_font_path):
|
||||||
@@ -332,9 +326,7 @@ class DisplayManager:
|
|||||||
|
|
||||||
# Load 4x6 font as extra_small_font
|
# Load 4x6 font as extra_small_font
|
||||||
try:
|
try:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
font_path = "assets/fonts/4x6-font.ttf"
|
||||||
relative_font_path = os.path.join(script_dir, "../assets/fonts/4x6-font.ttf")
|
|
||||||
font_path = os.path.abspath(relative_font_path)
|
|
||||||
logger.info(f"Attempting to load 4x6 TTF font from: {font_path} at size 6")
|
logger.info(f"Attempting to load 4x6 TTF font from: {font_path} at size 6")
|
||||||
self.extra_small_font = ImageFont.truetype(font_path, 6)
|
self.extra_small_font = ImageFont.truetype(font_path, 6)
|
||||||
logger.info(f"4x6 TTF extra small font loaded successfully from {font_path}")
|
logger.info(f"4x6 TTF extra small font loaded successfully from {font_path}")
|
||||||
|
|||||||
@@ -193,14 +193,11 @@ class BaseNBAManager:
|
|||||||
"""Load fonts used by the scoreboard."""
|
"""Load fonts used by the scoreboard."""
|
||||||
fonts = {}
|
fonts = {}
|
||||||
try:
|
try:
|
||||||
# Try to load the Press Start 2P font first using absolute paths
|
# Try to load the Press Start 2P font first
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
fonts['score'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 10)
|
||||||
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
fonts['time'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
font_4x6 = os.path.abspath(os.path.join(script_dir, "../assets/fonts/4x6-font.ttf"))
|
fonts['team'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
fonts['score'] = ImageFont.truetype(ps2p, 10)
|
fonts['status'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
||||||
fonts['time'] = ImageFont.truetype(ps2p, 8)
|
|
||||||
fonts['team'] = ImageFont.truetype(ps2p, 8)
|
|
||||||
fonts['status'] = ImageFont.truetype(font_4x6, 6)
|
|
||||||
logging.info("[NBA] Successfully loaded Press Start 2P font for all text elements")
|
logging.info("[NBA] Successfully loaded Press Start 2P font for all text elements")
|
||||||
except IOError:
|
except IOError:
|
||||||
logging.warning("[NBA] Press Start 2P font not found, trying 4x6 font.")
|
logging.warning("[NBA] Press Start 2P font not found, trying 4x6 font.")
|
||||||
|
|||||||
@@ -182,14 +182,11 @@ class BaseNFLManager: # Renamed class
|
|||||||
"""Load fonts used by the scoreboard."""
|
"""Load fonts used by the scoreboard."""
|
||||||
fonts = {}
|
fonts = {}
|
||||||
try:
|
try:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
fonts['score'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 10)
|
||||||
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
fonts['time'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
font_4x6 = os.path.abspath(os.path.join(script_dir, "../assets/fonts/4x6-font.ttf"))
|
fonts['team'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
fonts['score'] = ImageFont.truetype(ps2p, 10)
|
fonts['status'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6) # Using 4x6 for status
|
||||||
fonts['time'] = ImageFont.truetype(ps2p, 8)
|
fonts['detail'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6) # Added detail font
|
||||||
fonts['team'] = ImageFont.truetype(ps2p, 8)
|
|
||||||
fonts['status'] = ImageFont.truetype(font_4x6, 6) # Using 4x6 for status
|
|
||||||
fonts['detail'] = ImageFont.truetype(font_4x6, 6) # Added detail font
|
|
||||||
logging.info("[NFL] Successfully loaded fonts")
|
logging.info("[NFL] Successfully loaded fonts")
|
||||||
except IOError:
|
except IOError:
|
||||||
logging.warning("[NFL] Fonts not found, using default PIL font.")
|
logging.warning("[NFL] Fonts not found, using default PIL font.")
|
||||||
|
|||||||
@@ -162,13 +162,10 @@ class BaseNHLManager:
|
|||||||
"""Load fonts used by the scoreboard."""
|
"""Load fonts used by the scoreboard."""
|
||||||
fonts = {}
|
fonts = {}
|
||||||
try:
|
try:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
fonts['score'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 12)
|
||||||
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
fonts['time'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
font_4x6 = os.path.abspath(os.path.join(script_dir, "../assets/fonts/4x6-font.ttf"))
|
fonts['team'] = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
fonts['score'] = ImageFont.truetype(ps2p, 12)
|
fonts['status'] = ImageFont.truetype("assets/fonts/4x6-font.ttf", 6)
|
||||||
fonts['time'] = ImageFont.truetype(ps2p, 8)
|
|
||||||
fonts['team'] = ImageFont.truetype(ps2p, 8)
|
|
||||||
fonts['status'] = ImageFont.truetype(font_4x6, 6)
|
|
||||||
logging.info("[NHL] Successfully loaded Press Start 2P font for all text elements")
|
logging.info("[NHL] Successfully loaded Press Start 2P font for all text elements")
|
||||||
except IOError:
|
except IOError:
|
||||||
logging.warning("[NHL] Press Start 2P font not found, trying 4x6 font.")
|
logging.warning("[NHL] Press Start 2P font not found, trying 4x6 font.")
|
||||||
|
|||||||
@@ -185,12 +185,10 @@ class OddsTickerManager:
|
|||||||
def _load_fonts(self) -> Dict[str, ImageFont.FreeTypeFont]:
|
def _load_fonts(self) -> Dict[str, ImageFont.FreeTypeFont]:
|
||||||
"""Load fonts for the ticker display."""
|
"""Load fonts for the ticker display."""
|
||||||
try:
|
try:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
|
||||||
return {
|
return {
|
||||||
'small': ImageFont.truetype(ps2p, 6),
|
'small': ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 6),
|
||||||
'medium': ImageFont.truetype(ps2p, 8),
|
'medium': ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8),
|
||||||
'large': ImageFont.truetype(ps2p, 10)
|
'large': ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 10)
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error loading fonts: {e}")
|
logger.error(f"Error loading fonts: {e}")
|
||||||
|
|||||||
@@ -428,14 +428,11 @@ class StockManager:
|
|||||||
fallback = Image.new('RGBA', (32, 32), (0, 0, 0, 0))
|
fallback = Image.new('RGBA', (32, 32), (0, 0, 0, 0))
|
||||||
draw = ImageDraw.Draw(fallback)
|
draw = ImageDraw.Draw(fallback)
|
||||||
try:
|
try:
|
||||||
# Resolve font path absolutely to avoid fallback under systemd; fall back to PS2P if missing
|
# Try to load OpenSans font first, fall back to PS2P if missing
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
font_path = os.path.abspath(os.path.join(script_dir, "../assets/fonts/OpenSans-Regular.ttf"))
|
|
||||||
try:
|
try:
|
||||||
font = ImageFont.truetype(font_path, 16)
|
font = ImageFont.truetype("assets/fonts/OpenSans-Regular.ttf", 16)
|
||||||
except Exception:
|
except Exception:
|
||||||
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
font = ImageFont.truetype(ps2p, 8)
|
|
||||||
except:
|
except:
|
||||||
font = ImageFont.load_default()
|
font = ImageFont.load_default()
|
||||||
|
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ class YouTubeDisplay:
|
|||||||
|
|
||||||
def _initialize_display(self):
|
def _initialize_display(self):
|
||||||
"""Initialize display components."""
|
"""Initialize display components."""
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
self.font = ImageFont.truetype("assets/fonts/PressStart2P-Regular.ttf", 8)
|
||||||
ps2p = os.path.abspath(os.path.join(script_dir, "../assets/fonts/PressStart2P-Regular.ttf"))
|
|
||||||
self.font = ImageFont.truetype(ps2p, 8)
|
|
||||||
try:
|
try:
|
||||||
self.youtube_logo = Image.open("assets/youtube_logo.png")
|
self.youtube_logo = Image.open("assets/youtube_logo.png")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user