"""Capture the real task-center UI above an owned, changing backdrop (Windows). Uses only temporary sample projects and an isolated task store. Never starts CAD. Run: python tools/accept_acrylic_ui.py --output build/acrylic-acceptance """ import argparse import ctypes from ctypes import wintypes import json import logging import os from pathlib import Path import sys import tempfile import time os.environ.pop('QT_QPA_PLATFORM',None) sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src')) from PySide6.QtCore import Qt,QRectF,QPoint from PySide6.QtGui import QColor,QFont,QPainter,QLinearGradient,QPen,QCursor from PySide6.QtWidgets import QApplication,QWidget,QToolTip from PIL import ImageGrab,ImageChops,ImageStat from dx_productivity.trial_task_center.store import TaskStore from dx_productivity.trial_task_center.service import TaskCenterService from dx_productivity.trial_task_center.logging_setup import configure_logging from dx_productivity.trial_task_center.ui.main_window import TrialTaskCenterWindow from dx_productivity.trial_task_center.target_plan import ComponentTarget,TargetPlanRow def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--output',type=Path,default=Path('build/acrylic-acceptance')) parser.add_argument('--webengine-roundtrip',action='store_true') parser.add_argument('--history',action='store_true') parser.add_argument('--dsh-switch',action='store_true',help='Measure live Acrylic after entering the actual DSH WebEngine page') args=parser.parse_args();out=args.output.resolve();out.mkdir(parents=True,exist_ok=True) app=QApplication([]);app.setFont(QFont('Microsoft YaHei UI',9)) def settle(seconds=.2): deadline=time.monotonic()+seconds while time.monotonic()sidebar[1] and table[3]>table[1] a=captures['native-app-backdrop-a'];b=captures['native-app-backdrop-b'] mean=lambda image:sum(ImageStat.Stat(image).mean)/3 difference=ImageChops.difference(a,b) report['sidebar_backdrop_difference']=mean(difference.crop(sidebar)) report['opaque_table_backdrop_difference']=mean(difference.crop(table)) report['right_header_backdrop_difference']=mean(difference.crop(header)) report['right_execution_backdrop_difference']=mean(difference.crop(execution)) assert report['sidebar_backdrop_difference']>2,report assert report['right_header_backdrop_difference']>2,report assert report['right_execution_backdrop_difference']>2,report assert report['opaque_table_backdrop_difference']<1.5,report if args.webengine_roundtrip: from dx_productivity.trial_task_center.ui.dsh_native import NativeHarnessView report['before_webengine_surface']={'alpha':window.windowHandle().format().alphaBufferSize(), 'translucent':window.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground), 'acrylic':window.property('acrylicEnabled'),'contrast':window.property('highContrastFallback')} def create_view(): view=NativeHarnessView(root/'dsh',window) view.start=lambda:None # Real Chromium surface; no server, model or CAD. view.web.setHtml('Owned DSH WebEngine surface') return view window._create_dsh_view=create_view for index in range(2): window.dsh_action.trigger();settle(2) window.task_center_action.trigger();settle(1) report['after_webengine_surface']={'alpha':window.windowHandle().format().alphaBufferSize(), 'translucent':window.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground), 'acrylic':window.property('acrylicEnabled'),'contrast':window.property('highContrastFallback')} background.phase=0;background.update();capture(f'roundtrip-{index}-a') background.phase=1;background.update();capture(f'roundtrip-{index}-b') delta=ImageChops.difference(captures[f'roundtrip-{index}-a'],captures[f'roundtrip-{index}-b']) report[f'roundtrip_{index}_sidebar_difference']=mean(delta.crop(sidebar)) report[f'roundtrip_{index}_table_difference']=mean(delta.crop(table)) (out/'roundtrip-probe.json').write_text(json.dumps(report,indent=2),encoding='utf8') assert report[f'roundtrip_{index}_sidebar_difference']>2,report assert report[f'roundtrip_{index}_table_difference']<1.5,report if args.dsh_switch: from PySide6.QtTest import QTest QTest.mouseClick(window.dsh_navigation,Qt.MouseButton.LeftButton) deadline=time.monotonic()+120 while time.monotonic()2,report assert report['after_dsh_header_difference']>2,report assert report['after_dsh_table_difference']<1.5,report report['real_dsh_switch_restored_acrylic']=True window.plan_panel.find_text.setText('RV');window.plan_panel.find() report['visible_search_feedback']=window.plan_panel.find_result.isVisible() assert '2 / 6'in window.plan_panel.find_result.text() capture('native-app-search') window.plan_panel.find_text.setText('NO-MATCH');window.plan_panel.find() report['empty_search_feedback']=window.plan_panel.table.empty_hint.isVisible() assert report['empty_search_feedback'] capture('native-app-empty-search') window.plan_panel.clear_find();window.plan_panel.table.clearSelection() task_id=window._task_id window.task_list.filter.setCurrentIndex(window.task_list.filter.findData('completed')) assert window.task_list.list.count()==0 and window._task_id==task_id capture('native-app-completed-category') window.task_list.filter.setCurrentIndex(window.task_list.filter.findData('unfinished')) assert window.task_list.list.count()==len(tasks) window.task_list.filter.setCurrentIndex(window.task_list.filter.findData('all')) assert window.task_list.current_task_id()==task_id report['status_categories']=True window.reduced_transparency_button.setChecked(True);capture('native-app-solid') assert not window.property('acrylicEnabled') solid=captures['native-app-solid'] report['solid_sidebar_mean']=ImageStat.Stat(solid.crop(sidebar)).mean assert min(report['solid_sidebar_mean'])>200,report report['solid_fallback']=True if args.webengine_roundtrip: window.dsh_action.trigger();settle(.3) window.task_center_action.trigger();settle(.3) assert not window.property('acrylicEnabled') background.phase=0;background.update();capture('roundtrip-solid-a') background.phase=1;background.update();capture('roundtrip-solid-b') delta=ImageChops.difference(captures['roundtrip-solid-a'],captures['roundtrip-solid-b']) report['roundtrip_reduced_sidebar_difference']=mean(delta.crop(sidebar)) assert report['roundtrip_reduced_sidebar_difference']<1.5,report window.reduced_transparency_button.setChecked(False);settle(.3) window.resize(980,700);capture('native-app-compact') report['compact_size']=[window.width(),window.height()] report['compact_table_height']=window.plan_panel.table.viewport().height() assert report['compact_size']==[980,700] assert report['compact_table_height']>=100 assert window.task_list.filter.isVisible() point=window.task_list.filter.mapTo(window,window.task_list.filter.rect().bottomRight()) assert 0<=point.x()0 capture('native-app-history') panel.search.setText('4100-CA0000-T0');wait_history() assert panel.table.rowCount()>0 panel.table.selectRow(0) assert '4100-CA0000-T0' in panel.details.toPlainText() capture('native-app-history-search') panel.search.clear();wait_history() def confirm_history(): modal=QApplication.activeModalWidget() if not isinstance(modal,QMessageBox): QTimer.singleShot(100,confirm_history);return modal.grab().save(str(out/'native-app-history-clear-confirm.png')) QTest.mouseClick(modal.button(QMessageBox.StandardButton.Yes),Qt.MouseButton.LeftButton) QTimer.singleShot(100,confirm_history) assert panel.clear_button.isEnabled(),{'status':panel.status.text(),'mutation_enabled':panel._mutations_enabled} panel.clear_button.click();wait_history() assert panel.table.rowCount()==0,{'status':panel.status.text(),'clear_success':panel._clear_success, 'mutation_enabled':panel._mutations_enabled,'rows':panel.table.rowCount()} assert len(service.tasks())==2 capture('native-app-history-cleared') report['history_search_clear_and_task_preservation']=True window.task_center_action.trigger();settle(.2) window.project_options_button.setChecked(True);settle(.2) report['options_exposed']=window.run_panel.copy_value_check.isVisible() window.plan_panel.discard_all();window.close() deadline=time.monotonic()+15 while window.isVisible() and time.monotonic()