|
@@ -28,6 +28,7 @@
|
|
|
#####################################################################
|
|
|
|
|
|
import os
|
|
|
+import json
|
|
|
from flbry.variables import *
|
|
|
|
|
|
# This file will manage settings / installation and stuff like this.
|
|
@@ -46,9 +47,80 @@ def get_settings_folder(flbry="flbry/"):
|
|
|
|
|
|
return data_dir
|
|
|
|
|
|
+def check_config():
|
|
|
|
|
|
+ # This function checks whether config exists. If not makes a
|
|
|
+ # default setting.
|
|
|
|
|
|
+ default = {"theme":"default"}
|
|
|
+
|
|
|
+ if not os.path.exists(get_settings_folder()+"config.json"):
|
|
|
+ with open(get_settings_folder()+"config.json", 'w') as f:
|
|
|
+ json.dump(default, f, indent=4, sort_keys=True)
|
|
|
+
|
|
|
+def get(key):
|
|
|
+
|
|
|
+ # This function gets a setting from settings.
|
|
|
+
|
|
|
+ with open(get_settings_folder()+"config.json") as f:
|
|
|
+ data = json.load(f)
|
|
|
+
|
|
|
+ try:
|
|
|
+ return data[key]
|
|
|
+ except:
|
|
|
+ return None
|
|
|
+
|
|
|
+def save(key, value):
|
|
|
+
|
|
|
+ # This function will save a value into the settings file.
|
|
|
+
|
|
|
+ with open(get_settings_folder()+"config.json") as f:
|
|
|
+ data = json.load(f)
|
|
|
+
|
|
|
+ data[key] = value
|
|
|
+
|
|
|
+ with open(get_settings_folder()+"config.json", 'w') as f:
|
|
|
+ json.dump(data, f, indent=4, sort_keys=True)
|
|
|
+
|
|
|
+
|
|
|
+def set_theme(theme):
|
|
|
+
|
|
|
+ # This will set a global theme
|
|
|
+
|
|
|
+
|
|
|
+ user_themes = get_settings_folder()+"themes/"
|
|
|
+ default_themes = "themes/"
|
|
|
+
|
|
|
+ # First let's see if user has a theme folder in settings.
|
|
|
+ try:
|
|
|
+ os.makedirs(user_themes)
|
|
|
+ except:
|
|
|
+ pass
|
|
|
+
|
|
|
+ # Trying to load the theme from user themes first
|
|
|
+ try:
|
|
|
+ with open(user_themes+theme+".json") as f:
|
|
|
+ data = json.load(f)
|
|
|
+ except Exception as e:
|
|
|
+
|
|
|
+ try:
|
|
|
+ with open(default_themes+theme+".json") as f:
|
|
|
+ data = json.load(f)
|
|
|
+ except Exception as e:
|
|
|
+
|
|
|
+ return
|
|
|
|
|
|
+ # Now let's actually apply the theme
|
|
|
+ from flbry import variables
|
|
|
+
|
|
|
+ for i in data:
|
|
|
+ if data[i] in variables.clr:
|
|
|
+ variables.clr[i] = clr[data[i]]
|
|
|
+ else:
|
|
|
+ variables.clr[i] = "\033["+data[i]+"m"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
def install_desktop(force=True):
|
|
|
|
|
|
# This function will generate a .desktop file. And put it in
|
|
@@ -82,3 +154,77 @@ Categories=Network;AudioVideo"""
|
|
|
center("Installed in Applications Menu", "bdgr")
|
|
|
except:
|
|
|
center("Installing in Applications Menu failed", "bdrd")
|
|
|
+
|
|
|
+def theme_ui():
|
|
|
+
|
|
|
+ # This is the ui for setting up themes.
|
|
|
+
|
|
|
+ themes = []
|
|
|
+ for i in os.listdir("themes"):
|
|
|
+ if i.endswith(".json"):
|
|
|
+ themes.append(i.replace(".json", ""))
|
|
|
+ for i in os.listdir(get_settings_folder()+"themes"):
|
|
|
+ if i.endswith(".json") and i.replace(".json", "") not in themes:
|
|
|
+ themes.append(i.replace(".json", ""))
|
|
|
+
|
|
|
+ d = {"categories":["Theme"],
|
|
|
+ "size":[1],
|
|
|
+ "data":[]}
|
|
|
+ for i in themes:
|
|
|
+ d["data"].append([i])
|
|
|
+ table(d)
|
|
|
+ center("Select Theme")
|
|
|
+
|
|
|
+ # User selects a theme
|
|
|
+ c = input(typing_dots())
|
|
|
+ try:
|
|
|
+ save("theme", themes[int(c)])
|
|
|
+ except:
|
|
|
+ save("theme", "default")
|
|
|
+
|
|
|
+ center("Theme set to: "+get("theme"), "bdgr")
|
|
|
+ set_theme(get("theme"))
|
|
|
+
|
|
|
+
|
|
|
+def ui():
|
|
|
+
|
|
|
+ # This will be the user interface for setting up setting.
|
|
|
+
|
|
|
+ with open(get_settings_folder()+"config.json") as f:
|
|
|
+ data = json.load(f)
|
|
|
+
|
|
|
+ d = {"categories":["name","value"],
|
|
|
+ "size":[1,1],
|
|
|
+ "data":[]}
|
|
|
+
|
|
|
+ for i in data:
|
|
|
+ d["data"].append([i, data[i]])
|
|
|
+ table(d)
|
|
|
+
|
|
|
+ center("Type the number of setting to set")
|
|
|
+
|
|
|
+ # user inputs the number
|
|
|
+ while True:
|
|
|
+ c = input(typing_dots())
|
|
|
+ try:
|
|
|
+ c = int(c)
|
|
|
+ except:
|
|
|
+ break
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ # If editing theme
|
|
|
+ if list(data.keys())[c] == "theme":
|
|
|
+ theme_ui()
|
|
|
+
|
|
|
+ else:
|
|
|
+
|
|
|
+ value = input(" New Value:")
|
|
|
+
|
|
|
+ try:
|
|
|
+ save(list(data.keys())[c], value)
|
|
|
+ center("Setting was overwritten successfully.", "bdgr")
|
|
|
+ except Exception as e:
|
|
|
+ center("Error saving setting: "+str(e), "bdrd")
|
|
|
+
|
|
|
+
|