-
Notifications
You must be signed in to change notification settings - Fork 0
/
autobrightness.pyw
50 lines (42 loc) · 1.1 KB
/
autobrightness.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from monitorcontrol import *
import darkdetect
import serial
import pystray
from PIL import Image
import time
import sys
COM_PORT = "COM5"
def getSign(number):
if number >= 0:
return 1
else:
return -1
def command(icon, item):
name = str(item)
if name == "Exit":
icon.stop()
sys.exit()
def mainLoop(icon):
icon.visible = True
serialPort = serial.Serial(port = COM_PORT, baudrate=2000000)
while True:
time.sleep(0.05)
if serialPort.in_waiting > 0:
luminance = int(serialPort.readline().decode())
print(luminance)
for monitor in get_monitors():
with monitor:
prevLuminance = monitor.get_luminance()
deltaL = luminance - prevLuminance
for i in range(abs(deltaL)):
monitor.set_luminance(prevLuminance + getSign(deltaL))
prevLuminance = monitor.get_luminance()
if __name__ == "__main__":
if darkdetect.isDark():
image = Image.open("icon_dark.png")
else:
image = Image.open("icon.png")
icon = pystray.Icon("AutoBrightness", image, menu=pystray.Menu(
pystray.MenuItem("Exit", command)
))
icon.run(mainLoop)