TUI added & minor fixes

This commit is contained in:
Lucca Ketterer 2020-10-05 22:16:05 +02:00
parent 2a07b591aa
commit 28c2c9a36e

View File

@ -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()
@ -52,6 +53,14 @@ def visualizer(color):
cava.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
def vibrant(r,g,b):
@ -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()
elif opt == '-i':
connect()
curses.wrapper(tui_main)
disconnect()
helpmenu()
sys.exit()
if __name__ == "__main__":
main(sys.argv[1:])