Show descriptive names for n parameters based on selected pattern
This commit is contained in:
48
src/main.py
48
src/main.py
@@ -95,6 +95,38 @@ class App:
|
||||
|
||||
async_mainloop(self.root)
|
||||
|
||||
def get_n_parameter_name(self, pattern_name, n_index):
|
||||
"""Get the descriptive name for an n parameter based on the pattern.
|
||||
Returns None if no description exists."""
|
||||
patterns_config = self.settings.get("patterns", {})
|
||||
pattern_config = patterns_config.get(pattern_name, {})
|
||||
|
||||
# Find which n parameter this index maps to
|
||||
n_key = f"n{n_index}"
|
||||
for desc_name, mapped_n in pattern_config.items():
|
||||
if mapped_n == n_key:
|
||||
return desc_name
|
||||
|
||||
# If no mapping found, return None
|
||||
return None
|
||||
|
||||
def update_n_labels(self, tab, pattern_name):
|
||||
"""Update the n parameter labels to show descriptive names and hide/show inputs."""
|
||||
for i in range(1, 5):
|
||||
label_key = f"n{i}_label"
|
||||
frame_key = f"n{i}_frame"
|
||||
|
||||
if label_key in tab.widgets and frame_key in tab.widgets:
|
||||
desc_name = self.get_n_parameter_name(pattern_name, i)
|
||||
|
||||
if desc_name:
|
||||
# Show the input and update label
|
||||
tab.widgets[frame_key].grid()
|
||||
tab.widgets[label_key].config(text=desc_name)
|
||||
else:
|
||||
# Hide the input if no description
|
||||
tab.widgets[frame_key].grid_remove()
|
||||
|
||||
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"]
|
||||
@@ -283,8 +315,11 @@ class App:
|
||||
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)
|
||||
n_inputs[f"n{i}_frame"] = n_frame # Store frame reference for hiding/showing
|
||||
|
||||
tk.Label(n_frame, text=f"n{i}", font=("Arial", 20), bg=bg_color, fg=fg_color).pack(pady=(0, 5))
|
||||
n_label = tk.Label(n_frame, text=f"n{i}", font=("Arial", 20), bg=bg_color, fg=fg_color)
|
||||
n_label.pack(pady=(0, 5))
|
||||
n_inputs[f"n{i}_label"] = n_label # Store label reference
|
||||
|
||||
# Create a frame for the input with arrows on both sides
|
||||
input_container = tk.Frame(n_frame, bg=bg_color)
|
||||
@@ -377,6 +412,14 @@ class App:
|
||||
"n3_var": n_inputs["n3_var"],
|
||||
"n4": n_inputs["n4"],
|
||||
"n4_var": n_inputs["n4_var"],
|
||||
"n1_label": n_inputs["n1_label"],
|
||||
"n2_label": n_inputs["n2_label"],
|
||||
"n3_label": n_inputs["n3_label"],
|
||||
"n4_label": n_inputs["n4_label"],
|
||||
"n1_frame": n_inputs["n1_frame"],
|
||||
"n2_frame": n_inputs["n2_frame"],
|
||||
"n3_frame": n_inputs["n3_frame"],
|
||||
"n4_frame": n_inputs["n4_frame"],
|
||||
"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
|
||||
@@ -476,6 +519,7 @@ class App:
|
||||
|
||||
# The initial call to update_ui_for_pattern now only sets slider values and highlights
|
||||
self.update_ui_for_pattern(tab, initial_pattern)
|
||||
self.update_n_labels(tab, initial_pattern) # Update n parameter labels
|
||||
|
||||
def refresh_color_palette_display(self, tab):
|
||||
"""Clears and repopulates the color swatches in the palette display."""
|
||||
@@ -678,6 +722,7 @@ class App:
|
||||
|
||||
# Update UI visibility based on the current pattern
|
||||
self.update_ui_for_pattern(current_tab_widget, initial_pattern)
|
||||
self.update_n_labels(current_tab_widget, initial_pattern) # Update n parameter labels
|
||||
|
||||
def reload_config(self):
|
||||
print("Reloading configuration...")
|
||||
@@ -1003,6 +1048,7 @@ class App:
|
||||
|
||||
self.highlight_pattern_button(current_tab_widget, pattern_name)
|
||||
self.update_ui_for_pattern(current_tab_widget, pattern_name) # Update UI based on new pattern
|
||||
self.update_n_labels(current_tab_widget, pattern_name) # Update n parameter labels
|
||||
|
||||
await self.websocket_client.send_data(payload)
|
||||
print(f"Sent pattern payload: {payload}")
|
||||
|
||||
Reference in New Issue
Block a user