40 行
2.3 KiB
Python
40 行
2.3 KiB
Python
"""Check actual Inspector geometry, including clipping by inner containers."""
|
|
import json,math,pathlib
|
|
|
|
def nodes_of_class(node,kind):
|
|
result=[node]if node.get('class')==kind else[]
|
|
for child in node.get('children',[]):result.extend(nodes_of_class(child,kind))
|
|
return result
|
|
|
|
def inspect(path,profile):
|
|
frame=json.loads(pathlib.Path(path).read_text(encoding='utf-8'))['frames'][-1]
|
|
pages=[]
|
|
def visible_pages(node,parent_visible=True):
|
|
visible=parent_visible and node.get('visible',True)
|
|
if not visible:return
|
|
if node.get('class')=='AppletPage':pages.append(node)
|
|
for child in node.get('children',[]):visible_pages(child,visible)
|
|
visible_pages(frame['widgets'])
|
|
page=pages[-1]
|
|
circle=profile.startswith('round');width=466 if circle else 390;height=466 if circle else 450
|
|
failures=[];buttons=[];icons=[]
|
|
def visit(node,ancestors=(),px=0,py=0,visible=True):
|
|
g=node['geometry'];x=px+g['x'];y=py+g['y'];w=g['w'];h=g['h']
|
|
visible=visible and node.get('visible',True)
|
|
if not visible:return
|
|
box=[x,y,w,h];kind=node['class'];identifier=node.get('id','')
|
|
if kind in ['Button','ImageBox','Label']:
|
|
for ancestor in ancestors:
|
|
ax,ay,aw,ah=ancestor['box']
|
|
if x<ax-1 or y<ay-1 or x+w>ax+aw+1 or y+h>ay+ah+1:
|
|
failures.append({'reason':'ancestor clipping','class':kind,'id':identifier,'box':box,'ancestor':ancestor})
|
|
if kind in ['Button','ImageBox']:
|
|
radius=max(math.hypot(tx-233,ty-233)for tx in[x,x+w]for ty in[y,y+h])if circle else None
|
|
if(circle and radius>230)or(not circle and(x<0 or y<0 or x+w>width or y+h>height)):
|
|
failures.append({'reason':'screen boundary','class':kind,'id':identifier,'box':box,'radius':radius})
|
|
record={'id':identifier,'box':box,'radius':radius}
|
|
(buttons if kind=='Button'else icons).append(record)
|
|
for child in node.get('children',[]):visit(child,ancestors+({'class':kind,'id':identifier,'box':box},),x,y,visible)
|
|
visit(page)
|
|
return {'page':page.get('id'),'buttons':len(buttons),'icons':len(icons),'max_button_radius':round(max([b['radius']or 0 for b in buttons],default=0),2),'failures':failures,'passed':not failures}
|