Add multiple servers
This commit is contained in:
parent
d1b9de736f
commit
161fd5e12f
93
main.py
93
main.py
|
@ -11,44 +11,77 @@ class App:
|
||||||
self.root = tk.Tk()
|
self.root = tk.Tk()
|
||||||
self.root.attributes('-fullscreen', True)
|
self.root.attributes('-fullscreen', True)
|
||||||
|
|
||||||
# Red Slider
|
# List of servers (IP, Port)
|
||||||
self.red_slider = tk.Scale(self.root, from_=255, to=0, orient=tk.VERTICAL, length=500, width=50, label="Red")
|
self.servers = [("192.168.0.206", 80), ("192.168.0.208", 80)]
|
||||||
self.red_slider.set(0)
|
|
||||||
self.red_slider.pack(side=tk.LEFT, padx=10)
|
|
||||||
self.red_slider.bind("<ButtonRelease-1>", self.update_colour)
|
|
||||||
|
|
||||||
self.green_slider = tk.Scale(self.root, from_=255, to=0, orient=tk.VERTICAL, length=500, width=50, label="Green")
|
# Create Notebook for tabs
|
||||||
self.green_slider.set(0)
|
self.notebook = ttk.Notebook(self.root)
|
||||||
self.green_slider.pack(side=tk.LEFT, padx=10)
|
self.notebook.pack(expand=1, fill="both")
|
||||||
self.green_slider.bind("<ButtonRelease-1>", self.update_colour)
|
|
||||||
|
|
||||||
|
# Create a tab for each server
|
||||||
self.blue_slider = tk.Scale(self.root, from_=255, to=0, orient=tk.VERTICAL, length=500, width=50, label="Blue")
|
self.tabs = {}
|
||||||
self.blue_slider.set(0)
|
for server in self.servers:
|
||||||
self.blue_slider.pack(side=tk.LEFT, padx=10)
|
tab = ttk.Frame(self.notebook)
|
||||||
self.blue_slider.bind("<ButtonRelease-1>", self.update_colour)
|
self.notebook.add(tab, text=f"{server[0]}:{server[1]}")
|
||||||
|
self.create_sliders(tab)
|
||||||
|
self.tabs[server] = tab
|
||||||
self.brightness_slider = tk.Scale(self.root, from_=255, to=0, orient=tk.VERTICAL, length=500, width=50, label="Brighness")
|
|
||||||
self.brightness_slider.set(127)
|
|
||||||
self.brightness_slider.pack(side=tk.LEFT, padx=10)
|
|
||||||
self.brightness_slider.bind("<ButtonRelease-1>", self.update_colour)
|
|
||||||
|
|
||||||
async_mainloop(self.root)
|
async_mainloop(self.root)
|
||||||
|
|
||||||
|
def create_sliders(self, tab):
|
||||||
|
"""Create sliders for each tab."""
|
||||||
|
slider_length = 800
|
||||||
|
slider_width = 50
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
# 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,
|
||||||
|
}
|
||||||
|
|
||||||
@async_handler
|
@async_handler
|
||||||
async def update_colour(self, event):
|
async def update_colour(self, event, tab):
|
||||||
print(event)
|
"""Update color based on the slider values and send to the selected server."""
|
||||||
r = self.red_slider.get()
|
red_slider = tab.widgets['red_slider']
|
||||||
g = self.green_slider.get()
|
green_slider = tab.widgets['green_slider']
|
||||||
b = self.blue_slider.get()
|
blue_slider = tab.widgets['blue_slider']
|
||||||
brightness = self.brightness_slider.get()
|
brightness_slider = tab.widgets['brightness_slider']
|
||||||
color = color_utils.adjust_brightness((r,b,g), brightness)
|
|
||||||
|
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)
|
print(color, brightness)
|
||||||
|
|
||||||
await send_to_server(bytes(color), ("192.168.0.206","80"))
|
selected_server = self.notebook.tab(self.notebook.select(), "text").split(":")
|
||||||
|
await send_to_server(bytes(color), (selected_server[0], int(selected_server[1])))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = App()
|
app = App()
|
Loading…
Reference in New Issue