No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tray.py 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  2. import brightness
  3. import threading
  4. import time
  5. import pystray
  6. from io import BytesIO
  7. import cairosvg
  8. from PIL import Image
  9. #icon_path = "/usr/share/icons/breeze-dark/devices/22/video-display-brightness.svg"
  10. #icon_path = "/usr/share/icons/breeze-dark/devices/32/video-display-brightness-symbolic.svg"
  11. #icon_path = "/usr/share/icons/breeze-dark/status/32/input-keyboard-brightness.svg"
  12. icon_path = "/usr/share/icons/breeze-dark/actions/24/brightness-high.svg"
  13. def is_running():
  14. #print("check1")
  15. return "Active" if brightness.is_active else "Inactive"
  16. def get_value():
  17. #print("check2")
  18. return f"Brightness: {brightness.last_brightness}"
  19. def quit(icon):
  20. print("stop brightness")
  21. brightness.running = False
  22. print("stop tray")
  23. icon.stop()
  24. def poll(icon):
  25. while brightness.running:
  26. #print("update")
  27. icon.update_menu()
  28. time.sleep(5.0)
  29. def main():
  30. out = BytesIO()
  31. cairosvg.svg2png(url=icon_path, write_to=out)
  32. image = Image.open(out)
  33. print("start brightness")
  34. t_b = threading.Thread(target=brightness.main)
  35. t_b.start()
  36. print("prepare tray")
  37. icon = pystray.Icon("AutoBrightness", image, "AutoBrightness",
  38. menu=pystray.Menu(
  39. pystray.MenuItem(
  40. 'Activated',
  41. None,
  42. enabled=False,
  43. checked=lambda icon=pystray.Icon: is_running(),
  44. ),
  45. pystray.MenuItem(
  46. lambda icon=pystray.Icon: get_value(),
  47. None,
  48. enabled=False,
  49. ),
  50. pystray.MenuItem(
  51. "Quit",
  52. lambda icon=pystray.Icon: quit(icon),
  53. ),
  54. )
  55. )
  56. print("start polling")
  57. t_p = threading.Thread(target=poll, args=(icon,))
  58. t_p.start()
  59. print("start tray")
  60. icon.run()
  61. print("join brightness")
  62. t_b.join()
  63. t_p.join()
  64. print("done")
  65. if __name__ == "__main__":
  66. main()