mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-11 21:33:00 +00:00
Update font test to display all sizes at once as a static image
This commit is contained in:
@@ -23,14 +23,15 @@ def main():
|
|||||||
# Initialize font test manager
|
# Initialize font test manager
|
||||||
font_test_manager = FontTestManager(config, display_manager)
|
font_test_manager = FontTestManager(config, display_manager)
|
||||||
|
|
||||||
logger.info("Starting font test display. Press Ctrl+C to exit.")
|
logger.info("Starting static font test display. Press Ctrl+C to exit.")
|
||||||
|
|
||||||
# Run the font test display
|
# Display all font sizes at once
|
||||||
|
font_test_manager.display()
|
||||||
|
|
||||||
|
# Keep the display running until user interrupts
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
font_test_manager.update()
|
time.sleep(1) # Sleep to prevent CPU hogging
|
||||||
font_test_manager.display()
|
|
||||||
time.sleep(0.1) # Small delay to prevent CPU hogging
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info("Font test display stopped by user.")
|
logger.info("Font test display stopped by user.")
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ class FontTestManager:
|
|||||||
self.config = config
|
self.config = config
|
||||||
self.font_path = "assets/fonts/PressStart2P-Regular.ttf"
|
self.font_path = "assets/fonts/PressStart2P-Regular.ttf"
|
||||||
self.font_sizes = [4, 6, 8, 10, 12, 14, 16, 18]
|
self.font_sizes = [4, 6, 8, 10, 12, 14, 16, 18]
|
||||||
self.current_size_index = 0
|
|
||||||
self.display_duration = 3 # Display each size for 3 seconds
|
|
||||||
self.last_update = 0
|
|
||||||
self.logger = logging.getLogger('FontTest')
|
self.logger = logging.getLogger('FontTest')
|
||||||
|
|
||||||
# Verify font exists
|
# Verify font exists
|
||||||
@@ -30,49 +27,50 @@ class FontTestManager:
|
|||||||
self.logger.info(f"Initialized FontTestManager with {len(self.font_sizes)} font sizes to test")
|
self.logger.info(f"Initialized FontTestManager with {len(self.font_sizes)} font sizes to test")
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update the display with the current font size."""
|
"""No update needed for static display."""
|
||||||
current_time = time.time()
|
pass
|
||||||
|
|
||||||
# Check if it's time to switch to the next font size
|
|
||||||
if current_time - self.last_update >= self.display_duration:
|
|
||||||
self.current_size_index = (self.current_size_index + 1) % len(self.font_sizes)
|
|
||||||
self.last_update = current_time
|
|
||||||
self.logger.info(f"Switching to font size: {self.font_sizes[self.current_size_index]}")
|
|
||||||
|
|
||||||
def display(self, force_clear: bool = False):
|
def display(self, force_clear: bool = False):
|
||||||
"""Display the current font size test."""
|
"""Display all font sizes at once across the screen."""
|
||||||
try:
|
try:
|
||||||
# Clear the display
|
# Clear the display
|
||||||
self.display_manager.clear()
|
self.display_manager.clear()
|
||||||
|
|
||||||
# Get current font size
|
|
||||||
current_size = self.font_sizes[self.current_size_index]
|
|
||||||
|
|
||||||
# Load the font at the current size
|
|
||||||
font = ImageFont.truetype(self.font_path, current_size)
|
|
||||||
|
|
||||||
# Create text to display (the size number)
|
|
||||||
text = str(current_size)
|
|
||||||
|
|
||||||
# Get display dimensions
|
# Get display dimensions
|
||||||
width = self.display_manager.matrix.width
|
width = self.display_manager.matrix.width
|
||||||
height = self.display_manager.matrix.height
|
height = self.display_manager.matrix.height
|
||||||
|
|
||||||
# Get text dimensions
|
# Calculate spacing between font sizes
|
||||||
|
total_sizes = len(self.font_sizes)
|
||||||
|
spacing = width // (total_sizes + 1) # Add 1 to account for edges
|
||||||
|
|
||||||
|
# Draw each font size
|
||||||
draw = ImageDraw.Draw(self.display_manager.image)
|
draw = ImageDraw.Draw(self.display_manager.image)
|
||||||
bbox = draw.textbbox((0, 0), text, font=font)
|
|
||||||
text_width = bbox[2] - bbox[0]
|
|
||||||
text_height = bbox[3] - bbox[1]
|
|
||||||
|
|
||||||
# Calculate position to center the text
|
for i, size in enumerate(self.font_sizes):
|
||||||
x = (width - text_width) // 2
|
# Load the font at the current size
|
||||||
y = (height - text_height) // 2
|
font = ImageFont.truetype(self.font_path, size)
|
||||||
|
|
||||||
|
# Create text to display (the size number)
|
||||||
|
text = str(size)
|
||||||
|
|
||||||
|
# Get text dimensions
|
||||||
|
bbox = draw.textbbox((0, 0), text, font=font)
|
||||||
|
text_width = bbox[2] - bbox[0]
|
||||||
|
text_height = bbox[3] - bbox[1]
|
||||||
|
|
||||||
|
# Calculate position to center the text horizontally and vertically
|
||||||
|
x = spacing * (i + 1) - (text_width // 2)
|
||||||
|
y = (height - text_height) // 2
|
||||||
|
|
||||||
|
# Draw the text
|
||||||
|
draw.text((x, y), text, font=font, fill=(255, 255, 255))
|
||||||
|
|
||||||
# Draw the text
|
# Update the display once
|
||||||
draw.text((x, y), text, font=font, fill=(255, 255, 255))
|
|
||||||
|
|
||||||
# Update the display
|
|
||||||
self.display_manager.update_display()
|
self.display_manager.update_display()
|
||||||
|
|
||||||
|
# Log that display is complete
|
||||||
|
self.logger.info("Font size test display complete. All sizes shown at once.")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error displaying font test: {e}", exc_info=True)
|
self.logger.error(f"Error displaying font test: {e}", exc_info=True)
|
||||||
Reference in New Issue
Block a user