TUI added & minor fixes
This commit is contained in:
parent
2a07b591aa
commit
28c2c9a36e
@ -14,6 +14,7 @@ import io
|
|||||||
import time
|
import time
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
from pydbus import SessionBus
|
from pydbus import SessionBus
|
||||||
|
import curses
|
||||||
|
|
||||||
s1 = socket.socket()
|
s1 = socket.socket()
|
||||||
s2 = socket.socket()
|
s2 = socket.socket()
|
||||||
@ -43,14 +44,22 @@ def visualizer(color):
|
|||||||
for line in sed.stdout:
|
for line in sed.stdout:
|
||||||
line = int(line)
|
line = int(line)
|
||||||
r,g,b = hex_to_rgb(color)
|
r,g,b = hex_to_rgb(color)
|
||||||
r = int(r*(line/1000))
|
r = int(r*(line/1000))
|
||||||
g = int(g*(line/1000))
|
g = int(g*(line/1000))
|
||||||
b = int(b*(line/1000))
|
b = int(b*(line/1000))
|
||||||
hex_color = rgb_to_hex(r,g,b)
|
hex_color = rgb_to_hex(r,g,b)
|
||||||
print(r,g,b)
|
print(r,g,b)
|
||||||
send(hex_color)
|
send(hex_color)
|
||||||
cava.stdout.close()
|
cava.stdout.close()
|
||||||
sed.stdout.close()
|
sed.stdout.close()
|
||||||
|
|
||||||
|
def get_base_color(color):
|
||||||
|
return [i / min(color) for i in color]
|
||||||
|
|
||||||
|
_r,_g,_b = 0,0,0
|
||||||
|
|
||||||
|
def vibrant(r,g,b):
|
||||||
|
intensity = 30 # usabel range 1-100 max:1000
|
||||||
|
|
||||||
_r,_g,_b = 0,0,0
|
_r,_g,_b = 0,0,0
|
||||||
|
|
||||||
@ -69,13 +78,13 @@ def vibrant(r,g,b):
|
|||||||
if rgb[c] > 255:
|
if rgb[c] > 255:
|
||||||
rgb[c] = 255
|
rgb[c] = 255
|
||||||
#rgb[min_idx] = int(rgb[min_idx]*(rgb[min_idx]/d)**2)
|
#rgb[min_idx] = int(rgb[min_idx]*(rgb[min_idx]/d)**2)
|
||||||
return rgb
|
return rgb
|
||||||
|
|
||||||
def ambient_light_thread():
|
def ambient_light_thread():
|
||||||
r,g,b = 0,0,0
|
r,g,b = 0,0,0
|
||||||
brighness = 1
|
brighness = 1
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if r > _r:
|
if r > _r:
|
||||||
r-=1
|
r-=1
|
||||||
elif r < _r:
|
elif r < _r:
|
||||||
@ -99,7 +108,7 @@ def ambient_light():
|
|||||||
|
|
||||||
t = Thread(target=ambient_light_thread)
|
t = Thread(target=ambient_light_thread)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
global _r,_g,_b
|
global _r,_g,_b
|
||||||
|
|
||||||
bus = SessionBus()
|
bus = SessionBus()
|
||||||
@ -111,10 +120,10 @@ def ambient_light():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
# screenshot
|
# screenshot
|
||||||
|
|
||||||
# Xorg
|
# Xorg
|
||||||
#img = pyscreenshot.grab(backend="mss", childprocess=False, bbox=(1920,0,4480,1440))
|
#img = pyscreenshot.grab(backend="mss", childprocess=False, bbox=(1920,0,4480,1440))
|
||||||
|
|
||||||
#Wayland
|
#Wayland
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
cap = cv2.VideoCapture('/tmp/a')
|
cap = cv2.VideoCapture('/tmp/a')
|
||||||
@ -125,14 +134,14 @@ def ambient_light():
|
|||||||
|
|
||||||
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
|
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
|
||||||
img = Image.fromarray(frame)
|
img = Image.fromarray(frame)
|
||||||
cap.release()
|
cap.release()
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
img = np.array(img)
|
img = np.array(img)
|
||||||
pixels = np.float32(img.reshape(-1, 3))
|
pixels = np.float32(img.reshape(-1, 3))
|
||||||
img = cv2.UMat(img)
|
img = cv2.UMat(img)
|
||||||
n_colors = 1
|
n_colors = 1
|
||||||
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
|
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
|
||||||
flags = cv2.KMEANS_RANDOM_CENTERS
|
flags = cv2.KMEANS_RANDOM_CENTERS
|
||||||
_, labels, palette = cv2.kmeans(img, n_colors, None, criteria, 10, flags)
|
_, labels, palette = cv2.kmeans(img, n_colors, None, criteria, 10, flags)
|
||||||
@ -154,6 +163,7 @@ def hex_to_rgb(hex):
|
|||||||
g = int(hex[2:4],16)
|
g = int(hex[2:4],16)
|
||||||
b = int(hex[4:6],16)
|
b = int(hex[4:6],16)
|
||||||
return r,g,b
|
return r,g,b
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
h = rgb_to_hex(0,i,0)
|
h = rgb_to_hex(0,i,0)
|
||||||
@ -161,6 +171,38 @@ def test():
|
|||||||
print(h)
|
print(h)
|
||||||
time.sleep(0.0)
|
time.sleep(0.0)
|
||||||
|
|
||||||
|
def tui_main(scr, *args):
|
||||||
|
# -- Perform an action with Screen --
|
||||||
|
scr.border(0)
|
||||||
|
scr.addstr(5, 5, 'Hello from Curses!', curses.A_BOLD)
|
||||||
|
scr.addstr(6, 5, 'Press q to close this screen', curses.A_NORMAL)
|
||||||
|
scr.addstr(8, 5, '\u250C')
|
||||||
|
|
||||||
|
rgb = [0,0,0]
|
||||||
|
color_selector = 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
status = '{},{},{} {}'.format(rgb[0], rgb[1], rgb[2], color_selector)
|
||||||
|
scr.addstr(1, 1, status)
|
||||||
|
|
||||||
|
ch = scr.getch()
|
||||||
|
if ch == ord('q'):
|
||||||
|
break
|
||||||
|
elif ch == ord('j'):
|
||||||
|
if rgb[color_selector] > 0:
|
||||||
|
rgb[color_selector] -= 1
|
||||||
|
send(rgb_to_hex(rgb[0], rgb[1], rgb[2]))
|
||||||
|
elif ch == ord('k'):
|
||||||
|
if rgb[color_selector] < 255:
|
||||||
|
rgb[color_selector] += 1
|
||||||
|
send(rgb_to_hex(rgb[0], rgb[1], rgb[2]))
|
||||||
|
elif ch == ord('l'):
|
||||||
|
if color_selector < 3:
|
||||||
|
color_selector += 1
|
||||||
|
elif ch == ord('h'):
|
||||||
|
if color_selector > 0:
|
||||||
|
color_selector -= 1
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
if not sys.stdin.isatty():
|
if not sys.stdin.isatty():
|
||||||
connect()
|
connect()
|
||||||
@ -171,7 +213,7 @@ def main(argv):
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(argv, "s:v:aht")
|
opts, args = getopt.getopt(argv, "s:v:ahti")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
print(sys.argv[0], "invalid option")
|
print(sys.argv[0], "invalid option")
|
||||||
print("Try", sys.argv[0], "-h for help")
|
print("Try", sys.argv[0], "-h for help")
|
||||||
@ -180,30 +222,29 @@ def main(argv):
|
|||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt == "-h":
|
if opt == "-h":
|
||||||
helpmenu()
|
helpmenu()
|
||||||
sys.exit()
|
|
||||||
elif opt == "-s":
|
elif opt == "-s":
|
||||||
connect()
|
connect()
|
||||||
send(arg)
|
send(arg)
|
||||||
disconnect()
|
disconnect()
|
||||||
sys.exit()
|
|
||||||
elif opt == "-a":
|
elif opt == "-a":
|
||||||
connect()
|
connect()
|
||||||
ambient_light()
|
ambient_light()
|
||||||
disconnect()
|
disconnect()
|
||||||
sys.exit()
|
|
||||||
elif opt == "-v":
|
elif opt == "-v":
|
||||||
connect()
|
connect()
|
||||||
visualizer(arg)
|
visualizer(arg)
|
||||||
disconnect()
|
disconnect()
|
||||||
sys.exit()
|
|
||||||
elif opt == "-t":
|
elif opt == "-t":
|
||||||
connect()
|
connect()
|
||||||
test()
|
test()
|
||||||
disconnect()
|
disconnect()
|
||||||
sys.exit()
|
elif opt == '-i':
|
||||||
|
connect()
|
||||||
helpmenu()
|
curses.wrapper(tui_main)
|
||||||
|
disconnect()
|
||||||
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user