"""Screen capture utility. `capture_screen()` grabs the current screen via mss and returns a PIL RGB image. Bounding-box selection of the inventory area is done in the GUI by two clicks (top-left + bottom-right) — far more reliable than heuristic auto-detection across the many possible game UI scales and DPI settings. """ from __future__ import annotations from dataclasses import dataclass from typing import Tuple from PIL import Image @dataclass class GridBBox: left: int top: int right: int bottom: int def as_tuple(self) -> Tuple[int, int, int, int]: return (self.left, self.top, self.right, self.bottom) def capture_screen(monitor: int = 1) -> Image.Image: """Capture the full screen of the given monitor as a PIL RGB image. monitor=0 = all monitors combined, 1 = primary on most systems. Falls back to monitor 0 if the requested index is missing. """ import mss # lazy: keep mss optional for renderer/CLI-only use with mss.mss() as sct: try: mon = sct.monitors[monitor] except IndexError: mon = sct.monitors[0] shot = sct.grab(mon) img = Image.frombytes("RGB", shot.size, shot.bgra, "raw", "BGRX") return img