-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.py
49 lines (41 loc) · 1.54 KB
/
configure.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
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from kivymd.app import MDApp
app = MDApp.get_running_app()
class Config:
variable_dict = {}
def get_variable(self, variable):
if variable in self.variable_dict:
return self.variable_dict[variable]
else:
raise Exception(f"{variable} Doesn't Exist in variable dictionary")
def set_variables(self, variable_dict=None):
if variable_dict is None:
variable_dict = {}
self.variable_dict = variable_dict
for var, value in variable_dict.items():
if 'self.' in var:
var = var.replace('self.', '')
if var != 'dark_mode':
if type(value) != str:
exec(f'app.{var}={value}')
else:
exec(f"app.{var}='{value}'")
def save_variables(self):
for var in list(self.variable_dict.keys()):
if 'self.' in var:
del self.variable_dict[var]
var = var.replace('self.', '')
exec(f"self.variable_dict['{var}']= app.{var}")
with open('variable_dict.txt', 'w') as file:
file.write(str(self.variable_dict))
def restore_variables(self):
if os.path.exists('variable_dict.txt'):
with open('variable_dict.txt', 'r') as file:
self.variable_dict = eval(file.read())
self.set_variables(self.variable_dict)
if self.variable_dict != {}:
return True
else:
return False
else:
return False