Compare commits
3 Commits
kat
...
e803dd4243
| Author | SHA1 | Date | |
|---|---|---|---|
| e803dd4243 | |||
| baf3d0b0ff | |||
| 7f43b93cb7 |
283
settings.json
283
settings.json
@@ -7,13 +7,91 @@
|
|||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"colors": [
|
"colors": [
|
||||||
"#0000ff",
|
"#968a00"
|
||||||
"#c30074",
|
|
||||||
"#00ff00"
|
|
||||||
],
|
],
|
||||||
"brightness": 9,
|
"brightness": 21,
|
||||||
"pattern": "off",
|
"pattern": "off",
|
||||||
"delay": 50
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10,
|
||||||
|
"patterns": {
|
||||||
|
"pulse": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"n_chase": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"on": {
|
||||||
|
"colors": [
|
||||||
|
"#968a00"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"rainbow": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"off": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"blink": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dj": {
|
"dj": {
|
||||||
@@ -23,13 +101,104 @@
|
|||||||
"settings": {
|
"settings": {
|
||||||
"colors": [
|
"colors": [
|
||||||
"#0000ff",
|
"#0000ff",
|
||||||
"#c30074",
|
"#ff0000"
|
||||||
"#00ff00",
|
],
|
||||||
|
"brightness": 73,
|
||||||
|
"pattern": "transition",
|
||||||
|
"delay": 10000,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10,
|
||||||
|
"patterns": {
|
||||||
|
"rainbow": {
|
||||||
|
"colors": [
|
||||||
|
"#00006a"
|
||||||
|
],
|
||||||
|
"delay": 17,
|
||||||
|
"n1": 1,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"on": {
|
||||||
|
"colors": [
|
||||||
|
"#ffff00",
|
||||||
|
"#0000ff"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"blink": {
|
||||||
|
"colors": [
|
||||||
|
"#0000d0"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"pulse": {
|
||||||
|
"delay": 1002,
|
||||||
|
"colors": [
|
||||||
|
"#006600",
|
||||||
|
"#0000ff"
|
||||||
|
],
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"transition": {
|
||||||
|
"colors": [
|
||||||
|
"#0000ff",
|
||||||
|
"#ff0000"
|
||||||
|
],
|
||||||
|
"delay": 10000,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10
|
||||||
|
},
|
||||||
|
"n_chase": {
|
||||||
|
"n1": 11,
|
||||||
|
"n2": 11,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10,
|
||||||
|
"delay": 99,
|
||||||
|
"colors": [
|
||||||
|
"#0000ff"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"off": {
|
||||||
|
"colors": [
|
||||||
"#000000"
|
"#000000"
|
||||||
],
|
],
|
||||||
"brightness": 6,
|
"delay": 99,
|
||||||
"pattern": "flicker",
|
"n1": 10,
|
||||||
"delay": 520
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"middle": {
|
"middle": {
|
||||||
@@ -48,7 +217,19 @@
|
|||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "flicker",
|
"pattern": "flicker",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"patterns": {
|
||||||
|
"flicker": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sides": {
|
"sides": {
|
||||||
@@ -65,7 +246,19 @@
|
|||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "on",
|
"pattern": "on",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"patterns": {
|
||||||
|
"on": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"outside": {
|
"outside": {
|
||||||
@@ -80,8 +273,36 @@
|
|||||||
"#000000"
|
"#000000"
|
||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "on",
|
"pattern": "transition",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"n1": -17,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10,
|
||||||
|
"patterns": {
|
||||||
|
"on": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10
|
||||||
|
},
|
||||||
|
"transition": {
|
||||||
|
"colors": [
|
||||||
|
"#000000"
|
||||||
|
],
|
||||||
|
"delay": 99,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"middle1": {
|
"middle1": {
|
||||||
@@ -97,7 +318,16 @@
|
|||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "flicker",
|
"pattern": "flicker",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"n1": 10,
|
||||||
|
"n2": 10,
|
||||||
|
"n3": 10,
|
||||||
|
"n4": 10,
|
||||||
|
"n5": 10,
|
||||||
|
"n6": 10,
|
||||||
|
"patterns": {
|
||||||
|
"flicker": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"middle2": {
|
"middle2": {
|
||||||
@@ -113,7 +343,10 @@
|
|||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "flicker",
|
"pattern": "flicker",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"patterns": {
|
||||||
|
"flicker": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"middle3": {
|
"middle3": {
|
||||||
@@ -129,7 +362,10 @@
|
|||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "flicker",
|
"pattern": "flicker",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"patterns": {
|
||||||
|
"flicker": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"middle4": {
|
"middle4": {
|
||||||
@@ -145,18 +381,19 @@
|
|||||||
],
|
],
|
||||||
"brightness": 6,
|
"brightness": 6,
|
||||||
"pattern": "flicker",
|
"pattern": "flicker",
|
||||||
"delay": 520
|
"delay": 520,
|
||||||
|
"patterns": {
|
||||||
|
"flicker": {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
"on",
|
"on",
|
||||||
"off",
|
"off",
|
||||||
"blink",
|
"rainbow",
|
||||||
"rainbow_cycle",
|
"transition",
|
||||||
"color_transition",
|
"n_chase",
|
||||||
"theater_chase",
|
|
||||||
"flicker",
|
|
||||||
"pulse"
|
"pulse"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
429
src/main.py
429
src/main.py
@@ -7,6 +7,7 @@ from networking import WebSocketClient
|
|||||||
import color_utils
|
import color_utils
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
import time
|
import time
|
||||||
|
import math
|
||||||
|
|
||||||
# Dark theme colors (unchanged)
|
# Dark theme colors (unchanged)
|
||||||
bg_color = "#2e2e2e"
|
bg_color = "#2e2e2e"
|
||||||
@@ -22,6 +23,26 @@ highlight_pattern_color = "#6a5acd"
|
|||||||
active_palette_color_border = "#FFD700" # Gold color
|
active_palette_color_border = "#FFD700" # Gold color
|
||||||
|
|
||||||
|
|
||||||
|
def delay_to_slider(delay_ms):
|
||||||
|
"""Convert delay in ms (10-10000) to slider position (0-1000) using logarithmic scale."""
|
||||||
|
if delay_ms <= 10:
|
||||||
|
return 0
|
||||||
|
if delay_ms >= 10000:
|
||||||
|
return 1000
|
||||||
|
# Logarithmic conversion: delay = 10 * (10000/10) ^ (position/1000)
|
||||||
|
# Solving for position: position = 1000 * log(delay/10) / log(1000)
|
||||||
|
return 1000 * math.log(delay_ms / 10) / math.log(1000)
|
||||||
|
|
||||||
|
def slider_to_delay(slider_value):
|
||||||
|
"""Convert slider position (0-1000) to delay in ms (10-10000) using logarithmic scale."""
|
||||||
|
if slider_value <= 0:
|
||||||
|
return 10
|
||||||
|
if slider_value >= 1000:
|
||||||
|
return 10000
|
||||||
|
# Logarithmic conversion: delay = 10 * 1000 ^ (position/1000)
|
||||||
|
return int(10 * (1000 ** (slider_value / 1000)))
|
||||||
|
|
||||||
|
|
||||||
class App:
|
class App:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
@@ -42,6 +63,10 @@ class App:
|
|||||||
self.delay_update_interval_ms = 100
|
self.delay_update_interval_ms = 100
|
||||||
self.pending_delay_update_id = None
|
self.pending_delay_update_id = None
|
||||||
|
|
||||||
|
self.last_n_params_update_time = 0
|
||||||
|
self.n_params_update_interval_ms = 100
|
||||||
|
self.pending_n_params_update_id = None
|
||||||
|
|
||||||
# --- WebSocketClient ---
|
# --- WebSocketClient ---
|
||||||
self.websocket_client = WebSocketClient("ws://192.168.4.1:80/ws")
|
self.websocket_client = WebSocketClient("ws://192.168.4.1:80/ws")
|
||||||
self.root.after(100, async_handler(self.websocket_client.connect))
|
self.root.after(100, async_handler(self.websocket_client.connect))
|
||||||
@@ -66,24 +91,46 @@ class App:
|
|||||||
|
|
||||||
self.notebook.bind("<<NotebookTabChanged>>", self.on_tab_change)
|
self.notebook.bind("<<NotebookTabChanged>>", self.on_tab_change)
|
||||||
|
|
||||||
# Add Reload Config Button (unchanged)
|
|
||||||
reload_button = tk.Button(
|
|
||||||
self.root,
|
|
||||||
text="Reload Config",
|
|
||||||
command=self.reload_config,
|
|
||||||
bg=active_bg_color,
|
|
||||||
fg=fg_color,
|
|
||||||
font=("Arial", 20),
|
|
||||||
padx=20,
|
|
||||||
pady=10,
|
|
||||||
relief=tk.FLAT,
|
|
||||||
)
|
|
||||||
reload_button.pack(side=tk.BOTTOM, pady=20)
|
|
||||||
|
|
||||||
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
|
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
|
||||||
|
|
||||||
async_mainloop(self.root)
|
async_mainloop(self.root)
|
||||||
|
|
||||||
|
def get_pattern_settings(self, tab_name, pattern_name):
|
||||||
|
"""Get pattern-specific settings (colors, delay, n params). Returns defaults if not found."""
|
||||||
|
light_settings = self.settings["lights"][tab_name]["settings"]
|
||||||
|
if "patterns" not in light_settings:
|
||||||
|
light_settings["patterns"] = {}
|
||||||
|
if pattern_name not in light_settings["patterns"]:
|
||||||
|
light_settings["patterns"][pattern_name] = {}
|
||||||
|
|
||||||
|
pattern_settings = light_settings["patterns"][pattern_name]
|
||||||
|
return {
|
||||||
|
"colors": pattern_settings.get("colors", ["#000000"]),
|
||||||
|
"delay": pattern_settings.get("delay", 100),
|
||||||
|
"n1": pattern_settings.get("n1", 10),
|
||||||
|
"n2": pattern_settings.get("n2", 10),
|
||||||
|
"n3": pattern_settings.get("n3", 10),
|
||||||
|
"n4": pattern_settings.get("n4", 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
def save_pattern_settings(self, tab_name, pattern_name, colors=None, delay=None, n_params=None):
|
||||||
|
"""Save pattern-specific settings."""
|
||||||
|
light_settings = self.settings["lights"][tab_name]["settings"]
|
||||||
|
if "patterns" not in light_settings:
|
||||||
|
light_settings["patterns"] = {}
|
||||||
|
if pattern_name not in light_settings["patterns"]:
|
||||||
|
light_settings["patterns"][pattern_name] = {}
|
||||||
|
|
||||||
|
pattern_settings = light_settings["patterns"][pattern_name]
|
||||||
|
if colors is not None:
|
||||||
|
pattern_settings["colors"] = colors
|
||||||
|
if delay is not None:
|
||||||
|
pattern_settings["delay"] = delay
|
||||||
|
if n_params is not None:
|
||||||
|
for i in range(1, 5):
|
||||||
|
if f"n{i}" in n_params:
|
||||||
|
pattern_settings[f"n{i}"] = n_params[f"n{i}"]
|
||||||
|
|
||||||
def on_closing(self):
|
def on_closing(self):
|
||||||
print("Closing application...")
|
print("Closing application...")
|
||||||
asyncio.create_task(self.websocket_client.close())
|
asyncio.create_task(self.websocket_client.close())
|
||||||
@@ -101,15 +148,22 @@ class App:
|
|||||||
self.tabs[key] = tab
|
self.tabs[key] = tab
|
||||||
|
|
||||||
def create_light_control_widgets(self, tab, tab_name, ids, initial_settings):
|
def create_light_control_widgets(self, tab, tab_name, ids, initial_settings):
|
||||||
slider_length = 800
|
slider_length = 600
|
||||||
slider_width = 50
|
slider_width = 50
|
||||||
|
|
||||||
# Extract initial color, brightness, and delay
|
# Get initial pattern and load pattern-specific settings
|
||||||
initial_colors = initial_settings.get("colors", ["#000000"])
|
|
||||||
initial_hex_color = initial_colors[0] if initial_colors else "#000000"
|
|
||||||
initial_brightness = initial_settings.get("brightness", 127)
|
|
||||||
initial_delay = initial_settings.get("delay", 0)
|
|
||||||
initial_pattern = initial_settings.get("pattern", "on")
|
initial_pattern = initial_settings.get("pattern", "on")
|
||||||
|
initial_brightness = initial_settings.get("brightness", 127) # Global brightness
|
||||||
|
pattern_settings = self.get_pattern_settings(tab_name, initial_pattern)
|
||||||
|
|
||||||
|
# Extract initial color, delay, and n params from pattern-specific settings
|
||||||
|
initial_colors = pattern_settings["colors"]
|
||||||
|
initial_hex_color = initial_colors[0] if initial_colors else "#000000"
|
||||||
|
initial_delay = pattern_settings["delay"]
|
||||||
|
initial_n1 = pattern_settings["n1"]
|
||||||
|
initial_n2 = pattern_settings["n2"]
|
||||||
|
initial_n3 = pattern_settings["n3"]
|
||||||
|
initial_n4 = pattern_settings["n4"]
|
||||||
|
|
||||||
initial_r, initial_g, initial_b = color_utils.hex_to_rgb(initial_hex_color)
|
initial_r, initial_g, initial_b = color_utils.hex_to_rgb(initial_hex_color)
|
||||||
|
|
||||||
@@ -117,9 +171,13 @@ class App:
|
|||||||
main_tab_frame = tk.Frame(tab, bg=bg_color)
|
main_tab_frame = tk.Frame(tab, bg=bg_color)
|
||||||
main_tab_frame.pack(expand=True, fill="both", padx=10, pady=10)
|
main_tab_frame.pack(expand=True, fill="both", padx=10, pady=10)
|
||||||
|
|
||||||
# Left panel for sliders
|
# Left panel container for sliders and n inputs
|
||||||
slider_panel_frame = tk.Frame(main_tab_frame, bg=bg_color)
|
left_panel_container = tk.Frame(main_tab_frame, bg=bg_color)
|
||||||
slider_panel_frame.pack(side=tk.LEFT, padx=10, pady=10)
|
left_panel_container.pack(side=tk.LEFT, padx=10, pady=10)
|
||||||
|
|
||||||
|
# Slider panel
|
||||||
|
slider_panel_frame = tk.Frame(left_panel_container, bg=bg_color)
|
||||||
|
slider_panel_frame.pack(side=tk.TOP, padx=10, pady=10)
|
||||||
|
|
||||||
# Common slider configuration
|
# Common slider configuration
|
||||||
slider_config = {
|
slider_config = {
|
||||||
@@ -166,22 +224,142 @@ class App:
|
|||||||
brightness_slider.bind("<B1-Motion>", lambda _: self.schedule_update_brightness(tab))
|
brightness_slider.bind("<B1-Motion>", lambda _: self.schedule_update_brightness(tab))
|
||||||
brightness_slider.bind("<ButtonRelease-1>", lambda _: self.schedule_update_brightness(tab, force_send=True))
|
brightness_slider.bind("<ButtonRelease-1>", lambda _: self.schedule_update_brightness(tab, force_send=True))
|
||||||
|
|
||||||
# Delay Slider
|
# Delay Slider with logarithmic scale (10ms to 10000ms)
|
||||||
delay_slider_config = slider_config.copy()
|
delay_slider_config = slider_config.copy()
|
||||||
delay_slider_config.update(
|
delay_slider_config.update(
|
||||||
{
|
{
|
||||||
"from_": 1000,
|
"from_": 1000, # Slider range 0-1000 (will be converted to 10-10000ms logarithmically)
|
||||||
"to": 0,
|
"to": 0,
|
||||||
"resolution": 10,
|
"resolution": 1,
|
||||||
"label": "Delay (ms)",
|
"label": "Delay (ms)",
|
||||||
|
"showvalue": False, # Hide default value, we'll show logarithmic value in custom label
|
||||||
"troughcolor": trough_color_delay,
|
"troughcolor": trough_color_delay,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
delay_slider = tk.Scale(slider_panel_frame, **delay_slider_config)
|
# Create a frame to contain the slider and its value label (to make them appear as one unit)
|
||||||
delay_slider.set(initial_delay)
|
delay_container = tk.Frame(slider_panel_frame, bg=bg_color)
|
||||||
delay_slider.pack(side=tk.LEFT, padx=10)
|
delay_container.pack(side=tk.LEFT, padx=10)
|
||||||
delay_slider.bind("<B1-Motion>", lambda _: self.schedule_update_delay(tab))
|
|
||||||
delay_slider.bind("<ButtonRelease-1>", lambda _: self.schedule_update_delay(tab, force_send=True))
|
delay_slider = tk.Scale(delay_container, **delay_slider_config)
|
||||||
|
# Convert initial delay to slider position using logarithmic scale
|
||||||
|
initial_slider_pos = delay_to_slider(initial_delay)
|
||||||
|
delay_slider.set(initial_slider_pos)
|
||||||
|
|
||||||
|
# Create a custom label to show the actual delay value, positioned like the default Scale value
|
||||||
|
delay_value_label = tk.Label(delay_container, text=f"{initial_delay}", font=("Arial", 12), bg=bg_color, fg=fg_color, width=5, anchor="e")
|
||||||
|
delay_value_label.pack(side=tk.LEFT, padx=(0, 5))
|
||||||
|
|
||||||
|
# Function to update the side label when slider moves
|
||||||
|
def update_delay_value_label(event=None):
|
||||||
|
slider_value = delay_slider.get()
|
||||||
|
actual_delay = slider_to_delay(slider_value)
|
||||||
|
delay_value_label.config(text=f"{actual_delay}")
|
||||||
|
|
||||||
|
delay_slider.pack(side=tk.LEFT)
|
||||||
|
delay_slider.bind("<B1-Motion>", lambda e: (update_delay_value_label(), self.schedule_update_delay(tab)))
|
||||||
|
delay_slider.bind("<ButtonRelease-1>", lambda e: (update_delay_value_label(), self.schedule_update_delay(tab, force_send=True)))
|
||||||
|
|
||||||
|
# N inputs panel below sliders (moved down to make sliders longer)
|
||||||
|
n_inputs_frame = tk.Frame(left_panel_container, bg=bg_color)
|
||||||
|
n_inputs_frame.pack(side=tk.TOP, padx=10, pady=10)
|
||||||
|
|
||||||
|
n_inputs_inner_frame = tk.Frame(n_inputs_frame, bg=bg_color)
|
||||||
|
n_inputs_inner_frame.pack()
|
||||||
|
|
||||||
|
# Common spinbox config for n inputs - larger for touch screen
|
||||||
|
n_spinbox_config = {
|
||||||
|
"from_": 0,
|
||||||
|
"to": 255,
|
||||||
|
"increment": 1,
|
||||||
|
"width": 12,
|
||||||
|
"bg": bg_color,
|
||||||
|
"fg": fg_color,
|
||||||
|
"font": ("Arial", 24),
|
||||||
|
"buttonbackground": active_bg_color,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create n1-n4 inputs in a grid with arrows on both sides
|
||||||
|
n_inputs = {}
|
||||||
|
for i in range(1, 5):
|
||||||
|
n_frame = tk.Frame(n_inputs_inner_frame, bg=bg_color)
|
||||||
|
n_frame.grid(row=(i-1)//2, column=(i-1)%2, padx=10, pady=10)
|
||||||
|
|
||||||
|
tk.Label(n_frame, text=f"n{i}", font=("Arial", 20), bg=bg_color, fg=fg_color).pack(pady=(0, 5))
|
||||||
|
|
||||||
|
# Create a frame for the input with arrows on both sides
|
||||||
|
input_container = tk.Frame(n_frame, bg=bg_color)
|
||||||
|
input_container.pack(pady=5)
|
||||||
|
|
||||||
|
# Use StringVar for the value
|
||||||
|
n_var = tk.StringVar(value=str(initial_settings.get(f"n{i}", 10)))
|
||||||
|
|
||||||
|
# Left arrow button (decrease)
|
||||||
|
def decrease_value(var=n_var):
|
||||||
|
try:
|
||||||
|
current_str = var.get()
|
||||||
|
if not current_str:
|
||||||
|
current = 0
|
||||||
|
else:
|
||||||
|
current = int(current_str)
|
||||||
|
new_value = current - 1
|
||||||
|
var.set(str(new_value))
|
||||||
|
self.schedule_update_n_params(tab, force_send=True)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
# If value is invalid, set to -1
|
||||||
|
var.set("-1")
|
||||||
|
self.schedule_update_n_params(tab, force_send=True)
|
||||||
|
|
||||||
|
left_arrow = tk.Button(
|
||||||
|
input_container,
|
||||||
|
text="−",
|
||||||
|
font=("Arial", 32, "bold"),
|
||||||
|
bg=active_bg_color,
|
||||||
|
fg=fg_color,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
command=decrease_value,
|
||||||
|
width=3,
|
||||||
|
height=1,
|
||||||
|
)
|
||||||
|
left_arrow.pack(side=tk.LEFT, padx=2)
|
||||||
|
|
||||||
|
# Entry in the middle
|
||||||
|
n_entry = tk.Entry(
|
||||||
|
input_container,
|
||||||
|
textvariable=n_var,
|
||||||
|
font=("Arial", 24),
|
||||||
|
bg=bg_color,
|
||||||
|
fg=fg_color,
|
||||||
|
width=8,
|
||||||
|
justify=tk.CENTER,
|
||||||
|
relief=tk.SUNKEN,
|
||||||
|
bd=2,
|
||||||
|
)
|
||||||
|
n_entry.pack(side=tk.LEFT, padx=2, ipady=8)
|
||||||
|
n_entry.bind("<KeyRelease>", lambda event: self.schedule_update_n_params(tab))
|
||||||
|
n_entry.bind("<FocusOut>", lambda event: self.schedule_update_n_params(tab, force_send=True))
|
||||||
|
|
||||||
|
# Right arrow button (increase)
|
||||||
|
def increase_value(var=n_var):
|
||||||
|
current = int(var.get())
|
||||||
|
new_value = current + 1
|
||||||
|
var.set(str(new_value))
|
||||||
|
self.schedule_update_n_params(tab, force_send=True)
|
||||||
|
|
||||||
|
right_arrow = tk.Button(
|
||||||
|
input_container,
|
||||||
|
text="+",
|
||||||
|
font=("Arial", 32, "bold"),
|
||||||
|
bg=active_bg_color,
|
||||||
|
fg=fg_color,
|
||||||
|
relief=tk.FLAT,
|
||||||
|
command=increase_value,
|
||||||
|
width=3,
|
||||||
|
height=1,
|
||||||
|
)
|
||||||
|
right_arrow.pack(side=tk.LEFT, padx=2)
|
||||||
|
|
||||||
|
n_inputs[f"n{i}"] = n_entry
|
||||||
|
n_inputs[f"n{i}_var"] = n_var # Store the variable for later updates
|
||||||
|
|
||||||
# Store references to widgets for this tab
|
# Store references to widgets for this tab
|
||||||
tab.widgets = {
|
tab.widgets = {
|
||||||
@@ -190,6 +368,15 @@ class App:
|
|||||||
"blue_slider": blue_slider,
|
"blue_slider": blue_slider,
|
||||||
"brightness_slider": brightness_slider,
|
"brightness_slider": brightness_slider,
|
||||||
"delay_slider": delay_slider,
|
"delay_slider": delay_slider,
|
||||||
|
"delay_value_label": delay_value_label, # Store the delay value label for updates
|
||||||
|
"n1": n_inputs["n1"],
|
||||||
|
"n1_var": n_inputs["n1_var"],
|
||||||
|
"n2": n_inputs["n2"],
|
||||||
|
"n2_var": n_inputs["n2_var"],
|
||||||
|
"n3": n_inputs["n3"],
|
||||||
|
"n3_var": n_inputs["n3_var"],
|
||||||
|
"n4": n_inputs["n4"],
|
||||||
|
"n4_var": n_inputs["n4_var"],
|
||||||
"selected_color_index": 0, # Default to the first color
|
"selected_color_index": 0, # Default to the first color
|
||||||
}
|
}
|
||||||
tab.colors_in_palette = initial_colors.copy() # Store the list of hex colors for this tab
|
tab.colors_in_palette = initial_colors.copy() # Store the list of hex colors for this tab
|
||||||
@@ -417,7 +604,7 @@ class App:
|
|||||||
# If not in 'transition' mode, but a color is selected, update sliders to that.
|
# If not in 'transition' mode, but a color is selected, update sliders to that.
|
||||||
# Or, if this is a fresh load/tab change, ensure it's the first color.
|
# Or, if this is a fresh load/tab change, ensure it's the first color.
|
||||||
# This ensures the sliders consistently show the color that will be sent
|
# This ensures the sliders consistently show the color that will be sent
|
||||||
# for 'on'/'blink' based on the palette's first entry.
|
# for 'on' based on the palette's first entry.
|
||||||
hex_color = tab.colors_in_palette[tab.widgets["selected_color_index"]]
|
hex_color = tab.colors_in_palette[tab.widgets["selected_color_index"]]
|
||||||
r, g, b = color_utils.hex_to_rgb(hex_color)
|
r, g, b = color_utils.hex_to_rgb(hex_color)
|
||||||
tab.widgets["red_slider"].set(r)
|
tab.widgets["red_slider"].set(r)
|
||||||
@@ -454,8 +641,12 @@ class App:
|
|||||||
# In a full reload, create_tabs ensures it is.
|
# In a full reload, create_tabs ensures it is.
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Get current pattern and load pattern-specific settings
|
||||||
|
current_pattern = initial_settings.get("pattern", "on")
|
||||||
|
pattern_settings = self.get_pattern_settings(selected_tab_name, current_pattern)
|
||||||
|
|
||||||
# Update the local colors_in_palette list for the tab
|
# Update the local colors_in_palette list for the tab
|
||||||
current_tab_widget.colors_in_palette = initial_settings.get("colors", ["#000000"]).copy()
|
current_tab_widget.colors_in_palette = pattern_settings["colors"].copy()
|
||||||
current_tab_widget.widgets["selected_color_index"] = 0 # Default to first color
|
current_tab_widget.widgets["selected_color_index"] = 0 # Default to first color
|
||||||
|
|
||||||
# Refresh the color palette display and select the first color
|
# Refresh the color palette display and select the first color
|
||||||
@@ -467,9 +658,19 @@ class App:
|
|||||||
current_tab_widget.widgets["green_slider"].set(0)
|
current_tab_widget.widgets["green_slider"].set(0)
|
||||||
current_tab_widget.widgets["blue_slider"].set(0)
|
current_tab_widget.widgets["blue_slider"].set(0)
|
||||||
|
|
||||||
# Update brightness and delay sliders
|
# Update brightness (global) and delay (pattern-specific) sliders
|
||||||
current_tab_widget.widgets["brightness_slider"].set(initial_settings.get("brightness", 127))
|
current_tab_widget.widgets["brightness_slider"].set(initial_settings.get("brightness", 127))
|
||||||
current_tab_widget.widgets["delay_slider"].set(initial_settings.get("delay", 0))
|
# Convert delay to slider position using logarithmic scale
|
||||||
|
initial_delay = pattern_settings["delay"]
|
||||||
|
initial_delay_slider_pos = delay_to_slider(initial_delay)
|
||||||
|
current_tab_widget.widgets["delay_slider"].set(initial_delay_slider_pos)
|
||||||
|
# Update the delay value label to show the actual delay value
|
||||||
|
if "delay_value_label" in current_tab_widget.widgets:
|
||||||
|
current_tab_widget.widgets["delay_value_label"].config(text=f"{initial_delay}")
|
||||||
|
|
||||||
|
# Update n parameter inputs (pattern-specific)
|
||||||
|
for i in range(1, 5):
|
||||||
|
current_tab_widget.widgets[f"n{i}_var"].set(str(pattern_settings[f"n{i}"]))
|
||||||
|
|
||||||
# Highlight the active pattern button
|
# Highlight the active pattern button
|
||||||
initial_pattern = initial_settings.get("pattern", "on")
|
initial_pattern = initial_settings.get("pattern", "on")
|
||||||
@@ -547,6 +748,26 @@ class App:
|
|||||||
time_to_wait = int(self.delay_update_interval_ms - (current_time - self.last_delay_update_time))
|
time_to_wait = int(self.delay_update_interval_ms - (current_time - self.last_delay_update_time))
|
||||||
self.pending_delay_update_id = self.root.after(time_to_wait, lambda: self.update_delay(tab))
|
self.pending_delay_update_id = self.root.after(time_to_wait, lambda: self.update_delay(tab))
|
||||||
|
|
||||||
|
def schedule_update_n_params(self, tab, force_send=False):
|
||||||
|
current_time = time.time() * 1000
|
||||||
|
if force_send:
|
||||||
|
if self.pending_n_params_update_id:
|
||||||
|
self.root.after_cancel(self.pending_n_params_update_id)
|
||||||
|
self.pending_n_params_update_id = None
|
||||||
|
self.update_n_params(tab)
|
||||||
|
self.last_n_params_update_time = current_time
|
||||||
|
elif current_time - self.last_n_params_update_time >= self.n_params_update_interval_ms:
|
||||||
|
if self.pending_n_params_update_id:
|
||||||
|
self.root.after_cancel(self.pending_n_params_update_id)
|
||||||
|
self.pending_n_params_update_id = None
|
||||||
|
self.update_n_params(tab)
|
||||||
|
self.last_n_params_update_time = current_time
|
||||||
|
else:
|
||||||
|
if self.pending_n_params_update_id:
|
||||||
|
self.root.after_cancel(self.pending_n_params_update_id)
|
||||||
|
time_to_wait = int(self.n_params_update_interval_ms - (current_time - self.last_n_params_update_time))
|
||||||
|
self.pending_n_params_update_id = self.root.after(time_to_wait, lambda: self.update_n_params(tab))
|
||||||
|
|
||||||
# --- Asynchronous Update Functions ---
|
# --- Asynchronous Update Functions ---
|
||||||
@async_handler
|
@async_handler
|
||||||
async def update_rgb(self, tab):
|
async def update_rgb(self, tab):
|
||||||
@@ -577,7 +798,7 @@ class App:
|
|||||||
|
|
||||||
if current_pattern == "transition":
|
if current_pattern == "transition":
|
||||||
colors_to_send = tab.colors_in_palette.copy()
|
colors_to_send = tab.colors_in_palette.copy()
|
||||||
elif current_pattern in ["on", "blink", "theater_chase", "flicker"]: # Add other patterns that use a single color
|
elif current_pattern in ["on", "theater_chase", "flicker"]: # Add other patterns that use a single color
|
||||||
if tab.colors_in_palette:
|
if tab.colors_in_palette:
|
||||||
# For non-transition patterns, the device typically uses only the first color.
|
# For non-transition patterns, the device typically uses only the first color.
|
||||||
# However, if a user picks a color from the palette, we want THAT color to be the one
|
# However, if a user picks a color from the palette, we want THAT color to be the one
|
||||||
@@ -598,15 +819,29 @@ class App:
|
|||||||
"settings": {
|
"settings": {
|
||||||
"colors": colors_to_send, # This now dynamically changes based on pattern
|
"colors": colors_to_send, # This now dynamically changes based on pattern
|
||||||
"brightness": tab.widgets["brightness_slider"].get(),
|
"brightness": tab.widgets["brightness_slider"].get(),
|
||||||
"delay": tab.widgets["delay_slider"].get(),
|
"delay": slider_to_delay(tab.widgets["delay_slider"].get()), # Convert from logarithmic slider
|
||||||
"pattern": current_pattern, # Always send the current pattern
|
"pattern": current_pattern, # Always send the current pattern
|
||||||
|
"n1": int(tab.widgets["n1_var"].get()),
|
||||||
|
"n2": int(tab.widgets["n2_var"].get()),
|
||||||
|
"n3": int(tab.widgets["n3_var"].get()),
|
||||||
|
"n4": int(tab.widgets["n4_var"].get()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update the settings object with the new color list (and potentially other synced values)
|
# Update the settings object - save pattern-specific settings
|
||||||
self.settings["lights"][selected_server]["settings"]["colors"] = tab.colors_in_palette.copy()
|
current_pattern = self.settings["lights"][selected_server]["settings"].get("pattern", "on")
|
||||||
|
slider_value = tab.widgets["delay_slider"].get()
|
||||||
|
delay = slider_to_delay(slider_value)
|
||||||
|
n_params = {f"n{i}": int(tab.widgets[f"n{i}_var"].get()) for i in range(1, 5)}
|
||||||
|
|
||||||
|
# Save pattern-specific settings
|
||||||
|
self.save_pattern_settings(selected_server, current_pattern,
|
||||||
|
colors=tab.colors_in_palette.copy(),
|
||||||
|
delay=delay,
|
||||||
|
n_params=n_params)
|
||||||
|
|
||||||
|
# Brightness is global
|
||||||
self.settings["lights"][selected_server]["settings"]["brightness"] = tab.widgets["brightness_slider"].get()
|
self.settings["lights"][selected_server]["settings"]["brightness"] = tab.widgets["brightness_slider"].get()
|
||||||
self.settings["lights"][selected_server]["settings"]["delay"] = tab.widgets["delay_slider"].get()
|
|
||||||
self.settings.save()
|
self.settings.save()
|
||||||
|
|
||||||
await self.websocket_client.send_data(payload)
|
await self.websocket_client.send_data(payload)
|
||||||
@@ -644,8 +879,9 @@ class App:
|
|||||||
async def update_delay(self, tab):
|
async def update_delay(self, tab):
|
||||||
try:
|
try:
|
||||||
delay_slider = tab.widgets["delay_slider"]
|
delay_slider = tab.widgets["delay_slider"]
|
||||||
delay = delay_slider.get()
|
slider_value = delay_slider.get()
|
||||||
print(f"Delay: {delay}")
|
delay = slider_to_delay(slider_value) # Convert from logarithmic slider to actual delay
|
||||||
|
print(f"Delay: {delay}ms (slider: {slider_value})")
|
||||||
|
|
||||||
selected_server = self.notebook.tab(self.notebook.select(), "text")
|
selected_server = self.notebook.tab(self.notebook.select(), "text")
|
||||||
names = self.settings["lights"][selected_server]["names"]
|
names = self.settings["lights"][selected_server]["names"]
|
||||||
@@ -656,14 +892,41 @@ class App:
|
|||||||
"delay": delay,
|
"delay": delay,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
# Update the settings object with the new delay
|
# Update pattern-specific delay setting
|
||||||
self.settings["lights"][selected_server]["settings"]["delay"] = delay
|
current_pattern = self.settings["lights"][selected_server]["settings"].get("pattern", "on")
|
||||||
|
self.save_pattern_settings(selected_server, current_pattern, delay=delay)
|
||||||
self.settings.save()
|
self.settings.save()
|
||||||
await self.websocket_client.send_data(payload)
|
await self.websocket_client.send_data(payload)
|
||||||
print(f"Sent delay payload: {payload}")
|
print(f"Sent delay payload: {payload}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error updating delay: {e}")
|
print(f"Error updating delay: {e}")
|
||||||
|
|
||||||
|
@async_handler
|
||||||
|
async def update_n_params(self, tab):
|
||||||
|
try:
|
||||||
|
n_params = {}
|
||||||
|
for i in range(1, 5):
|
||||||
|
n_var = tab.widgets[f"n{i}_var"]
|
||||||
|
n_params[f"n{i}"] = int(n_var.get())
|
||||||
|
|
||||||
|
print(f"N Parameters: {n_params}")
|
||||||
|
|
||||||
|
selected_server = self.notebook.tab(self.notebook.select(), "text")
|
||||||
|
names = self.settings["lights"][selected_server]["names"]
|
||||||
|
payload = {
|
||||||
|
"save": True,
|
||||||
|
"names": names,
|
||||||
|
"settings": n_params,
|
||||||
|
}
|
||||||
|
# Update pattern-specific n params
|
||||||
|
current_pattern = self.settings["lights"][selected_server]["settings"].get("pattern", "on")
|
||||||
|
self.save_pattern_settings(selected_server, current_pattern, n_params=n_params)
|
||||||
|
self.settings.save()
|
||||||
|
await self.websocket_client.send_data(payload)
|
||||||
|
print(f"Sent n params payload: {payload}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error updating n params: {e}")
|
||||||
|
|
||||||
@async_handler
|
@async_handler
|
||||||
async def send_pattern(self, tab_name: str, pattern_name: str):
|
async def send_pattern(self, tab_name: str, pattern_name: str):
|
||||||
try:
|
try:
|
||||||
@@ -681,26 +944,52 @@ class App:
|
|||||||
|
|
||||||
current_settings_for_tab = self.settings["lights"][tab_name]["settings"]
|
current_settings_for_tab = self.settings["lights"][tab_name]["settings"]
|
||||||
|
|
||||||
|
# Save current pattern's settings before switching
|
||||||
|
old_pattern = current_settings_for_tab.get("pattern", "on")
|
||||||
|
current_delay = slider_to_delay(current_tab_widget.widgets["delay_slider"].get())
|
||||||
|
current_n_params = {f"n{i}": int(current_tab_widget.widgets[f"n{i}_var"].get()) for i in range(1, 5)}
|
||||||
|
self.save_pattern_settings(tab_name, old_pattern,
|
||||||
|
colors=current_tab_widget.colors_in_palette.copy(),
|
||||||
|
delay=current_delay,
|
||||||
|
n_params=current_n_params)
|
||||||
|
|
||||||
|
# Load the new pattern's settings
|
||||||
|
new_pattern_settings = self.get_pattern_settings(tab_name, pattern_name)
|
||||||
|
|
||||||
|
# Update UI with new pattern's settings
|
||||||
|
current_tab_widget.colors_in_palette = new_pattern_settings["colors"].copy()
|
||||||
|
self.refresh_color_palette_display(current_tab_widget)
|
||||||
|
|
||||||
|
# Update delay slider
|
||||||
|
delay_slider_pos = delay_to_slider(new_pattern_settings["delay"])
|
||||||
|
current_tab_widget.widgets["delay_slider"].set(delay_slider_pos)
|
||||||
|
if "delay_value_label" in current_tab_widget.widgets:
|
||||||
|
current_tab_widget.widgets["delay_value_label"].config(text=f"{new_pattern_settings['delay']}")
|
||||||
|
|
||||||
|
# Update n params
|
||||||
|
for i in range(1, 5):
|
||||||
|
current_tab_widget.widgets[f"n{i}_var"].set(str(new_pattern_settings[f"n{i}"]))
|
||||||
|
|
||||||
|
# Update RGB sliders to first color
|
||||||
|
if current_tab_widget.colors_in_palette:
|
||||||
|
hex_color = current_tab_widget.colors_in_palette[0]
|
||||||
|
r, g, b = color_utils.hex_to_rgb(hex_color)
|
||||||
|
current_tab_widget.widgets["red_slider"].set(r)
|
||||||
|
current_tab_widget.widgets["green_slider"].set(g)
|
||||||
|
current_tab_widget.widgets["blue_slider"].set(b)
|
||||||
|
current_tab_widget.widgets["selected_color_index"] = 0
|
||||||
|
self._highlight_selected_color_swatch(current_tab_widget)
|
||||||
|
|
||||||
payload_settings = {
|
payload_settings = {
|
||||||
"pattern": pattern_name,
|
"pattern": pattern_name,
|
||||||
"brightness": current_settings_for_tab.get("brightness", 127),
|
"brightness": current_settings_for_tab.get("brightness", 127), # Global brightness
|
||||||
"delay": current_settings_for_tab.get("delay", 0),
|
"delay": new_pattern_settings["delay"],
|
||||||
|
"colors": new_pattern_settings["colors"],
|
||||||
}
|
}
|
||||||
|
|
||||||
# Determine colors to send based on the *newly selected* pattern
|
# Include n parameters
|
||||||
if pattern_name == "transition":
|
for i in range(1, 5):
|
||||||
payload_settings["colors"] = current_tab_widget.colors_in_palette.copy()
|
payload_settings[f"n{i}"] = new_pattern_settings[f"n{i}"]
|
||||||
elif pattern_name in ["on", "blink"]: # Add other patterns that use a single color here
|
|
||||||
# When switching TO 'on' or 'blink', ensure the color sent is the one
|
|
||||||
# currently displayed on the sliders (which reflects the selected palette color).
|
|
||||||
r = current_tab_widget.widgets["red_slider"].get()
|
|
||||||
g = current_tab_widget.widgets["green_slider"].get()
|
|
||||||
b = current_tab_widget.widgets["blue_slider"].get()
|
|
||||||
hex_color_from_sliders = f"#{r:02x}{g:02x}{b:02x}"
|
|
||||||
payload_settings["colors"] = [hex_color_from_sliders]
|
|
||||||
else:
|
|
||||||
# For other patterns, send the full palette, device might ignore or use default
|
|
||||||
payload_settings["colors"] = current_tab_widget.colors_in_palette.copy()
|
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
"save": True,
|
"save": True,
|
||||||
@@ -708,10 +997,8 @@ class App:
|
|||||||
"settings": payload_settings,
|
"settings": payload_settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update the settings object with the new pattern and current colors/brightness/delay
|
# Update the current pattern
|
||||||
self.settings["lights"][tab_name]["settings"]["pattern"] = pattern_name
|
self.settings["lights"][tab_name]["settings"]["pattern"] = pattern_name
|
||||||
# Always save the full current palette state in settings.
|
|
||||||
self.settings["lights"][tab_name]["settings"]["colors"] = current_tab_widget.colors_in_palette.copy()
|
|
||||||
self.settings.save()
|
self.settings.save()
|
||||||
|
|
||||||
self.highlight_pattern_button(current_tab_widget, pattern_name)
|
self.highlight_pattern_button(current_tab_widget, pattern_name)
|
||||||
@@ -730,10 +1017,20 @@ class App:
|
|||||||
if not hasattr(current_tab_widget, "colors_in_palette"):
|
if not hasattr(current_tab_widget, "colors_in_palette"):
|
||||||
return # Tab not fully initialized yet
|
return # Tab not fully initialized yet
|
||||||
|
|
||||||
# Update settings for the current tab in the self.settings object
|
# Update settings for the current tab - save pattern-specific settings
|
||||||
self.settings["lights"][selected_server]["settings"]["colors"] = current_tab_widget.colors_in_palette
|
current_pattern = self.settings["lights"][selected_server]["settings"].get("pattern", "on")
|
||||||
|
slider_value = current_tab_widget.widgets["delay_slider"].get()
|
||||||
|
delay = slider_to_delay(slider_value)
|
||||||
|
n_params = {f"n{i}": int(current_tab_widget.widgets[f"n{i}_var"].get()) for i in range(1, 5)}
|
||||||
|
|
||||||
|
# Save pattern-specific settings
|
||||||
|
self.save_pattern_settings(selected_server, current_pattern,
|
||||||
|
colors=current_tab_widget.colors_in_palette,
|
||||||
|
delay=delay,
|
||||||
|
n_params=n_params)
|
||||||
|
|
||||||
|
# Brightness is global
|
||||||
self.settings["lights"][selected_server]["settings"]["brightness"] = current_tab_widget.widgets["brightness_slider"].get()
|
self.settings["lights"][selected_server]["settings"]["brightness"] = current_tab_widget.widgets["brightness_slider"].get()
|
||||||
self.settings["lights"][selected_server]["settings"]["delay"] = current_tab_widget.widgets["delay_slider"].get()
|
|
||||||
# The pattern is updated in send_pattern already, but ensure consistency
|
# The pattern is updated in send_pattern already, but ensure consistency
|
||||||
# For simplicity, we assume send_pattern is the primary way to change pattern.
|
# For simplicity, we assume send_pattern is the primary way to change pattern.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user