@@ -7,23 +7,57 @@ def compare_button_states(idle_path, hover_path):
77 print ("Missing screenshots for comparison." )
88 return False
99
10+ idle_meta = idle_path .replace (".png" , ".json" )
11+ hover_meta = hover_path .replace (".png" , ".json" )
12+
13+ if not os .path .exists (idle_meta ) or not os .path .exists (hover_meta ):
14+ print ("Missing metadata for comparison." )
15+ return False
16+
17+ with open (idle_meta , "r" ) as f : m1 = json .load (f )
18+ with open (hover_meta , "r" ) as f : m2 = json .load (f )
19+
1020 img1 = Image .open (idle_path ).convert ('RGB' )
1121 img2 = Image .open (hover_path ).convert ('RGB' )
1222
13- # Calculate average brightness
14- avg1 = np .mean (np .array (img1 ))
15- avg2 = np .mean (np .array (img2 ))
23+ # Identify the button that changed (the one being hovered)
24+ # For now, we compare all buttons and find the one with the most change
25+ # or look for a specific button if provided.
26+
27+ print (f"Button State Audit (Metadata-Aware):" )
1628
17- print (f"Button State Audit:" )
18- print (f" Idle Brightness: { avg1 :.2f} " )
19- print (f" Hover Brightness: { avg2 :.2f} " )
29+ max_diff = - 1
30+ best_btn = None
2031
21- # Hover should generally be brighter in our theme
22- if avg2 > avg1 :
23- print (f" [SUCCESS] Hover state detected (Brightness increased by { avg2 - avg1 :.2f} )" )
24- return True
32+ for b in m1 .get ("Buttons" , []):
33+ bounds = b ['Bounds' ]
34+ box = (bounds ['X' ], bounds ['Y' ], bounds ['X' ] + bounds ['Width' ], bounds ['Y' ] + bounds ['Height' ])
35+
36+ # Crop button area
37+ crop1 = img1 .crop (box )
38+ crop2 = img2 .crop (box )
39+
40+ avg1 = np .mean (np .array (crop1 ))
41+ avg2 = np .mean (np .array (crop2 ))
42+ diff = abs (avg2 - avg1 )
43+
44+ if diff > max_diff :
45+ max_diff = diff
46+ best_btn = (b ['Text' ], avg1 , avg2 )
47+
48+ if best_btn and max_diff > 5 : # Threshold for hover effect
49+ print (f" Detected hover effect on '{ best_btn [0 ]} ':" )
50+ print (f" Idle Brightness: { best_btn [1 ]:.2f} " )
51+ print (f" Hover Brightness: { best_btn [2 ]:.2f} " )
52+
53+ if best_btn [2 ] > best_btn [1 ]:
54+ print (f" [SUCCESS] Hover state detected (Brightness increased by { max_diff :.2f} )" )
55+ return True
56+ else :
57+ print (f" [FAIL] Hover state did not increase brightness." )
58+ return False
2559 else :
26- print (f" [FAIL] No visual change detected between Idle and Hover states ." )
60+ print (f" [FAIL] No significant visual change detected in any button bounding box ." )
2761 return False
2862
2963if __name__ == "__main__" :
0 commit comments