83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""Der Bildschirm für den lebenden Zeiger (hand/zeiger.Lauf) am echten Mac - dieselbe
|
|
Schnittstelle wie klonmaus.Bildschirm: bewegen, position, grenzen, schilder, stelle, schirm.
|
|
|
|
Bewegt wird der echte Zeiger (hand/click.py, Ereignisse mit unserer PID - das Cockpit hält sie
|
|
nie für deine Eingabe). Gesehen wird die echte Zeigerstelle: weicht sie von der zuletzt
|
|
gefahrenen ab, hast du die Maus bewegt, und der Zeiger ruht (zeiger.py, ruhe_mensch).
|
|
Grenzen: die Fläche, in der die Tische gekachelt liegen (sicht/tische.flaeche) - nie über
|
|
dem Cockpit oder fremden Fenstern.
|
|
"""
|
|
import os
|
|
import sys
|
|
import threading
|
|
import time
|
|
|
|
import fenster
|
|
|
|
_wurzel = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
|
def _click():
|
|
return sys.modules.get("cpclick") or __import__("click")
|
|
|
|
|
|
def _tische():
|
|
pfad = os.path.join(_wurzel, "sicht")
|
|
if pfad not in sys.path:
|
|
sys.path.append(pfad)
|
|
import tische
|
|
return tische
|
|
|
|
|
|
class Bildschirm:
|
|
AUFFRISCHEN_S = 1.5
|
|
|
|
def __init__(self):
|
|
self.sperre = threading.RLock()
|
|
self.liste, self.zuletzt = [], 0.0
|
|
t = _tische()
|
|
x, y, w, h = t.flaeche(t._mac_arbeitsbereich(), t._leiste())
|
|
self.grenzen = (float(x), float(y), float(x + w), float(y + h))
|
|
self.auffrischen(True)
|
|
|
|
def auffrischen(self, sofort=False):
|
|
jetzt = time.monotonic()
|
|
if not sofort and jetzt - self.zuletzt < self.AUFFRISCHEN_S:
|
|
return
|
|
self.zuletzt = jetzt
|
|
try:
|
|
neu = fenster.tischfenster()
|
|
except Exception:
|
|
return
|
|
with self.sperre:
|
|
self.liste = neu
|
|
|
|
def bewegen(self, x, y):
|
|
c = _click()
|
|
c._senden(c.MOVED, x, y)
|
|
|
|
def position(self):
|
|
return _click().zeiger()
|
|
|
|
def schilder(self):
|
|
"""Sitzschilder aller Tische in Bildschirmpunkten - Hover öffnet dort das Profil."""
|
|
import sitzen
|
|
self.auffrischen()
|
|
aus = []
|
|
for f in list(self.liste):
|
|
ox, oy, w, h = f["rect"]
|
|
for fx0, fy0, fx1, fy1 in sitzen.SCHILDER.values():
|
|
aus.append((ox + w * fx0, oy + h * fy0, ox + w * fx1, oy + h * fy1))
|
|
return aus
|
|
|
|
def stelle(self, raum, fx, fy):
|
|
self.auffrischen()
|
|
f = next((f for f in self.liste if raum and f.get("raum") == raum), None) or (self.liste or [None])[0]
|
|
if f is None:
|
|
return None
|
|
ox, oy, w, h = f["rect"]
|
|
return ox + w * fx, oy + h * fy
|
|
|
|
def schirm(self, f, pos):
|
|
return pos # die Rahmen sind schon Bildschirmpunkte
|