-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
36 lines (31 loc) · 1.26 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from simple_log import log
class SettingHandler:
settings = {"show_hidden_files":"False", "continue_from_last":"False", "last_dir":"$HOME"}
filename = "settings.txt"
guipy_location = None
def __init__(self, basepath):
self.guipy_location = basepath
self.filename = self.guipy_location + "/" + self.filename
def save_settings(self):
try:
log("Saving settings.", "i")
with open(self.filename, "w") as settings_file:
for key in self.settings:
settings_file.write(f"{key}:{self.settings[key]}\n")
except:
log("Unable to save settings.", "e")
def load_settings(self):
try:
log("Loading settings.", "i")
with open(self.filename, "r") as settings_file:
for line in settings_file:
if not line == "":
_line = line.split(":")
self.settings[_line[0]] = _line[1].strip()
except:
log("Setting file not found. Generating a default settings file.", "e")
self.save_settings()
self.load_settings()
def change_setting(self, setting, value):
self.settings[setting] = value
self.save_settings()