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.
68 lines
2.9 KiB
Python
68 lines
2.9 KiB
Python
"""Invoke the selected, named LM Verify menu and record native window changes."""
|
|
import ctypes
|
|
ctypes.windll.user32.SetThreadDpiAwarenessContext(ctypes.c_void_p(-4))
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import win32gui
|
|
import win32process
|
|
from pywinauto import Desktop
|
|
from pywinauto.controls.common_controls import TreeViewWrapper
|
|
|
|
|
|
def snapshot():
|
|
windows = []
|
|
win32gui.EnumWindows(lambda h, _: windows.append(h), None)
|
|
result = []
|
|
for h in windows:
|
|
title = win32gui.GetWindowText(h)
|
|
if not win32gui.IsWindowVisible(h):
|
|
continue
|
|
if win32gui.GetClassName(h) != '#32770' and not any(x in title for x in ('Expedition', 'Library Manager')):
|
|
continue
|
|
children = []
|
|
win32gui.EnumChildWindows(h, lambda c, _: children.append(c), None)
|
|
result.append({'hwnd': h, 'pid': win32process.GetWindowThreadProcessId(h)[1], 'title': title,
|
|
'controls': [(c, win32gui.GetDlgCtrlID(c), win32gui.GetClassName(c), win32gui.GetWindowText(c)) for c in children]})
|
|
return result
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import argparse
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('name')
|
|
parser.add_argument('--seconds', type=int, default=90)
|
|
args = parser.parse_args()
|
|
output = Path(__file__).resolve().parents[1] / 'build' / 'verify-launch-probe.jsonl'
|
|
lm = [w for w in Desktop(backend='win32').windows() if w.is_visible() and w.window_text().startswith('Library Manager:')]
|
|
assert len(lm) == 1, 'Need exactly one visible Library Manager'
|
|
import ctypes
|
|
ctypes.windll.user32.EndMenu()
|
|
lm[0].set_focus()
|
|
trees = [w for w in lm[0].descendants() if 'TreeView' in w.class_name()]
|
|
assert len(trees) == 1
|
|
tree = TreeViewWrapper(trees[0].handle)
|
|
block = tree.get_item(['Central Libraries', 'mentor_lib.lmc', 'Reusable Blocks', 'Logical-Physical', args.name], exact=True)
|
|
block.ensure_visible()
|
|
block.select()
|
|
block.click_input(button='right')
|
|
time.sleep(.3)
|
|
assert block.is_selected(), 'Right click changed selected CBB; aborting'
|
|
items = [i for m in Desktop(backend='uia').windows(control_type='Menu') for i in m.descendants(control_type='MenuItem') if i.window_text() == 'Verify']
|
|
assert len(items) == 1 and items[0].is_enabled()
|
|
items[0].invoke()
|
|
print('Verify invoked for', args.name, flush=True)
|
|
last = None
|
|
with output.open('a', encoding='utf-8') as stream:
|
|
start = time.monotonic()
|
|
while time.monotonic() - start < args.seconds:
|
|
state = snapshot()
|
|
if state != last:
|
|
record = {'time': time.strftime('%Y-%m-%d %H:%M:%S'), 'block': args.name, 'windows': state}
|
|
line = json.dumps(record, ensure_ascii=False)
|
|
stream.write(line + '\n'); stream.flush()
|
|
print(line, flush=True)
|
|
last = state
|
|
time.sleep(.3)
|