hover_check.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. """hover_check.py <pointer on Mon.png> <pointer on Sun.png> [<pointer on the dock.png> <pointer at the top.png>] - the calendar of workshop item 3599498791 enlarges the weekday
  3. under the pointer (its hover zones are cursorEnter scripts, the engine's cursor hit test). With the pointer on the Monday row
  4. the big label has to be the Monday one, with it on the Sunday row the Sunday one; the big label has about four times the
  5. bright pixels of a small one. The optional pair checks the dock, which magnifies the icons next to the pointer (that one follows
  6. the scripts' cursor world position): the icons 04 and 05 rise above the dock bar with the pointer on it and stay flat with the
  7. pointer at the top. Prints PASS or FAIL lines like check_frame.py. Screenshots are 1920x1080, the crops scale."""
  8. import sys
  9. from PIL import Image
  10. def zones(path):
  11. """bright pixels in the narrow column of the Monday label and of the Sunday label"""
  12. image = Image.open(path).convert("L")
  13. sx, sy = image.width / 1920, image.height / 1080
  14. pixels = image.load()
  15. def count(y0, y1):
  16. return sum(
  17. 1
  18. for y in range(int(y0 * sy), int(y1 * sy))
  19. for x in range(int(668 * sx), int(736 * sx))
  20. if pixels[x, y] >= 200
  21. )
  22. return count(440, 468), count(610, 642)
  23. def dock_rise(path):
  24. """bright pixels just above the dock bar over the icons 04 and 05"""
  25. image = Image.open(path).convert("L")
  26. sx, sy = image.width / 1920, image.height / 1080
  27. pixels = image.load()
  28. return sum(
  29. 1
  30. for y in range(int(900 * sy), int(931 * sy))
  31. for x in range(int(860 * sx), int(1061 * sx))
  32. if pixels[x, y] >= 200
  33. )
  34. def main():
  35. mon_zone, sun_zone = zones(sys.argv[1])[0], zones(sys.argv[2])[1]
  36. mon_other, sun_other = zones(sys.argv[1])[1], zones(sys.argv[2])[0]
  37. ok_mon = mon_zone > 120 and mon_zone > 2 * mon_other
  38. ok_sun = sun_zone > 120 and sun_zone > 2 * sun_other
  39. print(("PASS" if ok_mon else "FAIL"), f"weekday hover: pointer on Monday, big label bright pixels Monday/Sunday {mon_zone}/{mon_other}")
  40. print(("PASS" if ok_sun else "FAIL"), f"weekday hover: pointer on Sunday, big label bright pixels Sunday/Monday {sun_zone}/{sun_other}")
  41. ok_dock = True
  42. if len(sys.argv) >= 5:
  43. near, far = dock_rise(sys.argv[3]), dock_rise(sys.argv[4])
  44. ok_dock = near > 300 and far < 60
  45. print(("PASS" if ok_dock else "FAIL"), f"dock zoom: bright pixels above the bar with the pointer on the dock/at the top {near}/{far}")
  46. return 0 if ok_mon and ok_sun and ok_dock else 1
  47. if __name__ == "__main__":
  48. sys.exit(main())