Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/display_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self):
logger.info(f"News Manager initialized: {'Object' if self.news_manager else 'None'}")
logger.info("Display modes initialized in %.3f seconds", time.time() - init_time)

self.force_change = False
# Initialize Music Manager
music_init_time = time.time()
self.music_manager = None
Expand Down Expand Up @@ -1139,7 +1140,8 @@ def run(self):
# Reset logged duration when mode changes
if hasattr(self, '_last_logged_duration'):
delattr(self, '_last_logged_duration')
elif current_time - self.last_switch >= self.get_current_duration():
elif current_time - self.last_switch >= self.get_current_duration() or self.force_change:
self.force_change = False
if self.current_display_mode == 'calendar' and self.calendar:
self.calendar.advance_event()
elif self.current_display_mode == 'of_the_day' and self.of_the_day:
Expand Down Expand Up @@ -1288,8 +1290,11 @@ def run(self):
manager_to_display.display_stocks(force_clear=self.force_clear)
elif self.current_display_mode == 'stock_news':
manager_to_display.display_news() # Assumes internal clearing
elif self.current_display_mode == 'odds_ticker':
manager_to_display.display(force_clear=self.force_clear)
elif self.current_display_mode in {'odds_ticker', 'leaderboard'}:
try:
manager_to_display.display(force_clear=self.force_clear)
except StopIteration:
self.force_change = True
elif self.current_display_mode == 'calendar':
manager_to_display.display(force_clear=self.force_clear)
elif self.current_display_mode == 'youtube':
Expand Down
10 changes: 9 additions & 1 deletion src/leaderboard_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from typing import Dict, Any, List, Optional
import os
import time
from PIL import Image, ImageDraw, ImageFont
try:
from .display_manager import DisplayManager
Expand Down Expand Up @@ -42,7 +43,7 @@ def __init__(self, config: Dict[str, Any], display_manager: DisplayManager):
self.display_duration = self.leaderboard_config.get('display_duration', 30)
self.loop = self.leaderboard_config.get('loop', True)
self.request_timeout = self.leaderboard_config.get('request_timeout', 30)

self.time_over = 0
# Dynamic duration settings
self.dynamic_duration_enabled = self.leaderboard_config.get('dynamic_duration', True)
self.min_duration = self.leaderboard_config.get('min_duration', 30)
Expand Down Expand Up @@ -1355,6 +1356,11 @@ def display(self, force_clear: bool = False) -> None:
# Signal that scrolling has stopped
self.display_manager.set_scrolling_state(False)
logger.info("Leaderboard scrolling stopped - reached end of content")
if self.time_over == 0:
self.time_over = time.time()
elif time.time() - self.time_over >= 2:
self.time_over = 0
raise StopIteration

# Check if we're at a natural break point for mode switching
elapsed_time = current_time - self._display_start_time
Expand Down Expand Up @@ -1402,6 +1408,8 @@ def display(self, force_clear: bool = False) -> None:
self.display_manager.draw = ImageDraw.Draw(self.display_manager.image)
self.display_manager.update_display()

except StopIteration as e:
raise e
except Exception as e:
logger.error(f"Error in leaderboard display: {e}")
self._display_fallback_message()