diff --git a/eve_orehold_watcher.py b/eve_orehold_watcher.py index 9b39f41..43e3c04 100644 --- a/eve_orehold_watcher.py +++ b/eve_orehold_watcher.py @@ -82,6 +82,41 @@ def save_region(cp, left, top, width, height): cp.write(f) +def snip_region(prompt="Drag a box around the area to watch. Esc to cancel."): + """Full-screen drag-select; returns (left, top, width, height) or None. Reusable + by any watcher that needs a one-time region (survey scanner, Local window, ...).""" + import tkinter as tk + coords = {} + root = tk.Tk() + root.attributes("-fullscreen", True) + root.attributes("-alpha", 0.25) + root.configure(bg="black") + canvas = tk.Canvas(root, cursor="cross", bg="black", highlightthickness=0) + canvas.pack(fill=tk.BOTH, expand=True) + rect = {"id": None, "x0": 0, "y0": 0} + + def on_press(e): + rect["x0"], rect["y0"] = e.x_root, e.y_root + rect["id"] = canvas.create_rectangle(e.x, e.y, e.x, e.y, outline="red", width=2) + + def on_drag(e): + canvas.coords(rect["id"], rect["x0"] - root.winfo_rootx(), + rect["y0"] - root.winfo_rooty(), e.x, e.y) + + def on_release(e): + x0, y0, x1, y1 = rect["x0"], rect["y0"], e.x_root, e.y_root + coords["r"] = (min(x0, x1), min(y0, y1), abs(x1 - x0), abs(y1 - y0)) + root.destroy() + + canvas.bind("", on_press) + canvas.bind("", on_drag) + canvas.bind("", on_release) + root.bind("", lambda e: root.destroy()) + print(prompt) + root.mainloop() + return coords.get("r") + + RATE_PATH = os.path.join(HERE, ".mining_rate")