TUI added & minor fixes
This commit is contained in:
parent
2a07b591aa
commit
28c2c9a36e
@ -14,6 +14,7 @@ import io
|
||||
import time
|
||||
from gi.repository import GLib
|
||||
from pydbus import SessionBus
|
||||
import curses
|
||||
|
||||
s1 = socket.socket()
|
||||
s2 = socket.socket()
|
||||
@ -43,14 +44,22 @@ def visualizer(color):
|
||||
for line in sed.stdout:
|
||||
line = int(line)
|
||||
r,g,b = hex_to_rgb(color)
|
||||
r = int(r*(line/1000))
|
||||
g = int(g*(line/1000))
|
||||
r = int(r*(line/1000))
|
||||
g = int(g*(line/1000))
|
||||
b = int(b*(line/1000))
|
||||
hex_color = rgb_to_hex(r,g,b)
|
||||
print(r,g,b)
|
||||
send(hex_color)
|
||||
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
|
||||
|
||||
@ -69,13 +78,13 @@ def vibrant(r,g,b):
|
||||
if rgb[c] > 255:
|
||||
rgb[c] = 255
|
||||
#rgb[min_idx] = int(rgb[min_idx]*(rgb[min_idx]/d)**2)
|
||||
return rgb
|
||||
return rgb
|
||||
|
||||
def ambient_light_thread():
|
||||
r,g,b = 0,0,0
|
||||
brighness = 1
|
||||
while True:
|
||||
|
||||
|
||||
if r > _r:
|
||||
r-=1
|
||||
elif r < _r:
|
||||
@ -99,7 +108,7 @@ def ambient_light():
|
||||
|
||||
t = Thread(target=ambient_light_thread)
|
||||
t.start()
|
||||
|
||||
|
||||
global _r,_g,_b
|
||||
|
||||
bus = SessionBus()
|
||||
@ -111,10 +120,10 @@ def ambient_light():
|
||||
|
||||
while True:
|
||||
# screenshot
|
||||
|
||||
|
||||
# Xorg
|
||||
#img = pyscreenshot.grab(backend="mss", childprocess=False, bbox=(1920,0,4480,1440))
|
||||
|
||||
|
||||
#Wayland
|
||||
time.sleep(0.1)
|
||||
cap = cv2.VideoCapture('/tmp/a')
|
||||
@ -125,14 +134,14 @@ def ambient_light():
|
||||
|
||||
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
|
||||
img = Image.fromarray(frame)
|
||||
cap.release()
|
||||
cap.release()
|
||||
|
||||
|
||||
'''
|
||||
img = np.array(img)
|
||||
pixels = np.float32(img.reshape(-1, 3))
|
||||
img = cv2.UMat(img)
|
||||
n_colors = 1
|
||||
img = cv2.UMat(img)
|
||||
n_colors = 1
|
||||
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
|
||||
flags = cv2.KMEANS_RANDOM_CENTERS
|
||||
_, 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)
|
||||
b = int(hex[4:6],16)
|
||||
return r,g,b
|
||||
|
||||
def test():
|
||||
for i in range(256):
|
||||
h = rgb_to_hex(0,i,0)
|
||||
@ -161,6 +171,38 @@ def test():
|
||||
print(h)
|
||||
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):
|
||||
if not sys.stdin.isatty():
|
||||
connect()
|
||||
@ -171,7 +213,7 @@ def main(argv):
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(argv, "s:v:aht")
|
||||
opts, args = getopt.getopt(argv, "s:v:ahti")
|
||||
except getopt.GetoptError:
|
||||
print(sys.argv[0], "invalid option")
|
||||
print("Try", sys.argv[0], "-h for help")
|
||||
@ -180,30 +222,29 @@ def main(argv):
|
||||
for opt, arg in opts:
|
||||
if opt == "-h":
|
||||
helpmenu()
|
||||
sys.exit()
|
||||
elif opt == "-s":
|
||||
connect()
|
||||
send(arg)
|
||||
disconnect()
|
||||
sys.exit()
|
||||
elif opt == "-a":
|
||||
connect()
|
||||
ambient_light()
|
||||
disconnect()
|
||||
sys.exit()
|
||||
elif opt == "-v":
|
||||
connect()
|
||||
visualizer(arg)
|
||||
disconnect()
|
||||
sys.exit()
|
||||
elif opt == "-t":
|
||||
connect()
|
||||
test()
|
||||
disconnect()
|
||||
sys.exit()
|
||||
|
||||
helpmenu()
|
||||
elif opt == '-i':
|
||||
connect()
|
||||
curses.wrapper(tui_main)
|
||||
disconnect()
|
||||
|
||||
sys.exit()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
main(sys.argv[1:])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user