-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConfiguration.py
69 lines (68 loc) · 2.09 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import re
import time
import json
from utils import *
class Configuration:
def __init__(self):
self.data = {}
self.displays = {}
self.controllers = {}
self.setDefault()
self.read()
def set(self, key, value):
self.data[key] = value
def get(self, key):
val = None
if key in self.data:
val = self.data[key]
return val
def unset(self, key):
if key in self.data:
del self.data[key]
def save(self):
f = open(appdataDir() + 'settings.ini', 'w')
json.dump({'settings':self.data, 'displays':self.displays}, f)
f.close()
def saveDisplay(self, id, settings):
self.displays[id] = settings
def getDisplay(self, id):
if id in self.displays:
return self.displays[id]
else:
return {}
def setDefault(self):
self.data['layerHeight'] = 0.1
self.data['exposureTime'] = 500
self.data['startingExposureTime'] = 800
self.data['startingLayers'] = 3
self.data['postPause'] = 0
self.data['retractDistance'] = 500
self.data['retractSpeed'] = 200
self.data['returnSpeed'] = 500
self.data['prePause'] = 0
def read(self):
try:
f = open(appdataDir() + 'settings.ini', 'r')
jsonData = json.load(f)
self.data = jsonData['settings']
self.displays = jsonData['displays']
except:
print("can't load file")
def monitorInfo(self, hash):
id = hash[0:hash.find(':')]
dim = re.split(',', hash[hash.find(':')+1:])
if len(dim) == 4:
return {'id': id, 'x':dim[0], 'y':dim[1], 'width':dim[2], 'height':dim[3]}
else:
return None
def monitorHash(self, id, x, y, w, h):
return str(id) + ':' + str(x) + ',' + str(y) + ',' + str(w) + ',' + str(h)
def reset(self):
self.data = {}
self.displays = {}
self.controllers = {}
self.save()
self.setDefault()
if __name__ == "__main__":
c = Configuration()
c.save()