Files
cbb-refresh-verify-795/tools/probe_dialog_capture.py
阿白叔 11a2b2e46e Import CBB refresh verify r4 stability baseline
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.
2026-09-29 15:05:20 +08:00

96 lines
4.5 KiB
Python

"""Capture the unidentified Workbook/PCB startup dialog's pixels on a private desktop.
The dialog titled 'Expedition PCB' with Yes/No buttons has no enumerable static
text, so its message must be read from an image. Runs against the fixture copy
first; nothing is saved and the PCB is killed at the end.
Output: build/dialog-capture/dialog-*.bmp (converted to PNG by the caller).
"""
import subprocess, time
from pathlib import Path
import faulthandler
import win32con, win32gui, win32process, win32service
faulthandler.dump_traceback_later(180, exit=True)
ROOT = Path(__file__).resolve().parents[1]
LIBRARY = Path(r'F:\Sync Tool Skyworth\Work Maps\Skyworth_CBB_Lib\Mentor_lib_EE7.9\mentor_lib.lmc')
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'
OUT = ROOT/'build'/'dialog-capture'
OUT.mkdir(parents=True, exist_ok=True)
DESKTOP = 'CbbDialogCapture' + __import__('uuid').uuid4().hex[:8]
def step(message):
print(f'[{time.strftime("%H:%M:%S")}] {message}', flush=True)
desktop = win32service.CreateDesktop(DESKTOP, 0, win32con.GENERIC_ALL, None)
desktop.SetThreadDesktop()
startup = win32process.STARTUPINFO(); startup.lpDesktop = 'winsta0\\' + DESKTOP
handle, thread, pid, _ = win32process.CreateProcess(
EXE, subprocess.list2cmdline([EXE, str(PCB), '-ReusableCircuit']), None, None, False, 0, None, None, startup)
thread.Close()
step(f'pcb pid={pid} (fixture library)')
captured, handled = set(), set()
deadline = time.monotonic() + 120
try:
while time.monotonic() < deadline:
windows = []
win32gui.EnumWindows(lambda h, _: windows.append(h), None)
alive = False
for hwnd in windows:
try:
if win32process.GetWindowThreadProcessId(hwnd)[1] != pid or not win32gui.IsWindowVisible(hwnd):
continue
if win32gui.GetClassName(hwnd) != '#32770':
continue
alive = True
children = []
win32gui.EnumChildWindows(hwnd, lambda c, _: children.append(c), None)
texts = [win32gui.GetWindowText(c) for c in children]
title = win32gui.GetWindowText(hwnd)
ids = [win32gui.GetDlgCtrlID(c) for c in children]
if hwnd not in captured:
import win32ui
captured.add(hwnd)
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
width, height = right-left, bottom-top
window_dc = win32gui.GetWindowDC(hwnd)
source = win32ui.CreateDCFromHandle(window_dc)
memory = source.CreateCompatibleDC()
bitmap = win32ui.CreateBitmap(); bitmap.CreateCompatibleBitmap(source, width, height)
memory.SelectObject(bitmap)
win32gui.PrintWindow(hwnd, memory.GetSafeHdc(), 0)
path = OUT/f'dialog-{len(captured):02d}.bmp'
bitmap.SaveBitmapFile(memory, str(path))
step(f'captured {path.name}: title={title!r} ids={ids} texts={[t for t in texts if t.strip()][:3]}')
identity = (hwnd, tuple(texts))
if identity in handled:
continue
if title == 'Tip of the Day' or 'Select the desired product license' in texts:
target = [c for c in children if win32gui.GetDlgCtrlID(c) == 1]
elif title == 'Expedition PCB' and 7 in ids:
target = [c for c in children if win32gui.GetDlgCtrlID(c) == 7] # 否 (probe only)
else:
target = []
if target and win32gui.IsWindowEnabled(target[0]):
win32gui.PostMessage(target[0], win32con.BM_CLICK, 0, 0)
handled.add(identity)
step(f'clicked {win32gui.GetDlgCtrlID(target[0])} on {title!r}')
except Exception:
continue
if not alive and time.monotonic() > deadline - 140:
step('no dialogs for a while')
time.sleep(1)
if time.monotonic() > deadline - 20:
break
time.sleep(.3)
finally:
for image in sorted(OUT.glob('dialog-*.bmp')):
step(f'kept {image.name}')
subprocess.run(['taskkill', '/PID', str(pid), '/T', '/F'], capture_output=True)
step('killed pcb')