Files
pokerfreak-shell/hand/fenster.py
T
mmintelandClaude Opus 5.5 594ba1b29c Klon: mehrere Hände, Demo-Modus, mehrere Fenster, Schalter COINPOKER_MOCK
- hand/umgebung.py: COINPOKER_MOCK=1 richtet Log, Debug-Port und Fensterregel
  gemeinsam auf den Klon; runner.py, fenster.py und cdp.mjs fragen ihn
- Klon spielt Hand um Hand (eigene Handnummer, vertauschte Farben), zeigt
  Chips, Einsätze, Pot, Uhr und Handnummer; --haende N, --demo spielt selbst
- start.py ohne Angaben liegt dort, wohin der Schalter zeigt (9401/9402)
- Join trägt coinpoker-join-content; Tischfenster öffnen versetzt
- Specs: Schalter, Kettentest über drei Hände (auch zwei Tische), Demo,
  zwei Fenster zugleich ohne Übersprechen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 17:08:27 +01:00

142 lines
4.4 KiB
Python

#!/usr/bin/env python3
"""Findet die Tischfenster und ordnet sie dem Raumnamen zu.
Tischfenster gehören zum Spielprozess ("CoinPoker Game"); das Lobbyfenster
gehört zur App. Die Zuordnung läuft zuerst über die Tischnummer im Titel -
Übungstische tragen aber nur "CoinPoker" als Titel, deshalb gibt es als
Rückfall: gibt es genau ein Tischfenster, ist es das richtige.
Mit COINPOKER_MOCK=1 (Klon aus mock/) zählt statt des Prozesses der Titel
`NLH <Nummer>` - der Klon-Tisch ist ein Chrome-Fenster.
python3 fenster.py --list
"""
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 os
import re
import subprocess
import sys
import umgebung
NUMMER = re.compile(r"\b(\d{5,})\b")
MOCK_TITEL = re.compile(r"^NLH \d{5,}\b")
MOCK_PROFIL = "coinpoker-mock" # Profilordner des Klon-Chromes, siehe mock/start.py
def mock():
return umgebung.mock()
def prozess_muster():
return f"CoinPoker|{MOCK_PROFIL}" if mock() else "CoinPoker"
def osa(script):
r = subprocess.run(["osascript", "-e", script], capture_output=True, text=True)
return (r.stdout or r.stderr).strip()
def prozesse():
r = subprocess.run(["pgrep", "-f", prozess_muster()], capture_output=True, text=True)
return [int(p) for p in r.stdout.split()]
def ist_spielprozess(pid):
r = subprocess.run(["ps", "-o", "command=", "-p", str(pid)],
capture_output=True, text=True)
return "CoinPoker Game" in r.stdout
def _zahl(text, i):
try:
return float(text.replace(" ", "").split(",")[i])
except Exception:
return None
def fenster_von(pid):
proc = f'(first process whose unix id is {pid})'
try:
anzahl = int(osa(f'tell application "System Events" to tell {proc} to count of windows'))
except Exception:
return []
ergebnis = []
for i in range(1, anzahl + 1):
titel = osa(f'tell application "System Events" to tell {proc} to get name of window {i}')
if not titel or "error" in titel.lower():
continue
pos = osa(f'tell application "System Events" to tell {proc} to get position of window {i}')
groesse = osa(f'tell application "System Events" to tell {proc} to get size of window {i}')
if "," not in pos or "," not in groesse:
continue
x, y = _zahl(pos, 0), _zahl(pos, 1)
w, h = _zahl(groesse, 0), _zahl(groesse, 1)
if None in (x, y, w, h):
continue
treffer = NUMMER.search(titel)
ergebnis.append({"pid": pid, "titel": titel, "rect": (x, y, w, h),
"tisch": treffer.group(1) if treffer else None,
"tischfenster": (bool(MOCK_TITEL.match(titel)) if umgebung.fensterregel() == "titel"
else ist_spielprozess(pid))})
return ergebnis
def alle():
ergebnis = []
for pid in prozesse():
ergebnis += fenster_von(pid)
return ergebnis
def tischfenster():
return [f for f in alle() if f["tischfenster"]]
def fenster_fuer(raum):
"""Das Fenster zum Raum - samt Prozess, damit der Klick dorthin geht."""
nummer = tisch_id(raum)
fenster = tischfenster()
if nummer:
for f in fenster:
if f["tisch"] == nummer:
return f
return fenster[0] if len(fenster) == 1 else None
def tisch_id(raum):
treffer = NUMMER.findall(raum or "")
return treffer[-1] if treffer else None
def rect_fuer(raum):
"""Rahmen des Fensters zu diesem Raum - oder None."""
nummer = tisch_id(raum)
fenster = tischfenster()
if nummer:
for f in fenster:
if f["tisch"] == nummer:
return f["rect"]
if len(fenster) == 1:
return fenster[0]["rect"]
return None
if __name__ == "__main__":
fenster = alle()
print(f"{len(fenster)} Fenster gefunden")
for f in fenster:
art = "Tischfenster" if f["tischfenster"] else "Lobby"
kennung = f" (Nr {f['tisch']})" if f["tisch"] else ""
print(f" pid {f['pid']} {art:<12}{kennung} {f['rect']} {f['titel'][:40]}")
for raum in ("Big Ben 1663167", "NLH 1662471 - x"):
print(f" rect_fuer({raum!r}) -> {rect_fuer(raum)}")