+ def save(self):
+ self.parent.save()
+
+ def checkValues(self):
+ if self.parent.value < 0:
+ self.parent.value = 0
+
+ if self.parent.value > 10:
+ self.parent.value = 10
+
+ def handleKey(self, key):
+ if key == config.key["prevElement"]:
+ self.parent.value = self.parent.value - 1
+ if key == config.key["nextElement"]:
+ self.parent.value = self.parent.value + 1
+
+ self.checkValues()
+ self.parent.change()
+
+ def __call__(self, selected): #needed by configlist
+ self.checkValues()
+ return ("slider", self.parent.value * 10)
+
+class ConfigSubsection:
+ def __init__(self):
+ pass
+
+class configElement:
+
+ def getIndexbyEntry(self, data):
+ cnt = 0;
+ tcnt = -1; #for defaultval
+ for x in self.vals:
+ if int(x[1]) == int(data):
+ return cnt
+ if int(x[1]) == int(self.defaultValue):
+ tcnt = cnt
+ cnt += 1
+ if tcnt != -1:
+ return tcnt
+ return 0 #prevent bigger then array
+
+ def datafromFile(self, control, data):
+ if control == ConfigSlider:
+ return int(data)
+ elif control == configSelection:
+ return int(data)
+ elif control == configDateTime:
+ return int(data)
+ elif control == configText:
+ return str(data)
+ elif control == configSequence:
+ list = [ ]
+ part = data.split(self.vals[0])
+ for x in part:
+ list.append(int(x))
+ return list
+ elif control == configSatlist:
+ return self.getIndexbyEntry(data)
+ else:
+ return ""
+
+ def datatoFile(self, control, data):
+ if control == ConfigSlider:
+ return str(data)
+ elif control == configSelection:
+ return str(data)
+ elif control == configDateTime:
+ return str(data)
+ elif control == configText:
+ return str(data.strip())
+
+ elif control == configSequence:
+ print data
+ try:
+ value = ((len(data) * ("%d" + self.vals[0]))[0:-1]) % tuple(data)
+ except:
+ value = str(data)
+# just in case you don't understand the above, here an equivalent:
+# value = ""
+# for i in data:
+# if value !="":
+# value += self.vals[0]
+# value += str(i)
+ return value
+ elif control == configSatlist:
+ return str(self.vals[self.value][1]);
+ else:
+ return ""
+
+ def loadData(self):
+ #print "load:" + self.configPath
+ try:
+ value = self.datafromFile(self.controlType, configfile.getKey(self.configPath))
+ except:
+ value = ""
+
+ if value == "":
+ #print "value not found - using default"
+
+ if self.controlType == configSatlist:
+ self.value = self.getIndexbyEntry(self.defaultValue)
+ else:
+ self.value = self.defaultValue
+
+ self.save() #add missing value to dict
+ else:
+ #print "set val:" + str(value)
+ self.value = value
+
+ #is this right? activate settings after load/cancel and use default
+ self.change()
+
+ def __init__(self, configPath, control, defaultValue, vals):
+ self.configPath = configPath
+ self.defaultValue = defaultValue
+ self.controlType = control
+ self.vals = vals
+ self.notifierList = [ ]
+ self.enabled = True
+ self.loadData()
+
+ def getConfigPath(self):
+ return self.configPath
+
+ def addNotifier(self, notifier):
+ self.notifierList.append(notifier);
+ notifier(self);
+ def change(self):
+ for notifier in self.notifierList:
+ notifier(self)
+ def reload(self):
+ self.loadData()
+ def save(self):
+ configfile.setKey(self.configPath, self.datatoFile(self.controlType,self.value))
+
+class configElement_nonSave(configElement):
+ def __init__(self, configPath, control, defaultValue, vals):
+ configElement.__init__(self, configPath, control, defaultValue, vals)
+
+ def save(self):
+ pass
+
+def getConfigListEntry(description, element):
+ b = element
+ item = b.controlType(b)
+ return ((description, item))