diff options
Diffstat (limited to 'interface/dummyserver.py')
-rwxr-xr-x | interface/dummyserver.py | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/interface/dummyserver.py b/interface/dummyserver.py new file mode 100755 index 0000000..cfd1451 --- /dev/null +++ b/interface/dummyserver.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +import array +import socket +import threading +import time + +from tkinter import * +from tkinter.ttk import * + +CHANNEL_COUNT = 64 + +class Main(Frame): + def _update_display(self): + with self.lock: + for i, s in zip(self.channels, self.sliders): + s.config(state=NORMAL) + s.set(i) + s.config(state=DISABLED) + + self.master.after(16, self._update_display) + + + def update(self, b: bytes): + with self.lock: + self.channels = array.array('B', b) + + def __init__(self, root): + super().__init__(root) + + self.sliders = [] + self.rowconfigure(0, weight=1) + for i in range(CHANNEL_COUNT): + self.columnconfigure(i, weight=1) + self.sliders.append(Scale(self, from_=255, to=0, orient=VERTICAL, state=DISABLED)) + self.sliders[-1].grid(row=0, column=i, sticky=N+E+S+W) + Label(self, text=str(i+1)).grid(row=1, column=i, sticky=N+E+S+W) + + self.channels = array.array('B', (0 for i in range(CHANNEL_COUNT))) + self.lock = threading.RLock() + + self.master.after(0, self._update_display) + +def handle_conn(conn, m): + while True: + a = conn.recv(1024) + if not a: + break + m.update(a) + +def socket_main(m): + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.bind(("", 6969)) + s.listen() + print("Listening") + while True: + conn, addr = s.accept() + threading.Thread(target=handle_conn, args=(conn, m,)).start() + +if __name__ == "__main__": + root = Tk() + root.rowconfigure(0, weight=1) + root.columnconfigure(0, weight=1) + + root.wm_title("Lighting Output") + + + main = Main(root) + main.grid(row=0, column=0, sticky=N+E+S+W) + + root.after(0, threading.Thread(target=socket_main, args=(main,)).start) + + main.mainloop() |