Added settings dialog

This commit is contained in:
Jamie Cash
2021-02-16 17:15:00 +00:00
parent 15eec4d08b
commit 2349a362e8
8 changed files with 425 additions and 170 deletions
+24 -20
View File
@@ -7,25 +7,18 @@ class Config(object):
Provides access to application configuration parameters stored in config.yaml.
"""
_config = None
_path = None
_instance = None
config_filepath = None
__config = None
__instance = None
def __init__(self):
"""
Singleton. Raise runtime error
"""
raise RuntimeError('Call instance() instead')
@classmethod
def instance(cls):
def __new__(cls):
"""
Singleton. Get instance of this class. Create if not already created.
:return:
"""
if cls._instance is None:
cls._instance = cls.__new__(cls)
return cls._instance
if cls.__instance is None:
cls.__instance = super(Config, cls).__new__(cls)
return cls.__instance
def load(self, path):
"""
@@ -34,10 +27,10 @@ class Config(object):
:return:
"""
with open(path, 'r') as yamlfile:
self._config = yaml.safe_load(yamlfile)
self.__config = yaml.safe_load(yamlfile)
# Store path so that we can save later
self._path = path
self.config_filepath = path
def save(self):
"""
@@ -45,9 +38,9 @@ class Config(object):
:return:
"""
with open(self._path, 'w') as file:
with open(self.config_filepath, 'w') as file:
file.write("---\n")
yaml.dump(self._config, file, sort_keys=False)
yaml.dump(self.__config, file, sort_keys=False)
file.write("...")
def get(self, path):
@@ -62,12 +55,23 @@ class Config(object):
for element in elements:
if last is None:
last = self._config[element]
last = self.__config[element]
else:
last = last[element]
return last
def get_root_nodes(self):
"""
Returns all root notes as a list
:return: dict of root notes of YAML config file
"""
nodes = []
for key in self.__config:
nodes.append(key)
return nodes
def set(self, path, value):
"""
Sets a config property value
@@ -75,7 +79,7 @@ class Config(object):
:param value: Value to set property to
:return:
"""
obj = self._config
obj = self.__config
key_list = path.split(".")
for k in key_list[:-1]: