Move patterns to separate patterns.json file

This commit is contained in:
2025-11-30 14:43:22 +13:00
parent 8dabf852ba
commit 92526ab05c
3 changed files with 48 additions and 36 deletions

25
patterns.json Normal file
View File

@@ -0,0 +1,25 @@
{
"on": {},
"off": {},
"rainbow": {
"Step Rate": "n1"
},
"transition": {},
"chase": {
"Colour 1 Length": "n1",
"Colour 2 Length": "n2",
"Step 1": "n3",
"Step 2": "n4"
},
"pulse": {
"Attack": "n1",
"Hold": "n2",
"Decay": "n3"
},
"circle": {
"Head Rate": "n1",
"Max Length": "n2",
"Tail Rate": "n3",
"Min Length": "n4"
}
}

View File

@@ -9,8 +9,8 @@
"colors": [
"#968a00"
],
"brightness": 57,
"pattern": "on",
"brightness": 39,
"pattern": "rainbow",
"delay": 99,
"n1": 10,
"n2": 10,
@@ -69,10 +69,11 @@
},
"off": {
"colors": [
"#000000"
"#0000ff",
"#ff0000"
],
"delay": 99,
"n1": -17,
"delay": 10000,
"n1": 10,
"n2": 10,
"n3": 10,
"n4": 10,
@@ -136,7 +137,7 @@
"#ff0000"
],
"brightness": 39,
"pattern": "on",
"pattern": "circle",
"delay": 10000,
"n1": 10,
"n2": 10,
@@ -200,7 +201,7 @@
"#0000ff",
"#ff0000"
],
"delay": 399,
"delay": 10000,
"n1": 10,
"n2": 10,
"n3": 10,
@@ -236,7 +237,7 @@
"#00ff00"
],
"delay": 1778,
"n1": 10,
"n1": 20,
"n2": 40,
"n3": 40,
"n4": 0
@@ -843,30 +844,5 @@
}
}
}
},
"patterns": {
"on": {},
"off": {},
"rainbow": {
"Step Rate": "n1"
},
"transition": {},
"chase": {
"Colour 1 Length": "n1",
"Colour 2 Length": "n2",
"Step 1": "n3",
"Step 2": "n4"
},
"pulse": {
"Attack": "n1",
"Hold": "n2",
"Decay": "n3"
},
"circle": {
"Head Rate": "n1",
"Max Length": "n2",
"Tail Rate": "n3",
"Min Length": "n4"
}
}
}

View File

@@ -46,6 +46,7 @@ def slider_to_delay(slider_value):
class App:
def __init__(self) -> None:
self.settings = Settings()
self.patterns = self.load_patterns()
self.root = tk.Tk()
self.root.attributes("-fullscreen", True)
self.root.configure(bg=bg_color)
@@ -95,11 +96,21 @@ class App:
async_mainloop(self.root)
def load_patterns(self):
"""Load patterns from patterns.json file."""
try:
with open("patterns.json", 'r') as file:
patterns = json.load(file)
print("Patterns loaded successfully.")
return patterns
except Exception as e:
print(f"Error loading patterns: {e}")
return {}
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, {})
pattern_config = self.patterns.get(pattern_name, {})
# Find which n parameter this index maps to
n_key = f"n{n_index}"
@@ -453,7 +464,7 @@ class App:
tk.Label(patterns_frame, text="Patterns:", font=("Arial", 20), bg=bg_color, fg=fg_color).pack(pady=10)
tab.pattern_buttons = {}
patterns = self.settings.get("patterns", [])
patterns = list(self.patterns.keys())
for pattern_name in patterns:
button = tk.Button(
patterns_frame,