86 lines
4.1 KiB
Python
86 lines
4.1 KiB
Python
"""Inspect the horizontal toolbar on a connected acceptance run."""
|
|
import argparse
|
|
import ctypes
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shlex
|
|
import win32api
|
|
import win32gui
|
|
from pywinauto import mouse
|
|
from packaged_menu import tools_running, wait_for
|
|
from toolbar_ui import PRIMARY_FEATURES, ToolbarUI
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("executable", type=Path)
|
|
parser.add_argument("--leave-collapsed", action="store_true")
|
|
parser.add_argument("--evidence", type=Path)
|
|
options = parser.parse_args()
|
|
executable = options.executable.resolve()
|
|
tool = wait_for(lambda: next((p for p in tools_running() if
|
|
Path(p.executable).resolve() == executable and "--request" in p.command_line), None))
|
|
args = shlex.split(tool.command_line, posix=False)
|
|
request = Path(args[args.index("--request") + 1].strip('"'))
|
|
snapshot = json.loads(request.read_text(encoding="utf-8-sig"))
|
|
ui = ToolbarUI(tool.pid)
|
|
if not ui.panel.exists(timeout=0.2) or not ui.panel.is_visible():
|
|
ui.expand()
|
|
panel_handle = ui.panel.handle
|
|
evidence = options.evidence or Path(os.environ["LOCALAPPDATA"]) / "DxProductivity/acceptance/toolbar-20261011"
|
|
evidence.mkdir(parents=True, exist_ok=True)
|
|
handle = ui.toolbar.handle
|
|
dpi = ctypes.windll.user32.GetDpiForWindow(handle)
|
|
bounds = win32gui.GetClientRect(handle)
|
|
assert bounds[3] * 96 / dpi <= 46, (bounds, dpi)
|
|
assert win32gui.GetWindowLong(handle, -20) & 0x8
|
|
buttons = [button.rectangle() for button in ui.toolbar.descendants()
|
|
if button.element_info.control_type in ('Button', 'CheckBox')]
|
|
centers = [(rect.top + rect.bottom) / 2 for rect in buttons]
|
|
assert max(centers) - min(centers) <= 2, buttons
|
|
ui.capture(ui.toolbar).save(str(evidence / "toolbar.png"))
|
|
if ui.panel.exists(timeout=0.2) and ui.panel.is_visible():
|
|
ui.collapse()
|
|
pages = []
|
|
for name in (*PRIMARY_FEATURES, "操作历史", "设置"):
|
|
ui.feature(name)
|
|
panel_bounds = win32gui.GetClientRect(ui.panel.handle)
|
|
panel_dpi = ctypes.windll.user32.GetDpiForWindow(ui.panel.handle)
|
|
assert panel_bounds[2] * 96 / panel_dpi <= 800, (name, panel_bounds)
|
|
assert panel_bounds[3] * 96 / panel_dpi <= 520, (name, panel_bounds)
|
|
ui.capture(ui.panel).save(str(evidence / f"page-{len(pages)}.png"))
|
|
pages.append({"page": name, "client_rect": panel_bounds, "dpi": panel_dpi})
|
|
ui.collapse()
|
|
progress = request.with_name("apply-progress.json")
|
|
before = progress.stat().st_mtime_ns
|
|
wait_for(lambda: progress.stat().st_mtime_ns > before, 15)
|
|
first = win32gui.GetWindowRect(handle)
|
|
grip = ui.toolbar.child_window(title="拖动工具栏").rectangle()
|
|
pointer = win32gui.GetCursorPos()
|
|
start = ((grip.left + grip.right) // 2, (grip.top + grip.bottom) // 2)
|
|
try:
|
|
mouse.press(coords=start)
|
|
mouse.move(coords=(start[0] - 30, start[1] - 20))
|
|
mouse.release(coords=(start[0] - 30, start[1] - 20))
|
|
finally:
|
|
mouse.release(coords=win32gui.GetCursorPos())
|
|
win32api.SetCursorPos(pointer)
|
|
moved = wait_for(lambda: win32gui.GetWindowRect(handle) if win32gui.GetWindowRect(handle) != first else None)
|
|
assert not win32gui.IsWindowVisible(panel_handle)
|
|
ui.feature("PDF 导出")
|
|
ui.panel.minimize()
|
|
wait_for(lambda: not win32gui.IsWindowVisible(panel_handle))
|
|
ui.expand()
|
|
assert "PDF 导出" in ui.texts(ui.panel)
|
|
if options.leave_collapsed:
|
|
ui.collapse()
|
|
result = {"executable": str(executable), "pid": tool.pid, "request": str(request),
|
|
"project": snapshot["design_path"], "dpi": dpi, "toolbar_client_rect": bounds,
|
|
"pages": pages, "heartbeat_updated": True, "drag_before": first,
|
|
"drag_after": moved, "minimize_restored": True, "left_collapsed": options.leave_collapsed}
|
|
(evidence / "native-ui.json").write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
print("PASS NATIVE HORIZONTAL TOOLBAR", json.dumps(result, ensure_ascii=False), flush=True)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|