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:
@@ -67,18 +67,24 @@ def write_config(data: dict, out_dir: Path) -> Path:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
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 pygetwindow as gw # type: ignore[import-untyped]
|
||||
from PIL import Image
|
||||
|
||||
wins = gw.getWindowsWithTitle(title_substr)
|
||||
if not wins:
|
||||
raise RuntimeError(f"No window matching title substring: {title_substr!r}")
|
||||
win = wins[0]
|
||||
needle = title_substr.lower()
|
||||
all_titles = [t for t in gw.getAllTitles() if t]
|
||||
matching = [t for t in all_titles if needle in t.lower()]
|
||||
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:
|
||||
win.activate()
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user