-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyLight.py
94 lines (62 loc) · 1.91 KB
/
PyLight.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python -W ignore::DeprecationWarning
import os
import sys
import time
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GdkPixbuf
from statistics import median
#Settings:
screenW = 1920
screenH = 1080
step = 40
#Starting App.
print("PyLight started.")
stepX = screenW / step
stepY = screenH / step
step2 = step * step
rl, gl, bl = 0, 0, 0
x, y, i = 0, 0, 0
ra, ga, ba = [], [], []
temp = []
array = []
rgb = []
pixbuf = None
window = None
output = None
R, G, B = None, None, None
pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 1, 1)
while True:
array = []
ra, ga, ba = [], [], []
window = Gdk.get_default_root_window()
x = 0
while x < step:
y = 0
while y < step:
pixbuf = Gdk.pixbuf_get_from_window(window, x * stepX, y * stepY, 1, 1)
temp = pixbuf.get_pixels()
ra.append(temp[0])
ga.append(temp[1])
ba.append(temp[2])
y += 1
x += 1
rl = int(round((rl + median(ra)) / 2.0))
gl = int(round((gl + median(ga)) / 2.0))
bl = int(round((bl + median(ba)) / 2.0))
rgb = [rl, gl, bl]
#Output for rivalcfg command.
'''
output = ''.join('{:02x}'.format(c) for c in rgb)
os.system("rivalcfg -c " + output)
'''
#Output for msi-rgb command.
'''
R = format(int(round(rgb[0] / 255.0 * 15.0)), 'x')
G = format(int(round(rgb[1] / 255.0 * 15.0)), 'x')
B = format(int(round(rgb[2] / 255.0 * 15.0)), 'x')
os.system("sudo msi-rgb " + R + R + R + R + R + R + R + R + " " + G + G + G + G + G + G + G + G + " " + B + B + B + B + B + B + B + B)
'''
print(rgb)
time.sleep(0.1)
print("PyLight exited.")