4 self.configElements = { }
6 self.file = open("config")
8 print "cannot open config file"
12 line = self.file.readline()
16 if line.startswith("#"): #skip comments
22 def addElement(self, line):
25 self.configElements[line[:x]] = line[x + 1:]
27 def getKey(self, key):
28 return self.configElements[key]
30 def setKey(self, key, value):
32 self.configElements[key] = value
35 if self.changed == 0: #no changes, so no write to disk needed
38 fileHandle = open("config", "w")
40 for x in self.configElements:
41 wstr = x + "=" + self.configElements[x]
43 if wstr[len(wstr) - 1] != '\n':
46 fileHandle.write(wstr)
51 def __init__(self, parent):
54 def checkValues(self):
55 if self.parent.value < 0:
58 if(self.parent.value >= (len(self.parent.vals) - 1)):
59 self.parent.value = len(self.parent.vals) - 1
67 def handleKey(self, key):
68 if key == config.prevElement:
69 self.parent.value = self.parent.value - 1
70 if key == config.nextElement:
71 self.parent.value = self.parent.value + 1
77 def __call__(self): #needed by configlist
79 return ("text", self.parent.vals[self.parent.value])
82 def __init__(self, parent):
86 def checkValues(self):
87 maxPos = len(self.parent.value) * self.parent.vals[1]
90 if self.markedPos >= maxPos:
91 self.markedPos = maxPos - 1
92 if self.markedPos < 0:
101 def handleKey(self, key):
102 #this will no change anything on the value itself
103 #so we can handle it here in gui element
104 if key == config.prevElement:
106 if key == config.nextElement:
114 #FIXME: dont call when press left/right
117 def __call__(self): #needed by configlist
120 mPos = self.markedPos
122 for i in self.parent.value:
123 if value != "": #fixme no heading separator possible
124 value += self.parent.vals[0]
125 if mPos >= len(value) - 1:
128 diff = self.parent.vals[1] - len(str(i))
130 #how about alignment?
131 value += " "[0:diff] #how is this done correct?
134 value = value[0:mPos] + "_" + value[mPos + 1:]
135 return ("text", value)
138 def __init__(self, obj):
146 self.choseElement = 0
151 configfile = configFile()
154 def __init__(self, parent):
163 def checkValues(self):
164 if self.parent.value < 0:
165 self.parent.value = 0
167 if self.parent.value > 10:
168 self.parent.value = 10
170 def handleKey(self, key):
171 if key == config.prevElement:
172 self.parent.value = self.parent.value - 1
173 if key == config.nextElement:
174 self.parent.value = self.parent.value + 1
179 def __call__(self): #needed by configlist
181 return ("slider", self.parent.value * 10)
183 class ConfigSubsection:
188 def datafromFile(self, control, data):
189 if control == ConfigSlider:
191 elif control == configBoolean:
193 elif control == configSequence:
195 part = data.split(self.vals[0])
202 def datatoFile(self, control, data):
203 if control == ConfigSlider:
205 elif control == configBoolean:
207 elif control == configSequence:
211 value += self.vals[0]
219 value = self.datafromFile(self.controlType, configfile.getKey(self.configPath))
224 print "value not found - using default"
225 self.value = self.defaultValue
226 self.save() #add missing value to dict
230 def __init__(self, configPath, control, defaultValue, vals):
231 self.configPath = configPath
232 self.defaultValue = defaultValue
233 self.controlType = control
235 self.notifierList = [ ]
237 def addNotifier(self, notifier):
238 self.notifierList.append(notifier);
241 for notifier in self.notifierList:
246 configfile.setKey(self.configPath, self.datatoFile(self.controlType,self.value))