Files
aza/AzA march 2026/_test_chat_singleton_count.py

57 lines
1.9 KiB
Python
Raw Normal View History

2026-06-10 22:55:03 +02:00
#!/usr/bin/env python3
"""Hilfsskript: zaehlt AzA-Empfang-Huelle und Kontakte-Fenster (Win32, ohne Patientendaten)."""
from __future__ import annotations
import ctypes
import sys
from ctypes import wintypes
EMPFANG_PREFIXES = ("AzA-Empfang", "AzA Empfang Chat")
KONTAKT_PREFIXES = ("AzA Kontakte",)
def _matches(title: str, prefixes: tuple[str, ...]) -> bool:
return any(title == p or title.startswith(p) for p in prefixes if p)
def count_azA_chat_windows() -> dict:
if sys.platform != "win32":
return {"error": "nur Windows"}
user32 = ctypes.windll.user32
empfang: list[tuple[int, int, str]] = []
kontakt: list[tuple[int, int, str]] = []
@ctypes.WINFUNCTYPE(ctypes.c_bool, wintypes.HWND, wintypes.LPARAM)
def _cb(hwnd, _lp):
visible = bool(user32.IsWindowVisible(hwnd) or user32.IsIconic(hwnd))
if not visible:
return True
buf = ctypes.create_unicode_buffer(320)
user32.GetWindowTextW(hwnd, buf, 320)
t = buf.value or ""
p = wintypes.DWORD()
user32.GetWindowThreadProcessId(hwnd, ctypes.byref(p))
pid = int(p.value)
if _matches(t, EMPFANG_PREFIXES):
empfang.append((int(hwnd), pid, t))
elif _matches(t, KONTAKT_PREFIXES):
kontakt.append((int(hwnd), pid, t))
return True
user32.EnumWindows(_cb, 0)
return {
"empfang_count": len(empfang),
"kontakt_count": len(kontakt),
"empfang": empfang,
"kontakt": kontakt,
}
if __name__ == "__main__":
r = count_azA_chat_windows()
print(f"Empfang-Huellen: {r.get('empfang_count', 0)}")
print(f"Kontakte-Fenster: {r.get('kontakt_count', 0)}")
for label, items in (("Empfang", r.get("empfang", [])), ("Kontakt", r.get("kontakt", []))):
for hwnd, pid, title in items:
print(f" {label}: HWND={hwnd} PID={pid} title={title!r}")