125 lines
7.3 KiB
Python
125 lines
7.3 KiB
Python
"""Disposable native Windows material probe, not a CAD or production UI change.
|
|
|
|
Run with Python + PySide6 + Pillow on Windows. Opens only owned test windows,
|
|
captures their shared rectangle, then closes them. No user content is sampled.
|
|
"""
|
|
import ctypes
|
|
from ctypes import wintypes
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
os.environ.pop('QT_QPA_PLATFORM',None)
|
|
from PySide6.QtCore import Qt,QTimer,QRectF
|
|
from PySide6.QtGui import QColor,QFont,QPainter,QLinearGradient,QPen
|
|
from PySide6.QtWidgets import QApplication,QWidget,QVBoxLayout,QLabel
|
|
from PIL import ImageGrab
|
|
|
|
root=Path(__file__).resolve().parent
|
|
user=ctypes.WinDLL('user32',use_last_error=True)
|
|
dwm=ctypes.WinDLL('dwmapi',use_last_error=True)
|
|
user.SetWindowCompositionAttribute.argtypes=[wintypes.HWND,ctypes.c_void_p]
|
|
user.SetWindowCompositionAttribute.restype=wintypes.BOOL
|
|
class Point(ctypes.Structure):
|
|
_fields_=[('x',ctypes.c_long),('y',ctypes.c_long)]
|
|
user.WindowFromPoint.argtypes=[Point]
|
|
user.WindowFromPoint.restype=wintypes.HWND
|
|
user.GetWindowThreadProcessId.argtypes=[wintypes.HWND,ctypes.POINTER(wintypes.DWORD)]
|
|
dwm.DwmSetWindowAttribute.argtypes=[wintypes.HWND,wintypes.DWORD,ctypes.c_void_p,wintypes.DWORD]
|
|
dwm.DwmSetWindowAttribute.restype=ctypes.c_long
|
|
class Accent(ctypes.Structure):
|
|
_fields_=[('state',ctypes.c_int),('flags',ctypes.c_int),('color',ctypes.c_uint32),('animation',ctypes.c_int)]
|
|
class Composition(ctypes.Structure):
|
|
_fields_=[('attribute',ctypes.c_int),('data',ctypes.c_void_p),('size',ctypes.c_size_t)]
|
|
def accent(hwnd,state):
|
|
policy=Accent(state,0,0x20F4F4F4,0)
|
|
data=Composition(19,ctypes.cast(ctypes.pointer(policy),ctypes.c_void_p),ctypes.sizeof(policy))
|
|
return bool(user.SetWindowCompositionAttribute(hwnd,ctypes.byref(data)))
|
|
def backdrop(hwnd,kind):
|
|
value=ctypes.c_int(kind)
|
|
return int(dwm.DwmSetWindowAttribute(hwnd,38,ctypes.byref(value),ctypes.sizeof(value)))
|
|
|
|
app=QApplication([])
|
|
app.setFont(QFont('Segoe UI',11))
|
|
screen=app.primaryScreen().availableGeometry()
|
|
width=min(1200,screen.width()-60);height=min(760,screen.height()-60)
|
|
origin=(screen.x()+(screen.width()-width)//2,screen.y()+(screen.height()-height)//2)
|
|
class Background(QWidget):
|
|
phase=0
|
|
def paintEvent(self,event):
|
|
p=QPainter(self);p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
p.fillRect(self.rect(),QColor('#e8edf2'))
|
|
for col in range(2):
|
|
area=QRectF(30+col*(width/2),110,width/2-60,height-155)
|
|
g=QLinearGradient(area.topLeft(),area.bottomRight())
|
|
g.setColorAt(0,QColor('#4c79b6') if self.phase==0 else QColor('#cf8663'))
|
|
g.setColorAt(.47,QColor('#aecac9'));g.setColorAt(1,QColor('#d6a39e') if self.phase==0 else QColor('#6a88b1'))
|
|
p.fillRect(area,g)
|
|
p.setPen(QPen(QColor('#ffffffb0'),2))
|
|
for x in range(int(area.left()),int(area.right()),24):p.drawLine(x,int(area.top()),x,int(area.bottom()))
|
|
p.setPen(QColor('#253d57'));p.setFont(QFont('Segoe UI',35,QFont.Weight.Bold))
|
|
p.drawText(area.adjusted(22,90,-10,0),'BACKDROP\nLIVE '+str(self.phase+1))
|
|
p.setPen(QColor('#fff'));p.setFont(QFont('Consolas',13))
|
|
for row in range(6):p.drawText(int(area.left()+22),int(area.top()+260+row*30),'RV05 4100-CA0000-T7 100nF')
|
|
p.setPen(QColor('#34475f'));p.setFont(QFont('Segoe UI',18,QFont.Weight.DemiBold))
|
|
p.drawText(30,38,'Native Windows / PySide6 material probe')
|
|
p.setFont(QFont('Segoe UI',10));p.setPen(QColor('#6c7f96'))
|
|
p.drawText(30,66,'Identical owned background on both sides. No screenshot texture is painted into either foreground window.')
|
|
p.drawText(30,height-17,'Captured from actual Windows composition; no CAD, no user project, no foreign window in the capture rectangle.')
|
|
|
|
class Pane(QWidget):
|
|
def __init__(self,title,subtitle):
|
|
super().__init__(None,Qt.WindowType.FramelessWindowHint|Qt.WindowType.Tool|Qt.WindowType.WindowStaysOnTopHint)
|
|
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
|
layout=QVBoxLayout(self);layout.setContentsMargins(24,25,24,24)
|
|
titleLabel=QLabel(title);titleLabel.setStyleSheet('background:transparent;color:#213952;font-size:18px;font-weight:600')
|
|
hint=QLabel(subtitle);hint.setStyleSheet('background:transparent;color:#46617f;font-size:11px');hint.setWordWrap(True)
|
|
layout.addWidget(titleLabel);layout.addWidget(hint);layout.addStretch()
|
|
for text in ['Audio_D2128','Selected: RV05','Plan saved / No CAD write']:
|
|
label=QLabel(text);label.setStyleSheet('background:rgba(255,255,255,110);color:#314d6c;border:1px solid rgba(255,255,255,170);border-radius:7px;padding:10px;font-size:12px');layout.addWidget(label)
|
|
def paintEvent(self,event):
|
|
p=QPainter(self);p.fillRect(self.rect(),QColor(255,255,255,45));p.setPen(QPen(QColor(255,255,255,170),1));p.drawRect(self.rect().adjusted(0,0,-1,-1))
|
|
|
|
bg=Background(None,Qt.WindowType.FramelessWindowHint|Qt.WindowType.Tool|Qt.WindowType.WindowStaysOnTopHint)
|
|
bg.setGeometry(origin[0],origin[1],width,height)
|
|
left=Pane('Transparency only','OS blur disabled. Background lines and letters remain sharp.')
|
|
right=Pane('Windows Acrylic','ACCENT_ENABLE_ACRYLICBLURBEHIND. Background is composed by Windows.')
|
|
paneW=int(width/2-112);paneH=height-250
|
|
left.setGeometry(origin[0]+56,origin[1]+143,paneW,paneH)
|
|
right.setGeometry(origin[0]+int(width/2)+56,origin[1]+143,paneW,paneH)
|
|
report={'os_build':sys.getwindowsversion().build,'capture_method':'PIL ImageGrab of owned background window rectangle, not QWidget.grab','uses_baked_backdrop':False,'ownership_grid_checked':True,'artifacts':[]}
|
|
bg.show();left.show();right.show();right.raise_();right.activateWindow()
|
|
def capture(name):
|
|
dpr=app.primaryScreen().devicePixelRatio()
|
|
bbox=tuple(round(v*dpr) for v in [origin[0],origin[1],origin[0]+width,origin[1]+height])
|
|
for y in range(bbox[1]+3,bbox[3]-3,24):
|
|
for x in range(bbox[0]+3,bbox[2]-3,24):
|
|
hwnd=user.WindowFromPoint(Point(x,y));pid=wintypes.DWORD()
|
|
user.GetWindowThreadProcessId(hwnd,ctypes.byref(pid))
|
|
if pid.value!=os.getpid():
|
|
left.close();right.close();bg.close();app.quit()
|
|
raise RuntimeError('Owned test rectangle is occluded; no capture saved')
|
|
im=ImageGrab.grab(bbox=bbox,all_screens=True)
|
|
im.save(root/name);report['artifacts'].append({'file':name,'dimensions':im.size,'phase':bg.phase})
|
|
def first():
|
|
report['accent_api_return']=accent(int(right.winId()),4)
|
|
report['left_native_handle']=int(left.winId());report['right_native_handle']=int(right.winId())
|
|
QTimer.singleShot(1800,second)
|
|
def second():
|
|
capture('native-acrylic-a.png');bg.phase=1;bg.update();QTimer.singleShot(1400,third)
|
|
def third():
|
|
capture('native-acrylic-b.png')
|
|
report['clear_accent_before_dwm']=accent(int(right.winId()),0)
|
|
report['dwm_transient_hresult']=backdrop(int(right.winId()),3)
|
|
QTimer.singleShot(1400,fourth)
|
|
def fourth():
|
|
capture('native-dwm-acrylic.png')
|
|
(root/'native-acrylic-verification.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
|
|
left.close();right.close();bg.close();app.quit()
|
|
QTimer.singleShot(800,first)
|
|
QTimer.singleShot(15000,app.quit)
|
|
app.exec()
|
|
assert 'dwm_transient_hresult'in report,'Probe did not complete'
|
|
print(json.dumps(report,ensure_ascii=True))
|