feat(ui): Qt progress window with Prism-Launcher-inspired dark palette
cloud-sync now ships a real Qt UI alongside the tkinter fallback.
Architecture:
- HeadlessProgress: --no-gui path, plain stdout
- TkProgressWindow: stdlib fallback when Qt isn't installed
- QtProgressWindow: preferred path; supports both PySide6 and PyQt6
(interchangeable APIs for our subset)
The factory in ui.py picks Qt → tkinter → headless. Tk stays so the
zipapp still works on bare Python with no extras.
Threading: QApplication runs on the main thread (started by run_with
via QDialog.exec). The restic worker runs on a daemon threading.Thread.
Cross-thread UI updates go via a Signal on a bridge QObject so Qt
auto-marshals them onto the main thread via a queued connection.
Cancellation: WM close + Cancel button both set a flag. sync.pull/push
pass ui.is_cancelled as restic.run's cancel_check; the subprocess gets
killed and returns -1 → exit 1.
Theme: Fusion style + Prism's dark palette (RGB values copied as facts
from PrismLauncher's DarkTheme.cpp). Override with PRISM_THEME=off.
Pyz size went 20 KB → 36 KB (added ui.py + ui_qt.py).
33 tests still green.
This commit is contained in:
+43
-5
@@ -23,10 +23,12 @@ import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.request
|
||||
import zipfile
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from .cli import Args
|
||||
|
||||
@@ -107,23 +109,59 @@ def run(
|
||||
env: dict[str, str] | None = None,
|
||||
cwd: Path | None = None,
|
||||
timeout: int = 900,
|
||||
cancel_check: Callable[[], bool] | None = None,
|
||||
) -> tuple[int, str]:
|
||||
"""Run restic. Inherits stderr to caller's terminal for live progress.
|
||||
Returns (returncode, captured_stdout)."""
|
||||
Returns (returncode, captured_stdout).
|
||||
|
||||
When cancel_check is supplied, polls every 100 ms; if it returns True,
|
||||
kills restic and returns ``(-1, "")``.
|
||||
"""
|
||||
merged_env = dict(os.environ)
|
||||
if env:
|
||||
merged_env.update(env)
|
||||
p = subprocess.run( # noqa: S603 — controlled invocation
|
||||
|
||||
if cancel_check is None:
|
||||
p_run = subprocess.run( # noqa: S603
|
||||
[str(binary), *args],
|
||||
cwd=str(cwd) if cwd else None,
|
||||
env=merged_env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=sys.stderr,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
check=False,
|
||||
)
|
||||
return p_run.returncode, p_run.stdout
|
||||
|
||||
# Cancel-capable path: spawn + poll
|
||||
p = subprocess.Popen( # noqa: S603
|
||||
[str(binary), *args],
|
||||
cwd=str(cwd) if cwd else None,
|
||||
env=merged_env,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=sys.stderr,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
check=False,
|
||||
)
|
||||
return p.returncode, p.stdout
|
||||
deadline = time.monotonic() + timeout
|
||||
while p.poll() is None:
|
||||
if cancel_check():
|
||||
p.kill()
|
||||
try:
|
||||
p.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
return -1, ""
|
||||
if time.monotonic() > deadline:
|
||||
p.kill()
|
||||
try:
|
||||
p.wait(timeout=5)
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
raise subprocess.TimeoutExpired([str(binary), *args], timeout)
|
||||
time.sleep(0.1)
|
||||
out = p.stdout.read() if p.stdout else ""
|
||||
return p.returncode, out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user