-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONutils.py
49 lines (37 loc) · 1.17 KB
/
JSONutils.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 json
import gi
gi.require_version('Gtk','3.0')
from gi.repository import Gtk
def saveConfig(ipAddress,transitionType,transitionTime):
#Create the obect to store
dictionnary = {
"ipAddress" : ipAddress,
"transitionType" : transitionType,
"transitionTime" : transitionTime
}
jsonParsed = json.dumps(dictionnary,indent=4)
#Write the config to text
with open("config/config.cfg",'w') as configFile:
configFile.write(jsonParsed)
def loadConfig():
#Read the file
with open("config/config.cfg",'r') as configFile:
dictionnary = json.load(configFile)
return dictionnary
def loadTheme():
#Read the file
with open("config/themes.cfg",'r') as themeFile:
try:
dictionnary = json.load(themeFile)
except ValueError:
#Create the dialog
errorDialog = Gtk.MessageDialog(parent=None,
flags=0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK)
errorDialog.set_property("text","JSON error")
errorDialog.format_secondary_text("An error occurred while parsing the JSON file. Please double check your file and try again")
errorDialog.run()
#Destroy the dialog
errorDialog.destroy()
return dictionnary