X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/301bab11f8453a6899153b7be338a352803b22cb..d93fedc90787f2888f91d3b42dd35868e030cdbe:/lib/python/Components/config.py diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 15119617..015ac067 100644 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -1,31 +1,58 @@ -# temp stuff :) +class configFile: + def __init__(self): + pass + + def openFile(self): + try: + self.file = open("config") + except IOError: + self.file = "" + + def getKey(self, key, dataType): + self.openFile() #good idea? (open every time we need it?) else we have to seek + while 1: + line = self.file.readline() + if line == "": + break + if line.startswith(key): + x = line.find("=") + if x > -1: + self.file.close() + return dataType(line[x + 1:]) + + self.file.close() + return "" + class configBoolean: def __init__(self, parent): self.parent = parent - self.val = parent.value - self.vals = parent.vals - + + def checkValues(self): + if self.parent.value < 0: + self.parent.value = 0 + + if(self.parent.value >= (len(self.parent.vals) - 1)): + self.parent.value = len(self.parent.vals) - 1 + + def cancel(self): + self.parent.reload() + + def save(self): + print "save bool" + def handleKey(self, key): if key == 1: - self.val = self.val - 1 + self.parent.value = self.parent.value - 1 if key == 2: - self.val = self.val + 1 - - if self.val < 0: - self.val = 0 - -# if self.val > 1: -# self.val = 1 - + self.parent.value = self.parent.value + 1 + + self.checkValues() + + self.parent.change() + def __call__(self): #needed by configlist - - print len(self.vals) - print self.val - - if(self.val > (len(self.vals) - 1)): - self.val = len(self.vals) - 1 - - return ("text",self.vals[self.val]) + self.checkValues() + return ("text", self.parent.vals[self.parent.value]) class configValue: def __init__(self, obj): @@ -34,51 +61,98 @@ class configValue: def __str__(self): return self.obj -def configEntry(obj): - # das hier ist ein zugriff auf die registry... - if obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN": - return ("SDTV green flashes", configBoolean(obj)) - elif obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN": - return ("HDTV reen flashes", configBoolean(obj)) - else: - return ("invalid", "") - class Config: def __init__(self): pass + + def saveLine(self, file, element): + #FIXME can handle INTs only + line = element.configPath + "=" + str(element.value) + "\n" + file.write(line) + + def save(self): + fileHandle = open("config", "w") + + for groupElement in self.__dict__.items(): + for element in groupElement[1].__dict__.items(): + self.saveLine(fileHandle, element[1]) + + fileHandle.close() + + while 1: + pass config = Config(); +configfile = configFile() class ConfigSlider: def __init__(self, parent): self.parent = parent - self.val = parent.value + + def cancel(self): + self.parent.reload() + + def save(self): + print "slider - 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 == 1: - self.val = self.val - 1 + self.parent.value = self.parent.value - 1 if key == 2: - self.val = self.val + 1 - - if self.val < 0: - self.val = 0 + self.parent.value = self.parent.value + 1 + + self.checkValues() + self.parent.change() - if self.val > 10: - self.val = 10 def __call__(self): #needed by configlist - return ("slider", self.val * 10) + self.checkValues() + return ("slider", self.parent.value * 10) class ConfigSubsection: def __init__(self): pass class configElement: + def dataType(self, control): + if control == ConfigSlider: + return int; + elif control == configBoolean: + return int; + else: + return "" + + def loadData(self): + try: + value = configfile.getKey(self.configPath, self.dataType(self.controlType)) + except: + value = "" + + if value == "": + print "value not found - using default" + self.value = self.defaultValue + else: + self.value = value + print "value ok" + def __init__(self, configPath, control, defaultValue, vals): self.configPath = configPath -# self.value = 0 #read from registry else use default - self.value = defaultValue #read from registry else use default + self.defaultValue = defaultValue self.controlType = control self.vals = vals self.notifierList = [ ] + self.loadData() 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()