X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/04a6ffad0d1bd64cda7270ba0fcad74c33a20a51..df21108d272341745a001f781a3b8bd628f4ace6:/lib/python/Components/config.py diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 9400565d..f0652143 100644 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -48,7 +48,18 @@ class configFile: fileHandle.write(wstr) - fileHandle.close() + fileHandle.close() + +def currentConfigSelectionElement(element): + return element.vals[element.value][0] + +def getConfigSelectionElement(element, value): + count = 0 + for x in element.vals: + if x[0] == value: + return count + count += 1 + return -1 class configSelection: def __init__(self, parent): @@ -78,10 +89,13 @@ class configSelection: def __call__(self, selected): #needed by configlist self.checkValues() - print "[config.py] orgstring: ", self.parent.vals[self.parent.value] - print "[config.py] translation: ", _(self.parent.vals[self.parent.value]) - return ("text", _(self.parent.vals[self.parent.value])) - + if isinstance(self.parent.vals[self.parent.value], str): + returnValue = _(self.parent.vals[self.parent.value]) + else: + returnValue = _(self.parent.vals[self.parent.value][1]) + + return ("text", returnValue) + class configDateTime: def __init__(self, parent): self.parent = parent @@ -167,6 +181,9 @@ class configSequenceArg: # configsequencearg.get("FLOAT", [(min,max),(min1,max1)]) => x.y with min <= x <= max and min1 <= y <= max1 if (type == "FLOAT"): return (("."), args, "") + + def getFloat(self, element): + return float(("%d.%0" + str(len(str(element.vals[1][1][1]))) + "d") % (element.value[0], element.value[1])) configsequencearg = configSequenceArg() @@ -419,7 +436,17 @@ class configElement: if control == ConfigSlider: return int(data) elif control == configSelection: - return int(data) + try: + return int(data) + except: + for x in data.split(":"): + if x[0] == "*": + count = 0 + for y in self.vals: + if y[0] == x[1:-1]: + return count + count += 1 + return self.defaultValue elif control == configDateTime: return int(data) elif control == configText: @@ -439,6 +466,20 @@ class configElement: if control == ConfigSlider: return str(data) elif control == configSelection: + if len(self.vals) < data + 1: + return "0" + if isinstance(self.vals[data], str): + return str(data) + else: + confList = [] + count = 0 + for x in self.vals: + if count == data: + confList.append("*" + str(x[0] + "*")) + else: + confList.append(x[0]) + count += 1 + return ":".join(confList) return str(data) elif control == configDateTime: return str(data) @@ -446,7 +487,6 @@ class configElement: return str(data.strip()) elif control == configSequence: - print data try: value = ((len(data) * ("%d" + self.vals[0]))[0:-1]) % tuple(data) except: @@ -486,13 +526,14 @@ class configElement: #is this right? activate settings after load/cancel and use default self.change() - def __init__(self, configPath, control, defaultValue, vals): + def __init__(self, configPath, control, defaultValue, vals, saveDefaults = True): self.configPath = configPath self.defaultValue = defaultValue self.controlType = control self.vals = vals self.notifierList = [ ] self.enabled = True + self.saveDefaults = saveDefaults self.loadData() def getConfigPath(self): @@ -507,7 +548,8 @@ class configElement: def reload(self): self.loadData() def save(self): - configfile.setKey(self.configPath, self.datatoFile(self.controlType,self.value)) + if self.defaultValue != self.value or self.saveDefaults == True: + configfile.setKey(self.configPath, self.datatoFile(self.controlType,self.value)) class configElement_nonSave(configElement): def __init__(self, configPath, control, defaultValue, vals):