05/23 Phase 2
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
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)",
|
||||
}
|
||||
|
||||
|
||||
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")
|
||||
text = "Last fetch: " + " | ".join(parts) + f" | {now}"
|
||||
self.set_text(text)
|
||||
Reference in New Issue
Block a user