2024-08-30 05:23:16 +00:00
|
|
|
import asyncio
|
|
|
|
import tkinter as tk
|
|
|
|
from tkinter import ttk
|
|
|
|
|
|
|
|
from async_tkinter_loop import async_handler, async_mainloop
|
|
|
|
from networking import send_to_server
|
|
|
|
import color_utils
|
|
|
|
|
|
|
|
class App:
|
|
|
|
def __init__(self) -> None:
|
|
|
|
self.root = tk.Tk()
|
|
|
|
self.root.attributes('-fullscreen', True)
|
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
# List of servers (IP, Port)
|
|
|
|
self.servers = [("192.168.0.206", 80), ("192.168.0.208", 80)]
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
# Create Notebook for tabs
|
|
|
|
self.notebook = ttk.Notebook(self.root)
|
|
|
|
self.notebook.pack(expand=1, fill="both")
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
# Create a tab for each server
|
|
|
|
self.tabs = {}
|
|
|
|
for server in self.servers:
|
|
|
|
tab = ttk.Frame(self.notebook)
|
|
|
|
self.notebook.add(tab, text=f"{server[0]}:{server[1]}")
|
|
|
|
self.create_sliders(tab)
|
|
|
|
self.tabs[server] = tab
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
async_mainloop(self.root)
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
def create_sliders(self, tab):
|
|
|
|
"""Create sliders for each tab."""
|
|
|
|
slider_length = 800
|
|
|
|
slider_width = 50
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
# Red Slider
|
|
|
|
red_slider = tk.Scale(tab, from_=255, to=0, orient=tk.VERTICAL, length=slider_length, width=slider_width, label="Red")
|
|
|
|
red_slider.set(0)
|
|
|
|
red_slider.pack(side=tk.LEFT, padx=10)
|
|
|
|
red_slider.bind("<ButtonRelease-1>", lambda event, srv=tab: self.update_colour(event, srv))
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
# Green Slider
|
|
|
|
green_slider = tk.Scale(tab, from_=255, to=0, orient=tk.VERTICAL, length=slider_length, width=slider_width, label="Green")
|
|
|
|
green_slider.set(0)
|
|
|
|
green_slider.pack(side=tk.LEFT, padx=10)
|
|
|
|
green_slider.bind("<ButtonRelease-1>", lambda event, srv=tab: self.update_colour(event, srv))
|
|
|
|
|
|
|
|
# Blue Slider
|
|
|
|
blue_slider = tk.Scale(tab, from_=255, to=0, orient=tk.VERTICAL, length=slider_length, width=slider_width, label="Blue")
|
|
|
|
blue_slider.set(0)
|
|
|
|
blue_slider.pack(side=tk.LEFT, padx=10)
|
|
|
|
blue_slider.bind("<ButtonRelease-1>", lambda event, srv=tab: self.update_colour(event, srv))
|
|
|
|
|
|
|
|
# Brightness Slider
|
|
|
|
brightness_slider = tk.Scale(tab, from_=255, to=0, orient=tk.VERTICAL, length=slider_length, width=slider_width, label="Brightness")
|
|
|
|
brightness_slider.set(127)
|
|
|
|
brightness_slider.pack(side=tk.LEFT, padx=10)
|
|
|
|
brightness_slider.bind("<ButtonRelease-1>", lambda event, srv=tab: self.update_colour(event, srv))
|
|
|
|
|
|
|
|
tab.widgets = {
|
|
|
|
'red_slider': red_slider,
|
|
|
|
'green_slider': green_slider,
|
|
|
|
'blue_slider': blue_slider,
|
|
|
|
'brightness_slider': brightness_slider,
|
|
|
|
}
|
2024-08-30 05:23:16 +00:00
|
|
|
|
|
|
|
@async_handler
|
2024-08-30 05:35:26 +00:00
|
|
|
async def update_colour(self, event, tab):
|
|
|
|
"""Update color based on the slider values and send to the selected server."""
|
|
|
|
red_slider = tab.widgets['red_slider']
|
|
|
|
green_slider = tab.widgets['green_slider']
|
|
|
|
blue_slider = tab.widgets['blue_slider']
|
|
|
|
brightness_slider = tab.widgets['brightness_slider']
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
r = red_slider.get()
|
|
|
|
g = green_slider.get()
|
|
|
|
b = blue_slider.get()
|
|
|
|
brightness = brightness_slider.get()
|
|
|
|
|
|
|
|
color = color_utils.adjust_brightness((r, b, g), brightness)
|
|
|
|
print(color, brightness)
|
2024-08-30 05:23:16 +00:00
|
|
|
|
2024-08-30 05:35:26 +00:00
|
|
|
selected_server = self.notebook.tab(self.notebook.select(), "text").split(":")
|
|
|
|
await send_to_server(bytes(color), (selected_server[0], int(selected_server[1])))
|
2024-08-30 05:23:16 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-08-30 05:35:26 +00:00
|
|
|
app = App()
|