From ff344006b972949a6bbe3ccfd040ae5ab555cbc1 Mon Sep 17 00:00:00 2001 From: ChuckBuilds <33324927+ChuckBuilds@users.noreply.github.com> Date: Fri, 11 Apr 2025 10:29:26 -0500 Subject: [PATCH] Fix stock news scrolling in test environment: - Optimize display manager settings for smooth scrolling - Add proper display initialization and cleanup in test script - Implement timing control to prevent display buffer overflow - Ensure consistent 1ms delay between updates for smooth scrolling --- config/config.json | 2 +- test_stock_news_manager.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config/config.json b/config/config.json index d97b9a44..d4d18d71 100644 --- a/config/config.json +++ b/config/config.json @@ -57,7 +57,7 @@ "enabled": true, "update_interval": 300, "scroll_speed": 1, - "scroll_delay": 0.0001, + "scroll_delay": 0.001, "max_headlines_per_symbol": 1, "headlines_per_rotation": 2 } diff --git a/test_stock_news_manager.py b/test_stock_news_manager.py index 9172d974..b8b4a406 100644 --- a/test_stock_news_manager.py +++ b/test_stock_news_manager.py @@ -10,6 +10,7 @@ print(f"Current working directory: {os.getcwd()}") def main(): """Test the StockNewsManager class directly.""" + display_manager = None try: # Load configuration config_manager = ConfigManager() @@ -27,14 +28,27 @@ def main(): # Initialize display manager display_manager = DisplayManager(display_config) + # Clear the display and show a test pattern + display_manager.clear() + display_manager.update_display() + time.sleep(1) # Give time to see the test pattern + # Initialize news manager with the loaded config news_manager = StockNewsManager(config, display_manager) print("Testing news display. Press Ctrl+C to exit.") - # Run the news display in a loop + # Run the news display in a loop with proper timing + last_update = time.time() while True: - news_manager.display_news() + current_time = time.time() + # Ensure we're not updating too frequently + if current_time - last_update >= 0.001: # 1ms minimum between updates + news_manager.display_news() + last_update = current_time + else: + # Small sleep to prevent CPU hogging + time.sleep(0.0001) except KeyboardInterrupt: print("\nTest interrupted by user") @@ -43,6 +57,11 @@ def main(): import traceback traceback.print_exc() finally: + if display_manager: + # Clear the display before exiting + display_manager.clear() + display_manager.update_display() + display_manager.cleanup() print("Test completed") if __name__ == "__main__":