From 99d99900022c532e22a78d7605aa3e57f200d0fd Mon Sep 17 00:00:00 2001 From: Chuck <33324927+ChuckBuilds@users.noreply.github.com> Date: Thu, 10 Apr 2025 20:22:26 -0500 Subject: [PATCH] updating scroll direction orienting scroll direction --- src/news_manager.py | 5 ++- test_scroll_direction.py | 87 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 test_scroll_direction.py diff --git a/src/news_manager.py b/src/news_manager.py index abe05e07..382ab790 100644 --- a/src/news_manager.py +++ b/src/news_manager.py @@ -174,7 +174,8 @@ class NewsManager: frame_image = Image.new('RGB', (self.display_manager.matrix.width, self.display_manager.matrix.height), (0, 0, 0)) # Calculate the source and destination regions for the visible portion - src_x = max(0, text_width - self.scroll_position - visible_width) + # For left-to-right scrolling, we start from the left side of the text + src_x = self.scroll_position src_width = min(visible_width, text_width - src_x) # Copy the visible portion of the text to the frame @@ -183,7 +184,7 @@ class NewsManager: frame_image.paste(src_region, (0, 0)) # If we need to wrap around to the beginning of the text - if src_x == 0 and self.scroll_position > text_width: + if src_x + src_width >= text_width: remaining_width = self.display_manager.matrix.width - src_width if remaining_width > 0: wrap_src_width = min(remaining_width, text_width) diff --git a/test_scroll_direction.py b/test_scroll_direction.py new file mode 100644 index 00000000..7fe48583 --- /dev/null +++ b/test_scroll_direction.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +import time +import sys +import os +from src.config_manager import ConfigManager +from src.display_manager import DisplayManager +from src.news_manager import NewsManager + +def main(): + """Test the scrolling direction of the news ticker.""" + try: + # Load configuration + config_manager = ConfigManager() + config = config_manager.load_config() + + # Initialize display manager + display_manager = DisplayManager(config.get('display', {})) + + # Initialize news manager + news_manager = NewsManager(config, display_manager) + + print("Starting scroll direction test...") + print("This test will display a simple text message scrolling from left to right") + print("Press Ctrl+C to exit") + + # Create a simple test message + test_message = "TEST MESSAGE - This is a test of scrolling direction" + + # Create a text image for the test message + text_image = news_manager._create_text_image(test_message) + text_width = text_image.width + + # Clear the display + display_manager.clear() + display_manager.update_display() + + # Test scrolling from left to right + scroll_position = 0 + while True: + # Create a new frame + frame_image = display_manager.create_blank_image() + + # Calculate the visible portion + visible_width = min(display_manager.matrix.width, text_width) + src_x = scroll_position + src_width = min(visible_width, text_width - src_x) + + # Copy the visible portion + if src_width > 0: + src_region = text_image.crop((src_x, 0, src_x + src_width, display_manager.matrix.height)) + frame_image.paste(src_region, (0, 0)) + + # Handle wrapping + if src_x + src_width >= text_width: + remaining_width = display_manager.matrix.width - src_width + if remaining_width > 0: + wrap_src_width = min(remaining_width, text_width) + wrap_region = text_image.crop((0, 0, wrap_src_width, display_manager.matrix.height)) + frame_image.paste(wrap_region, (src_width, 0)) + + # Update the display + display_manager.image = frame_image + display_manager.draw = display_manager.create_draw_object() + display_manager.update_display() + + # Update scroll position + scroll_position += 1 + + # Reset when we've scrolled past the end + if scroll_position > text_width + display_manager.matrix.width: + scroll_position = 0 + time.sleep(1) # Pause briefly before restarting + + time.sleep(0.05) # Control scroll speed + + except KeyboardInterrupt: + print("\nTest interrupted by user") + except Exception as e: + print(f"Error during test: {e}") + finally: + # Clean up + display_manager.clear() + display_manager.update_display() + print("Test completed") + +if __name__ == "__main__": + main() \ No newline at end of file