From 2ee0a4f7ef9b5a1d423a8f60817ef9ee9e54a070 Mon Sep 17 00:00:00 2001 From: Giuseppe Di Mauro Date: Mon, 4 Mar 2024 18:58:30 +0100 Subject: [PATCH] [GUI] fix broken GUI - update backgrounds references - also fix paths --- GUI.py | 6 +++--- GUI/backgrounds.html | 2 +- GUI/settings.html | 8 ++++---- utils/gui_utils.py | 17 +++++++++-------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/GUI.py b/GUI.py index 4588083..57a4b08 100644 --- a/GUI.py +++ b/GUI.py @@ -43,7 +43,7 @@ def index(): @app.route("/backgrounds", methods=["GET"]) def backgrounds(): - return render_template("backgrounds.html", file="backgrounds.json") + return render_template("backgrounds.html", file="background_videos.json") @app.route("/background/add", methods=["POST"]) @@ -92,9 +92,9 @@ def videos_json(): # Make backgrounds.json accessible -@app.route("/backgrounds.json") +@app.route("/background_videos.json") def backgrounds_json(): - return send_from_directory("utils", "backgrounds.json") + return send_from_directory("utils", "background_videos.json") # Make videos in results folder accessible diff --git a/GUI/backgrounds.html b/GUI/backgrounds.html index 541e39f..438aa90 100644 --- a/GUI/backgrounds.html +++ b/GUI/backgrounds.html @@ -125,7 +125,7 @@ // Show background videos $(document).ready(function () { - $.getJSON("backgrounds.json", + $.getJSON("background_videos.json", function (data) { delete data["__comment"]; var background = ''; diff --git a/GUI/settings.html b/GUI/settings.html index 1f0ef2e..c0aea38 100644 --- a/GUI/settings.html +++ b/GUI/settings.html @@ -200,12 +200,12 @@
- +
- diff --git a/utils/gui_utils.py b/utils/gui_utils.py index f683adf..58fcc42 100644 --- a/utils/gui_utils.py +++ b/utils/gui_utils.py @@ -125,12 +125,13 @@ def modify_settings(data: dict, config_load, checks: dict): # Delete background video def delete_background(key): - # Read backgrounds.json - with open("utils/backgrounds.json", "r", encoding="utf-8") as backgrounds: + # Read background_videos.json + breakpoint() + with open("utils/background_videos.json", "r", encoding="utf-8") as backgrounds: data = json.load(backgrounds) - # Remove background from backgrounds.json - with open("utils/backgrounds.json", "w", encoding="utf-8") as backgrounds: + # Remove background from background_videos.json + with open("utils/background_videos.json", "w", encoding="utf-8") as backgrounds: if data.pop(key, None): json.dump(data, backgrounds, ensure_ascii=False, indent=4) else: @@ -139,7 +140,7 @@ def delete_background(key): # Remove background video from ".config.template.toml" config = tomlkit.loads(Path("utils/.config.template.toml").read_text()) - config["settings"]["background"]["background_choice"]["options"].remove(key) + config["settings"]["background"]["background_video"]["options"].remove(key) with Path("utils/.config.template.toml").open("w") as toml_file: toml_file.write(tomlkit.dumps(config)) @@ -179,7 +180,7 @@ def add_background(youtube_uri, filename, citation, position): filename = filename.replace(" ", "_") # Check if background doesn't already exist - with open("utils/backgrounds.json", "r", encoding="utf-8") as backgrounds: + with open("utils/background_videos.json", "r", encoding="utf-8") as backgrounds: data = json.load(backgrounds) # Check if key isn't already taken @@ -193,7 +194,7 @@ def add_background(youtube_uri, filename, citation, position): return # Add background video to json file - with open("utils/backgrounds.json", "r+", encoding="utf-8") as backgrounds: + with open("utils/background_videos.json", "r+", encoding="utf-8") as backgrounds: data = json.load(backgrounds) data[filename] = [youtube_uri, filename + ".mp4", citation, position] @@ -202,7 +203,7 @@ def add_background(youtube_uri, filename, citation, position): # Add background video to ".config.template.toml" config = tomlkit.loads(Path("utils/.config.template.toml").read_text()) - config["settings"]["background"]["background_choice"]["options"].append(filename) + config["settings"]["background"]["background_video"]["options"].append(filename) with Path("utils/.config.template.toml").open("w") as toml_file: toml_file.write(tomlkit.dumps(config))