Preserve tested Verify source, authoritative READY checks, bounded bridge retries, diagnostics and failure-only reporting. Include 336-test suite and packaging assets; exclude live Mentor samples, field logs, backups and distributions.
54 lines
2.7 KiB
Python
54 lines
2.7 KiB
Python
"""Test ReusableCircuit startup on a non-input desktop, without switching it."""
|
|
import json
|
|
import subprocess
|
|
import time
|
|
import sys
|
|
from pathlib import Path
|
|
import win32con
|
|
import win32gui
|
|
import win32process
|
|
import win32service
|
|
|
|
root = Path(__file__).resolve().parents[1]/'build'/'background-probe'
|
|
root.mkdir(parents=True, exist_ok=True)
|
|
desktop = win32service.CreateDesktop('CbbVerifyBackgroundProbe', 0, win32con.GENERIC_ALL, None)
|
|
info = win32process.STARTUPINFO()
|
|
info.lpDesktop = r'winsta0\CbbVerifyBackgroundProbe'
|
|
pcb = Path(r'F:\Sync Tool Skyworth\Work Maps\Skyworth_CBB_Lib\Mentor_lib_EE7.9\ReusableBlocksLP\Audio_D2128_ESD\Work\PCB\Audio_D2128_ESD.pcb')
|
|
exe = r'D:\Mentor\7.9.5EE\SDD_HOME\wg\win32\bin\ExpeditionPCB.exe'
|
|
foreground = win32gui.GetForegroundWindow()
|
|
cursor = win32gui.GetCursorPos()
|
|
if '--attach' not in sys.argv:
|
|
process_handle, thread_handle, pid, tid = win32process.CreateProcess(exe, subprocess.list2cmdline([exe, str(pcb), '-ReusableCircuit']), None, None, False, 0, None, None, info)
|
|
thread_handle.Close()
|
|
print('pcb', pid, 'desktop', info.lpDesktop, flush=True)
|
|
last = None
|
|
with (root/'windows.jsonl').open('a', encoding='utf-8') as log:
|
|
for _ in range(180):
|
|
try:
|
|
windows = desktop.EnumDesktopWindows()
|
|
except Exception:
|
|
windows = []
|
|
state = []
|
|
for hwnd in windows:
|
|
hwnd = int(hwnd)
|
|
if not win32gui.IsWindowVisible(hwnd): continue
|
|
children = []
|
|
win32gui.EnumChildWindows(hwnd, lambda c, _: children.append(c), None)
|
|
texts = [win32gui.GetWindowText(c) for c in children]
|
|
title = win32gui.GetWindowText(hwnd)
|
|
pid = win32process.GetWindowThreadProcessId(hwnd)[1]
|
|
state.append({'hwnd': hwnd, 'pid': pid, 'title': title, 'texts': texts if win32gui.GetClassName(hwnd) == '#32770' else []})
|
|
if title == 'Tip of the Day' or 'Select the desired product license' in texts:
|
|
buttons = [c for c in children if win32gui.GetDlgCtrlID(c) == 1]
|
|
if buttons: win32gui.PostMessage(buttons[0], win32con.BM_CLICK, 0, 0)
|
|
if state != last:
|
|
event = {'time': time.strftime('%H:%M:%S'), 'windows': state, 'foreground': win32gui.GetForegroundWindow()}
|
|
line = json.dumps(event, ensure_ascii=False)
|
|
log.write(line+'\n');log.flush();print(line, flush=True);last=state
|
|
if any('Reusable Block - [Audio_D2128_ESD]' in x['title'] for x in state):
|
|
print('BACKGROUND_DOC_WINDOW_READY', 'foreground_before', foreground, 'foreground_now', win32gui.GetForegroundWindow(), flush=True)
|
|
break
|
|
time.sleep(.5)
|
|
print('Desktop retained by PCB process; no SwitchDesktop was called.', flush=True)
|