fix boundaries of configSequence input
[enigma2.git] / lib / python / Components / config.py
index bd5656c96fc3ef30defcfcf5d346d5a3c8485a65..5a92f076834f8439ab97d241f224ace4f0ae7ed8 100644 (file)
@@ -37,7 +37,9 @@ class configFile:
                        
                fileHandle = open("config", "w")
                
-               for x in self.configElements:
+               keys = self.configElements.keys()
+               keys.sort()
+               for x in keys:
                        wstr = x + "=" + self.configElements[x]
                        
                        if wstr[len(wstr) - 1] != '\n':
@@ -89,9 +91,6 @@ class configSatlist:
                if(self.parent.value >= (len(self.parent.vals) - 1)):
                        self.parent.value = len(self.parent.vals) - 1
                        
-               print "value" + str(self.parent.value)
-               print "name " + self.parent.vals[self.parent.value][0]
-
        def cancel(self):
                self.parent.reload()
 
@@ -119,8 +118,7 @@ class configSequence:
                self.markedPos = 0
                
        def checkValues(self):
-               maxPos = len(self.parent.value) * self.parent.vals[1] 
-               print maxPos
+               maxPos = len(self.parent.value) * len(self.parent.vals[1]) + len(self.parent.value)
                        
                if self.markedPos >= maxPos:
                        self.markedPos = maxPos - 1
@@ -249,6 +247,20 @@ class ConfigSubsection:
                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);
@@ -260,6 +272,8 @@ class configElement:
                        for x in part:
                                list.append(int(x))
                        return list
+               elif control == configSatlist:
+                       return self.getIndexbyEntry(data)
                else: 
                        return ""       
 
@@ -277,6 +291,8 @@ class configElement:
 #                                      value += self.vals[0]
 #                              value += str(i)
                        return value
+               elif control == configSatlist:
+                       return str(self.vals[self.value][1]);
                else: 
                        return ""       
 
@@ -288,10 +304,18 @@ class configElement:
 
                if value == "":
                        print "value not found - using default"
-                       self.value = self.defaultValue
+
+                       if self.controlType == configSatlist:
+                               self.value = self.getIndexbyEntry(self.defaultValue)
+                       else:   
+                               self.value = self.defaultValue
+
                        self.save()             #add missing value to dict
                else:
                        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
@@ -311,3 +335,15 @@ class configElement:
                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))
\ No newline at end of file