""" Debug screenshot tool — capture a clean screenshot from the emulator and save it so you can crop reference templates from it. Usage: source .venv/bin/activate python debug_screenshot.py # saves sos_screenshot_.png python debug_screenshot.py --output my_screen.png python debug_screenshot.py --port 5556 """ import argparse import logging import os import sys from datetime import datetime sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from core.adb import AdbClient from core.vision import Vision def main(): parser = argparse.ArgumentParser( description="Capture a debug screenshot from the emulator" ) parser.add_argument("--host", default="127.0.0.1") parser.add_argument("--port", type=int, default=5555) parser.add_argument("--output", "-o", help="Output PNG path") parser.add_argument("-v", "--verbose", action="store_true") args = parser.parse_args() level = logging.DEBUG if args.verbose else logging.INFO logging.basicConfig(level=level, format="%(message)s") log = logging.getLogger("sos") if not args.output: ts = datetime.now().strftime("%Y%m%d_%H%M%S") args.output = f"sos_screenshot_{ts}.png" print(f"[*] Connecting ADB to {args.host}:{args.port}...") adb = AdbClient(args.host, args.port) adb.connect() if not adb.is_connected(): print("[!] ADB not connected. Is BlueStacks running with ADB enabled?") sys.exit(1) print(f"[*] ADB connected: {adb.serial}") vision = Vision(adb) print("[*] Capturing screenshot (in-memory)...") vision.capture() w, h = vision.size print(f"[*] Device resolution: {w}x{h}") print(f"[*] Saving to {args.output}...") vision.save_debug_screenshot(args.output) # Also print pixel info utility print(f"\n[*] Saved: {args.output} ({os.path.getsize(args.output)} bytes)") print() print("NEXT STEPS:") print(f" 1. Open {args.output} in an image editor") print(f" 2. Crop the button/icon you want to click") print(f" 3. Save the crop to templates/.png") print(f" 4. Add a step in playbook/default.yaml referencing it") print() print("PIXEL CHECK: read a pixel color from the saved image:") print(f" python -c \"from PIL import Image; im=Image.open('{args.output}'); print(im.getpixel((100,200)))\"") print() adb.disconnect() if __name__ == "__main__": main()