-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpreferences.py
More file actions
64 lines (50 loc) · 1.76 KB
/
preferences.py
File metadata and controls
64 lines (50 loc) · 1.76 KB
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
56
57
58
59
60
61
62
63
64
import os
import json
from logger import log
from config import *
class Preferences(object):
Instance = None
def __init__(self):
self.windowPos = [0, 0]
self.serverIp = '192.168.1.200'
self.serverPort = 13555
self.boundsTopLeft = [0.2, 0.2]
self.boundsTopRight = [0.8, 0.2]
self.boundsBottomRight = [0.8, 0.8]
self.boundsBottomLeft = [0.2, 0.8]
self.totalFadeTimeMS = 200
self.fixedColorEnabled = False
self.colorHue = 20
self.colorSaturation = 255
self.colorBrightness = 0
self.camSaturation = 117
self.camBrightness = 30
self.camContrast = 74
self.camGain = 204
## Load prefs from file
def loadPreferences():
log.info("Loading preferences from file: %s", PREFERENCES_FILE)
Preferences.Instance = Preferences()
if not os.path.exists(PREFERENCES_FILE):
log.info("...preferences file does not exist. Using defaults!")
return
try:
file = open(PREFERENCES_FILE)
# Merge the two together
new_prefs = json.loads(file.read())
for attr, value in new_prefs.items():
if attr in Preferences.Instance.__dict__.keys():
Preferences.Instance.__setattr__(attr, value)
log.debug(" - %s = %s", attr, value)
file.close()
log.info("Preferences loaded")
except Exception as ex:
log.error("Failed to load preferences from file", ex)
## Save prefs
def savePreferences():
log.info("Saving preferences to file: %s", PREFERENCES_FILE)
jsonStr = json.dumps(Preferences.Instance.__dict__, sort_keys=True, indent=4)
file = open(PREFERENCES_FILE, 'w')
file.write(jsonStr)
file.close()
log.info("Preferences saved")