fix(calibrate): case-insensitive window title match; show visible titles on miss

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-04-16 06:15:22 +00:00
parent c23a66fd0b
commit f6ffeb22ec

View File

@@ -67,18 +67,24 @@ def write_config(data: dict, out_dir: Path) -> Path:
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
def _capture_window(title_substr: str): def _capture_window(title_substr: str):
"""Screenshot the first window matching *title_substr*. Windows-only (mss+pygetwindow). """Screenshot the first window whose title CONTAINS *title_substr* (case-insensitive).
Returns a PIL RGB Image. Windows-only (mss+pygetwindow). Returns a PIL RGB Image.
""" """
import mss # type: ignore[import-untyped] import mss # type: ignore[import-untyped]
import pygetwindow as gw # type: ignore[import-untyped] import pygetwindow as gw # type: ignore[import-untyped]
from PIL import Image from PIL import Image
wins = gw.getWindowsWithTitle(title_substr) needle = title_substr.lower()
if not wins: all_titles = [t for t in gw.getAllTitles() if t]
raise RuntimeError(f"No window matching title substring: {title_substr!r}") matching = [t for t in all_titles if needle in t.lower()]
win = wins[0] if not matching:
preview = "\n ".join(sorted(set(all_titles))[:40])
raise RuntimeError(
f"No window title contains {title_substr!r} (case-insensitive).\n"
f"Visible windows (first 40):\n {preview}"
)
win = gw.getWindowsWithTitle(matching[0])[0]
try: try:
win.activate() win.activate()
except Exception: except Exception: