mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Implement continuous scrolling for all stock symbols in one line
This commit is contained in:
@@ -418,7 +418,7 @@ class StockManager:
|
|||||||
self.frame_count += 1
|
self.frame_count += 1
|
||||||
|
|
||||||
def display_stocks(self, force_clear: bool = False):
|
def display_stocks(self, force_clear: bool = False):
|
||||||
"""Display stock information with scrolling animation."""
|
"""Display stock information with continuous scrolling animation."""
|
||||||
if not self.stocks_config.get('enabled', False):
|
if not self.stocks_config.get('enabled', False):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -430,19 +430,44 @@ class StockManager:
|
|||||||
logger.warning("No stock data available to display")
|
logger.warning("No stock data available to display")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the current stock to display
|
# Get all symbols
|
||||||
symbols = list(self.stock_data.keys())
|
symbols = list(self.stock_data.keys())
|
||||||
if not symbols:
|
if not symbols:
|
||||||
return
|
return
|
||||||
|
|
||||||
current_symbol = symbols[self.current_stock_index]
|
# Create a continuous scrolling image if needed
|
||||||
data = self.stock_data[current_symbol]
|
if self.cached_text_image is None or force_clear:
|
||||||
|
# Create a very wide image that contains all stocks in sequence
|
||||||
# Create the display image if needed
|
width = self.display_manager.matrix.width
|
||||||
if self.cached_text_image is None or self.cached_text != current_symbol:
|
height = self.display_manager.matrix.height
|
||||||
self.cached_text_image = self._create_stock_display(current_symbol, data, self.display_manager.matrix.width, self.display_manager.matrix.height)
|
|
||||||
self.cached_text = current_symbol
|
# Calculate total width needed for all stocks
|
||||||
|
# Each stock needs width*2 for scrolling, plus a small gap between stocks
|
||||||
|
gap = width // 4 # Gap between stocks
|
||||||
|
total_width = sum(width * 2 for _ in symbols) + gap * (len(symbols) - 1)
|
||||||
|
|
||||||
|
# Create the full image
|
||||||
|
full_image = Image.new('RGB', (total_width, height), (0, 0, 0))
|
||||||
|
draw = ImageDraw.Draw(full_image)
|
||||||
|
|
||||||
|
# Draw each stock in sequence
|
||||||
|
current_x = 0
|
||||||
|
for symbol in symbols:
|
||||||
|
data = self.stock_data[symbol]
|
||||||
|
|
||||||
|
# Create stock display for this symbol
|
||||||
|
stock_image = self._create_stock_display(symbol, data, width, height, 0)
|
||||||
|
|
||||||
|
# Paste this stock image into the full image
|
||||||
|
full_image.paste(stock_image, (current_x, 0))
|
||||||
|
|
||||||
|
# Move to next position
|
||||||
|
current_x += width * 2 + gap
|
||||||
|
|
||||||
|
# Cache the full image
|
||||||
|
self.cached_text_image = full_image
|
||||||
self.scroll_position = 0
|
self.scroll_position = 0
|
||||||
|
self.last_update = time.time()
|
||||||
|
|
||||||
# Clear the display if requested
|
# Clear the display if requested
|
||||||
if force_clear:
|
if force_clear:
|
||||||
@@ -451,10 +476,10 @@ class StockManager:
|
|||||||
|
|
||||||
# Calculate the visible portion of the image
|
# Calculate the visible portion of the image
|
||||||
width = self.display_manager.matrix.width
|
width = self.display_manager.matrix.width
|
||||||
scroll_width = width * 2 # Double width for smooth scrolling
|
total_width = self.cached_text_image.width
|
||||||
|
|
||||||
# Update scroll position with small increments
|
# Update scroll position with small increments
|
||||||
self.scroll_position = (self.scroll_position + self.scroll_speed) % scroll_width
|
self.scroll_position = (self.scroll_position + self.scroll_speed) % total_width
|
||||||
|
|
||||||
# Calculate the visible portion
|
# Calculate the visible portion
|
||||||
visible_portion = self.cached_text_image.crop((
|
visible_portion = self.cached_text_image.crop((
|
||||||
@@ -472,11 +497,8 @@ class StockManager:
|
|||||||
# Add a small delay between frames
|
# Add a small delay between frames
|
||||||
time.sleep(self.scroll_delay)
|
time.sleep(self.scroll_delay)
|
||||||
|
|
||||||
# Move to next stock after a delay
|
# If we've scrolled through the entire image, reset
|
||||||
if time.time() - self.last_update > 5: # Show each stock for 5 seconds
|
if self.scroll_position == 0:
|
||||||
self.current_stock_index = (self.current_stock_index + 1) % len(symbols)
|
return True
|
||||||
self.last_update = time.time()
|
|
||||||
self.cached_text_image = None # Force recreation of display for next stock
|
return False
|
||||||
|
|
||||||
# If we've shown all stocks, signal completion by returning True
|
|
||||||
return self.current_stock_index == 0
|
|
||||||
Reference in New Issue
Block a user