forked from JackD83/PyMenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.py
56 lines (41 loc) · 1.25 KB
/
Configuration.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
50
51
52
53
54
55
import json, subprocess
from ast import literal_eval as make_tuple
from pprint import pprint
configuration = json.load(open('config/config.json'))
theme = json.load(open('theme/theme.json'))
listeners = []
def getConfiguration():
return configuration
def reloadConfiguration():
configuration = json.load(open('config/config.json'))
def saveConfiguration():
try:
subprocess.Popen(["sync"])
except Exception:
pass
with open('config/config.json', 'w') as fp:
json.dump(configuration, fp,sort_keys=True, indent=4)
try:
subprocess.Popen(["sync"])
except Exception:
pass
for l in listeners:
l()
def getTheme():
return theme
def toColor(input):
return make_tuple(input)
def isRS97():
return "RS97" in configuration and configuration["RS97"]
def addConfigChangedCallback(listener):
listeners.append(listener)
def getPathData(path, data = None):
if(data == None):
data = configuration
if path and data:
args = path.split("/")
element = args[0]
if element:
newPath = '/'.join(args[1:])
value = data.get(element)
return value if len(args) == 1 else getPathData(value, newPath)