publish eve_orehold_watcher.py
This commit is contained in:
parent
6feb961179
commit
3f7d717685
1 changed files with 35 additions and 0 deletions
|
|
@ -82,6 +82,41 @@ def save_region(cp, left, top, width, height):
|
||||||
cp.write(f)
|
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("<ButtonPress-1>", on_press)
|
||||||
|
canvas.bind("<B1-Motion>", on_drag)
|
||||||
|
canvas.bind("<ButtonRelease-1>", on_release)
|
||||||
|
root.bind("<Escape>", lambda e: root.destroy())
|
||||||
|
print(prompt)
|
||||||
|
root.mainloop()
|
||||||
|
return coords.get("r")
|
||||||
|
|
||||||
|
|
||||||
RATE_PATH = os.path.join(HERE, ".mining_rate")
|
RATE_PATH = os.path.join(HERE, ".mining_rate")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue