From a1fc23112492b0b7975985934505316323192715 Mon Sep 17 00:00:00 2001 From: ChuckBuilds <33324927+ChuckBuilds@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:03:25 -0500 Subject: [PATCH] fix(stock_news): Resolve UnboundLocalError for width/height --- src/stock_news_manager.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/stock_news_manager.py b/src/stock_news_manager.py index d152d0ea..3802496b 100644 --- a/src/stock_news_manager.py +++ b/src/stock_news_manager.py @@ -190,13 +190,14 @@ class StockNewsManager: if not all_news: return + # Define width and height here, so they are always available + width = self.display_manager.matrix.width + height = self.display_manager.matrix.height + # Create a continuous scrolling image if needed if self.cached_text_image is None: random.shuffle(all_news) - width = self.display_manager.matrix.width - height = self.display_manager.matrix.height - # Estimate total width needed (adjust multiplier if needed) # Average headline length guess + symbol + screen width gap estimated_item_width = width * 3 # Estimate each item + gap needs ~3 screen widths @@ -243,7 +244,7 @@ class StockNewsManager: # self.last_update = time.time() # --- Scrolling logic remains the same --- - width = self.display_manager.matrix.width + # width = self.display_manager.matrix.width # Moved up # Check if cached image exists before accessing width if self.cached_text_image is None: logger.warning("[StockNews] Cached image is None, cannot scroll.")