feat(gui): warmup status indicator + completion callback (sub-track 4)
Sub-track 4 of startup_speedup_20260606. Adds per-frame GUI feedback during the AppController's background warmup: - render_warmup_status_indicator(app): module-level render fn called from render_main_interface. Shows 'Warming up... (N/M)' in warning color while pending, 'Imports: K failed' in error color on failure, or 'All imports ready (M modules)' in success color for 3 seconds after completion. Hidden otherwise. - _on_warmup_complete_callback(app, status): thread-safe callback registered with controller.on_warmup_complete() in App._post_init. Records timestamp + lock-protected toast list. - App._post_init: registers the callback. 6 new tests in tests/test_gui_warmup_indicator.py: - 2 importable-checks (function exists) - 3 callback-logic tests (timestamp, failures, thread-safety) - 1 live_gui smoke test (controller exposes warmup_status)
This commit is contained in:
@@ -395,6 +395,15 @@ class App:
|
||||
|
||||
def _post_init(self) -> None:
|
||||
theme.apply_current()
|
||||
# Register warmup completion callback (sub-track 4 of
|
||||
# startup_speedup_20260606). The callback runs on a background
|
||||
# _io_pool thread; it only sets primitive state on the App, which
|
||||
# is safe. The render_warmup_status_indicator() function reads
|
||||
# the timestamp to show a brief "ready" tag for 3 seconds.
|
||||
if hasattr(self.controller, "on_warmup_complete"):
|
||||
try:
|
||||
self.controller.on_warmup_complete(lambda status: _on_warmup_complete_callback(self, status))
|
||||
except Exception: pass
|
||||
|
||||
def _trigger_hot_reload(self) -> bool:
|
||||
from src.hot_reloader import HotReloader
|
||||
@@ -1302,6 +1311,7 @@ if __name__ == "__main__":
|
||||
def render_main_interface(app: App) -> None:
|
||||
render_error_tint(app)
|
||||
render_project_stale_tint(app)
|
||||
render_warmup_status_indicator(app)
|
||||
app.perf_monitor.start_frame()
|
||||
app._autofocus_response_tab = app.controller._autofocus_response_tab
|
||||
|
||||
@@ -3781,6 +3791,69 @@ def render_thinking_indicator(app: App) -> None:
|
||||
c = theme.get_color("status_error", alpha=alpha)
|
||||
imgui.text_colored(c, "THINKING..."); imgui.same_line()
|
||||
|
||||
def _on_warmup_complete_callback(app: App, status: dict) -> None:
|
||||
"""
|
||||
Thread-safe callback registered with controller.on_warmup_complete()
|
||||
during App._post_init. Records the completion timestamp; the
|
||||
indicator function uses it to show a brief "ready" tag. Also
|
||||
appends a message to a lock-protected list that the indicator
|
||||
(or the diagnostics panel) can read.
|
||||
Runs on a background _io_pool thread; only sets primitive state.
|
||||
[C: src/gui_2.py:render_warmup_status_indicator, src/gui_2.py:App._post_init, tests/test_gui_warmup_indicator.py:test_callback_sets_timestamp]
|
||||
"""
|
||||
try:
|
||||
app._warmup_completion_ts = time.time()
|
||||
pending = status.get("pending", [])
|
||||
completed = status.get("completed", [])
|
||||
failed = status.get("failed", [])
|
||||
total = len(pending) + len(completed) + len(failed)
|
||||
if failed: msg = f"Warmup finished with {len(failed)} failures ({total} modules)"
|
||||
else: msg = f"All imports ready ({total} modules)"
|
||||
if not hasattr(app, "_warmup_toast_lock"):
|
||||
import threading as _threading
|
||||
app._warmup_toast_lock = _threading.Lock()
|
||||
with app._warmup_toast_lock:
|
||||
if not hasattr(app, "_warmup_toast_messages"): app._warmup_toast_messages = []
|
||||
app._warmup_toast_messages.append((time.time(), msg))
|
||||
except Exception: pass
|
||||
|
||||
def render_warmup_status_indicator(app: App) -> None:
|
||||
"""
|
||||
Renders a per-frame warmup status line. Shows the progress of
|
||||
AppController's background warmup (Phase 2 of
|
||||
startup_speedup_20260606). Hidden when the controller has no warmup
|
||||
or warmup is done with no failures. Shows a transient "ready" tag
|
||||
for 3 seconds after completion.
|
||||
[C: src/gui_2.py:App._post_init, src/gui_2.py:render_main_interface, tests/test_gui_warmup_indicator.py:test_render_warmup_indicator_function_exists, tests/test_gui_warmup_indicator.py:test_callback_sets_timestamp]
|
||||
"""
|
||||
controller = getattr(app, "controller", None)
|
||||
if controller is None: return
|
||||
if not hasattr(controller, "warmup_status"): return
|
||||
try:
|
||||
status = controller.warmup_status()
|
||||
except Exception: return
|
||||
pending = status.get("pending", [])
|
||||
completed = status.get("completed", [])
|
||||
failed = status.get("failed", [])
|
||||
if pending:
|
||||
total = len(pending) + len(completed) + len(failed)
|
||||
done = len(completed) + len(failed)
|
||||
c = theme.get_color("status_warning")
|
||||
imgui.text_colored(c, f"Warming up... ({done}/{total})")
|
||||
return
|
||||
if failed:
|
||||
c = theme.get_color("status_error")
|
||||
imgui.text_colored(c, f"Imports: {len(failed)} failed")
|
||||
return
|
||||
# Steady state + transient 3s "ready" tag after completion.
|
||||
ts = getattr(app, "_warmup_completion_ts", 0.0)
|
||||
if ts > 0 and (time.time() - ts) < 3.0:
|
||||
total = len(completed) + len(failed)
|
||||
c = theme.get_color("status_success")
|
||||
imgui.text_colored(c, f"All imports ready ({total} modules)")
|
||||
return
|
||||
# No render: warmup done, no failures, transient window expired.
|
||||
|
||||
def render_synthesis_panel(app: App) -> None:
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user