some changes to the configSelection stuff
[enigma2.git] / lib / python / Components / config.py
index 1ce67f8e73000a5551fa18acf6dffed608bd77db..25684fc186dcda69b112869e5ffd145f6db476d2 100644 (file)
@@ -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,8 +89,13 @@ class configSelection:
 
        def __call__(self, selected):                   #needed by configlist
                self.checkValues()
-               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
@@ -148,7 +164,7 @@ class configSequenceArg:
        def get(self, type, args = ()):
                # configsequencearg.get ("IP")
                if (type == "IP"):
-                       return (("."), [(1,255),(0,255),(0,255),(0,255)], "")
+                       return (("."), [(0,255),(0,255),(0,255),(0,255)], "")
                # configsequencearg.get ("MAC")
                if (type == "MAC"):
                        return ((":"), [(1,255),(1,255),(1,255),(1,255),(1,255),(1,255)], "")
@@ -266,9 +282,9 @@ class configSequence:
                        #if diff > 0:
                                ## if this helps?!
                                #value += " " * diff
-                       print (("%0" + str(len(str(self.valueBounds[num][1]))) + "d") % int(i))
+                       print (("%0" + str(len(str(self.valueBounds[num][1]))) + "d") % i)
                        if (self.censorChar == ""):
-                               value += ("%0" + str(len(str(self.valueBounds[num][1]))) + "d") % int(i)
+                               value += ("%0" + str(len(str(self.valueBounds[num][1]))) + "d") % i
                        else:
                                value += (self.censorChar * len(str(self.valueBounds[num][1])))
                        num += 1
@@ -417,7 +433,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:
@@ -437,6 +463,18 @@ class configElement:
                if control == ConfigSlider:
                        return str(data)
                elif control == configSelection:
+                       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)