From 635682cbf9ce2211b68bbb3381faa62030474cca Mon Sep 17 00:00:00 2001 From: Lucca Ketterer Date: Thu, 26 Jan 2023 22:55:12 +0100 Subject: [PATCH] before stlite --- controller/controller.py | 45 +++++++++++++++++++++++++++++----------- controller/gui.py | 8 +++---- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/controller/controller.py b/controller/controller.py index 28b45c3..bfd782c 100755 --- a/controller/controller.py +++ b/controller/controller.py @@ -10,6 +10,15 @@ import pickle import re import webview +# function generate fibonacci sequence +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) + async def scan_for_pi() -> dict(): ip = socket.gethostbyname(socket.gethostname()) baseIP = '.'.join(ip.split(".")[:3]) @@ -96,22 +105,34 @@ def main(arg): def run(): config.set_option('server.headless', True) - bootstrap.run(gui.__file__, 'streamlit run gui.py --server.headless True', [], di) + # bootstrap.run(gui.__file__, 'streamlit run gui.py --server.headless True', [], di) - p = multiprocessing.Process(target=run) - p.start() + # p = multiprocessing.Process(target=run) + # p.start() - import requests + # import requests - while True: - try: - print(requests.get('http://localhost:8501')) - except: - continue - print('asdf') - break + # while True: + # try: + # print(requests.get('http://localhost:8501')) + # except: + # continue + # print('asdf') + # break # cli.main_run(str(gui.__file__)) - webview.create_window('LED Control', 'http://localhost:8501') + # from streamlit.web.server import Server + # server = Server(gui.__file__, 'streamlit run gui.py --server.headless True') + import tornado.web + + class MainHandler(tornado.web.RequestHandler): + def get(self): + self.write("Hello, world") + + application = tornado.web.Application([ + (r"/", ), ]) + application.listen(8888) + + webview.create_window('LED Control', application) webview.start() # proc.terminate() exit() diff --git a/controller/gui.py b/controller/gui.py index 47140fc..24c2656 100644 --- a/controller/gui.py +++ b/controller/gui.py @@ -42,7 +42,6 @@ def main(): def add_to_conf(): st.session_state.config['saved'].append(color) - init = 0 if 'config' not in st.session_state: init = 1 st.session_state.config = load_config() @@ -56,9 +55,10 @@ def main(): h = st.slider("Hue", 0.0, 1.0, 0.0, 0.01) s = st.slider("Saturation", 0.0, 1.0, 0.0, 0.01) v = st.slider("Value", 0.0, 1.0, 0.0, 0.01) - if init == 0: - r,g,b = colorsys.hsv_to_rgb(h,s,v) - color = rgb_to_hex(int(r * 255),int(g * 255),int(b * 255)) + + + r,g,b = colorsys.hsv_to_rgb(h,s,v) + color = rgb_to_hex(int(r * 255),int(g * 255),int(b * 255)) st.session_state.config['color'] = color[1:]