""" ui/statusbar.py --------------- Bottom status bar widget for LottoSight. Updated after every fetch via update_fetch_results(). """ import tkinter as tk from tkinter import ttk from datetime import datetime _SOURCE_NAMES = { "powerball_ny": "Powerball", "megamillions_ny": "Mega Millions (NY)", "megamillions_tx": "Mega Millions (TX)", "cash5_va": "Cash 5 (VA)", "millionaireforlife_va": "Millionaire for Life (VA)", "bankamillion_va": "Bank a Million (VA)", } class StatusBar(ttk.Frame): """ Thin horizontal bar docked at the bottom of the main window. All public methods are safe to call from the main thread only. """ def __init__(self, parent, **kwargs): super().__init__(parent, relief="sunken", **kwargs) self._label = ttk.Label(self, text="Ready", anchor="w", padding=(6, 2)) self._label.pack(fill="x", expand=True) def set_text(self, text: str): self._label.config(text=text) def set_fetching(self): self._label.config(text="Fetching data…") def set_ready(self): self._label.config(text="Ready") def update_fetch_results(self, results: list): """ Build and display status text from a fetch_all() result list. Format: Last fetch: Powerball — 3 added, 2 skipped | Mega Millions (NY) — 5 added, 0 skipped | 2026-05-23 08:42 AM """ now = datetime.now().strftime("%Y-%m-%d %I:%M %p") parts = [] for r in results: name = _SOURCE_NAMES.get(r["source"], r["source"]) if r["status"] == "error": parts.append(f"{name} — ERROR: {r['message']}") else: parts.append(f"{name} — {r['added']} added, {r['skipped']} skipped") self._last_fetch_text = "Last fetch: " + " | ".join(parts) + f" | {now}" self.set_text(self._last_fetch_text) def append_match_alert(self, msg: str): """Append a prediction-match alert to the current status text.""" base = getattr(self, "_last_fetch_text", self._label.cget("text")) self.set_text(f"{base} • {msg}")