75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Setzt eine Entscheidung des Kerns in einen Klick um - mit Sicherungen.
|
|
|
|
Sicherungen:
|
|
* Aussetzen wird nicht geklickt.
|
|
* Der Klick geht in das Fenster des richtigen Tisches (nicht in irgendeines).
|
|
* Eine Stopp-Datei schaltet das Klicken ab, ohne den Lauf zu beenden.
|
|
* Vor dem Klick wird geprüft, dass das Fenster noch da ist.
|
|
|
|
from act import ausfuehren
|
|
"""
|
|
import os as _os, sys as _sys
|
|
_w = _os.path.dirname(_os.path.abspath(__file__))
|
|
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "hand")):
|
|
_w = _os.path.dirname(_w)
|
|
WURZEL = _w
|
|
for _u in ("lesen", "entscheiden", "hand", "lobby", "korpus", "betrieb"):
|
|
_q = _os.path.join(_w, _u)
|
|
if _os.path.isdir(_q) and _q not in _sys.path:
|
|
_sys.path.insert(0, _q)
|
|
import importlib.util
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
import fenster
|
|
|
|
BASE = os.path.dirname(os.path.abspath(__file__))
|
|
STOPP = os.path.join(BASE, "scratch", "stop")
|
|
_spec = importlib.util.spec_from_file_location("cpclick", os.path.join(BASE, "click.py"))
|
|
click = importlib.util.module_from_spec(_spec)
|
|
_spec.loader.exec_module(click)
|
|
|
|
WARTEZEIT = 0.30
|
|
GESPERRT = {"ABSTAIN", None}
|
|
ZU_TAT = {"FOLD": "fold", "CHECK": "call", "CALL": "call", "RAISE": "raise"}
|
|
|
|
|
|
def gestoppt():
|
|
return os.path.exists(STOPP)
|
|
|
|
|
|
def ziel_fuer(aktion):
|
|
return ZU_TAT.get(aktion)
|
|
|
|
|
|
def ausfuehren(entscheidung, raum=None, warten=None):
|
|
"""Klickt die Entscheidung im Fenster des Raums. Gibt zurück, was geklickt wurde.
|
|
|
|
`warten` ist die Denkzeit in Sekunden; die Knopfleiste braucht ohnehin kurz.
|
|
"""
|
|
aktion = entscheidung.get("action")
|
|
if aktion in GESPERRT or gestoppt():
|
|
return None
|
|
ziel = ziel_fuer(aktion)
|
|
if not ziel:
|
|
return None
|
|
f = fenster.fenster_fuer(raum) if raum else None
|
|
rect = f["rect"] if f else click.window_rect()
|
|
pid = f["pid"] if f else None
|
|
if not rect:
|
|
return None
|
|
time.sleep(max(warten or 0.0, WARTEZEIT))
|
|
px, py = click.point_for(ziel, rect)
|
|
click.click(px, py, pid=pid)
|
|
groesse = entscheidung.get("size")
|
|
return ziel + (f" {groesse}" if groesse else "")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Fenster:", click.window_rect())
|
|
print("gestoppt:", gestoppt())
|
|
for name in click.SPOTS:
|
|
print(f" {name:<8} {click.point_for(name, click.window_rect())}")
|