fix: smooth GUI during pipeline downloads and harden wizard connection test

GUI log batching (_poll_log now drains queue into a single CTkTextbox.insert
call per 80 ms tick instead of N calls, each with see("end") scroll).

_QueueWriter strips ANSI/CSI escape codes and bare \r before enqueuing so
tqdm progress output is legible in the log textbox. OSC sequences terminated
by both BEL (\x07) and ST (\x1b\) are handled.

Wizard "Test Connection" moved off the main thread: requests.get runs in a
daemon thread; result posted back via after(0, ...). Widget refs captured
before thread launch to prevent stale updates if user navigates away. Bare
except narrowed to TclError (destroyed-widget guard only).

Code quality: import os moved to module level in app.py; _read_raw_config()
helper extracted to deduplicate dual raw config.json reads; return type
annotations added to _get_view_class, _get_dashboard, and cfg property.

Tests: 11 new unit tests for _QueueWriter (RED -> GREEN on OSC-ST fix).
This commit is contained in:
Tran G. (Revernomad) Khoa
2026-04-08 17:27:25 +07:00
parent 903cd366e2
commit 85bc406236
6 changed files with 198 additions and 44 deletions

View File

@@ -1,10 +1,11 @@
from __future__ import annotations
import json
import threading
from tkinter import TclError, filedialog
from typing import Callable
import customtkinter as ctk
from tkinter import filedialog
from gui._constants import COLOR_OK, COLOR_ERROR, PROJECT_ROOT
from gui.locales import t
@@ -72,28 +73,46 @@ class SetupWizard(ctk.CTkToplevel):
self._conn_lbl.pack(side="left")
ctk.CTkButton(foot, text=t("wizard.btn_next"), width=90,
command=lambda: self._show(1)).pack(side="right")
ctk.CTkButton(foot, text=t("wizard.btn_test"), width=140,
self._test_btn = ctk.CTkButton(foot, text=t("wizard.btn_test"), width=140,
fg_color="transparent", border_width=1,
text_color=("gray10", "gray90"),
command=self._test).pack(side="right", padx=(0, 8))
command=self._test)
self._test_btn.pack(side="right", padx=(0, 8))
def _test(self) -> None:
self._conn_lbl.configure(text=t("wizard.testing"), text_color="gray")
self.update()
try:
import requests
r = requests.get(self._url.get(),
auth=(self._user.get(), self._pw.get()),
timeout=8)
if r.ok:
self._conn_lbl.configure(text=t("wizard.connected"),
text_color=COLOR_OK)
else:
self._conn_lbl.configure(text=t("wizard.http_error", code=r.status_code),
text_color=COLOR_ERROR)
except Exception as e:
self._conn_lbl.configure(text=t("wizard.conn_error", e=e),
text_color=COLOR_ERROR)
# Capture widget refs now — _clear() replaces them if the user
# navigates away and back while the request is in-flight.
lbl = self._conn_lbl
btn = self._test_btn
lbl.configure(text=t("wizard.testing"), text_color="gray")
btn.configure(state="disabled")
url = self._url.get()
auth = (self._user.get(), self._pw.get())
def worker() -> None:
try:
import requests
r = requests.get(url, auth=auth, timeout=8)
if r.ok:
result = (t("wizard.connected"), COLOR_OK)
else:
result = (t("wizard.http_error", code=r.status_code), COLOR_ERROR)
except Exception as e:
result = (t("wizard.conn_error", e=e), COLOR_ERROR)
self.after(0, lambda: _apply_test_result(lbl, btn, *result))
threading.Thread(target=worker, daemon=True).start()
def _apply_test_result(lbl: ctk.CTkLabel, btn: ctk.CTkButton,
text: str, color: str) -> None:
"""Update connection test result widgets. Silently ignores destroyed widgets."""
try:
lbl.configure(text=text, text_color=color)
btn.configure(state="normal")
except TclError:
pass # wizard was closed before the HTTP response arrived
# ── Page 2: paths ────────────────────────────────────────────────────────