feat(calibrate): --delay countdown + messagebox warning before capture

Same fix as atm debug: desktop snapshot happens several seconds after user
confirms, giving time to alt-tab TradeStation to the foreground and get
rid of terminal/IDE windows covering it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-16 06:49:07 +00:00
parent 780b1d67dd
commit e7189742bf
2 changed files with 27 additions and 3 deletions

View File

@@ -363,14 +363,21 @@ _COLOR_ORDER = [
]
def run_calibration(out_dir: Path, screenshot: Path | None = None) -> Path:
def run_calibration(
out_dir: Path,
screenshot: Path | None = None,
capture_delay: float = 3.0,
) -> Path:
"""Launch the guided calibration wizard and return the saved config path.
If *screenshot* is provided, use that image instead of live window capture
(useful for dev/testing on non-Windows hosts).
*capture_delay* seconds countdown before the full-desktop snapshot — gives
the user time to bring TradeStation to the foreground and minimize anything
that covers it (PowerShell, VS Code, etc.).
"""
import tkinter as tk
from tkinter import simpledialog
from tkinter import simpledialog, messagebox
from PIL import Image
out_dir = Path(out_dir)
@@ -407,6 +414,19 @@ def run_calibration(out_dir: Path, screenshot: Path | None = None) -> Path:
# Default: region-select on full desktop (reliable with GPU-rendered apps).
# Returns (cropped image, virtual-desktop region) so runtime capture can
# re-crop the same area without needing pygetwindow to find the chart.
if capture_delay > 0:
root_msg = tk.Tk(); root_msg.withdraw()
messagebox.showinfo(
"Ready?",
f"Bring TradeStation to the foreground so it's FULLY VISIBLE.\n\n"
f"Minimize this terminal / VS Code / anything covering the chart.\n\n"
f"After you press OK, the desktop screenshot is taken in {capture_delay:.0f}s.",
parent=root_msg,
)
root_msg.destroy()
for i in range(int(capture_delay), 0, -1):
print(f" capture in {i}...", flush=True)
time.sleep(1.0)
try:
pil_img, chart_region = _capture_fullscreen_region()
except ValueError:

View File

@@ -35,6 +35,10 @@ def main(argv=None) -> None:
"--screenshot", type=Path, default=None, metavar="PATH",
help="Use a saved screenshot instead of live window capture (dev/testing)",
)
p_cal.add_argument(
"--delay", type=float, default=3.0, metavar="SEC",
help="Countdown before desktop snapshot (bring TradeStation to front). Default 3.",
)
# label
p_label = sub.add_parser("label", help="Label dot-colour samples (Tk)")
@@ -103,7 +107,7 @@ def _cmd_calibrate(args) -> None:
from atm.calibrate import run_calibration
except ImportError as exc:
sys.exit(f"calibrate module not available: {exc}")
run_calibration(Path("configs"), screenshot=args.screenshot)
run_calibration(Path("configs"), screenshot=args.screenshot, capture_delay=args.delay)
def _cmd_label(args) -> None: