- New ScreenshotFrame: capture screen / load PNG, two-click bbox, threaded template matching, editable preview grid for corrections - ManualFrame kept as second tab for users who prefer typing counts - capture.py: screen grab via mss (cross-platform) - requirements: add mss>=6.0 for screen capture support Closes the gap from v0.1.0 where users had to manually count every slab — now they aim, click two corners, and edit any mis-recognized cell. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
"""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
|