-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathPluginSettings.py
42 lines (24 loc) · 956 Bytes
/
PluginSettings.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
import json
class PluginSettings():
def __init__(self, filepath=''):
PluginSettings.__instance = self
self._settingsDictionary = {}
if filepath != '':
self.LoadFromFile(filepath)
def SetValue(self, setting, value)->None:
self._settingsDictionary[setting] = value
def GetValue(self, setting, default=''):
try:
return self._settingsDictionary[setting]
except KeyError:
return default
def SaveToFile(self, filepath)->None:
with open(filepath, 'w') as settingsFile:
json.dump(self._settingsDictionary, settingsFile)
def LoadFromFile(self, filepath)->None:
try:
# Load settings from the settings file, if it exists
with open(filepath, 'r') as settingsFile:
self._settingsDictionary = json.load(settingsFile)
except FileNotFoundError:
pass