From e30a70253ca3876687a80cc2857982035346c783 Mon Sep 17 00:00:00 2001
From: TheJoeCoder <joe@radialbog9.uk>
Date: Tue, 24 Sep 2024 09:57:31 +0100
Subject: [PATCH] Make config file better

---
 .gitignore |  1 +
 config.py  | 58 +++++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/.gitignore b/.gitignore
index 58b824d..6bbc21e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -127,3 +127,4 @@ dmypy.json
 cython_debug/
 
 module_config.json
+hw_config.json
\ No newline at end of file
diff --git a/config.py b/config.py
index 379783c..19dfd5c 100644
--- a/config.py
+++ b/config.py
@@ -1,12 +1,46 @@
-PROP_SCREEN_WIDTH = 240
-PROP_SCREEN_HEIGHT = 280
+import os.path
+import json
+
+default_config = {
+    "screen_width": 240,
+    "screen_height": 280,
+    "window_fullscreen": True,
+    "hide_mouse": True,
+    "window_scale": 2,
+    "leds_driver": "npixel",
+    "leds_location": "D12",
+    "leds_length": 15,
+    "flask_debug": False,
+    "flask_host": "0.0.0.0",
+    "flask_port": 5000
+}
+
+config = default_config.copy()
+if os.path.exists("config.json"):
+    with open("config.json", "r") as f:
+        config.update(json.load(f))
+
+with open("config.json", "w") as f:
+    json.dump(config, f, indent=4)
+
+PROP_SCREEN_WIDTH = config["screen_width"]
+PROP_SCREEN_HEIGHT = config["screen_height"]
+
+PROP_WINDOW_FULLSCREEN = config["window_fullscreen"]
+
+PROP_HIDE_MOUSE = config["hide_mouse"]
 
-PROP_WINDOW_FULLSCREEN = False
+# Make the window scale larger for development
+PROP_WINDOW_SCALE = config["window_scale"]
 
-PROP_HIDE_MOUSE = False
+PROP_FLASK_DEBUG = config["flask_debug"]
+PROP_FLASK_HOST = config["flask_host"]
+PROP_FLASK_PORT = config["flask_port"]
+
+PROP_LEDS_DRIVER = config["leds_driver"]
+PROP_LEDS_LOCATION = config["leds_location"]
+PROP_LEDS_LENGTH = config["leds_length"]
 
-# Make the window scale larger for development
-PROP_WINDOW_SCALE = 3
 
 PROP_AVAILABLE_WIDGETS = [
     "IPShowWidget",
@@ -19,15 +53,3 @@ PROP_AVAILABLE_PATTERNS = [
     "RainbowPattern",
     "SolidColorPattern"
 ]
-
-PROP_FLASK_DEBUG = False
-PROP_FLASK_HOST = "0.0.0.0"
-PROP_FLASK_PORT = 5000
-
-PROP_LEDS_DRIVER = "dummy"
-PROP_LEDS_LOCATION=""
-PROP_LEDS_LENGTH = 15
-
-# PROP_LEDS_DRIVER="npixel"
-# PROP_LEDS_LOCATION="D12"
-# PROP_LEDS_LENGTH = 15
-- 
GitLab