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()
|
||||||
@ -52,6 +53,14 @@ def visualizer(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
|
||||||
|
|
||||||
def vibrant(r,g,b):
|
def vibrant(r,g,b):
|
||||||
@ -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()
|
||||||
|
curses.wrapper(tui_main)
|
||||||
|
disconnect()
|
||||||
|
|
||||||
helpmenu()
|
|
||||||
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