import psutil
import win32gui
import win32process

print("--- DIAGNOSTIC SCRIPT ---")
python_pids = [p.pid for p in psutil.process_iter(['name']) if 'python' in p.info['name'].lower()]
print(f"Active Python PIDs: {python_pids}")

found_windows = []
def enum_cb(hwnd, _):
    _, pid = win32process.GetWindowThreadProcessId(hwnd)
    if pid in python_pids:
        title = win32gui.GetWindowText(hwnd)
        visible = win32gui.IsWindowVisible(hwnd)
        rect = win32gui.GetWindowRect(hwnd)
        found_windows.append((hwnd, pid, title, visible, rect))

win32gui.EnumWindows(enum_cb, None)
for hwnd, pid, title, visible, rect in found_windows:
    print(f"HWND: {hwnd} | PID: {pid} | Visible: {visible} | Rect: {rect} | Title: '{title}'")

if not found_windows:
    print("No windows found belonging to Python processes!")
