fix off-by-one bug in ConfigSubList
[enigma2.git] / lib / python / Components / config.py
index b5a0bbbdba8049a1a93c7e9996827f95b6fb2b44..07186157768d97b9450cac0c67ee01a956b2e80f 100644 (file)
@@ -1,6 +1,7 @@
 import time
 from Tools.NumericalTextInput import NumericalTextInput
 from Tools.Directories import resolveFilename, SCOPE_CONFIG
+import copy
 
 
 # ConfigElement, the base class of all ConfigElements.
@@ -72,6 +73,16 @@ class ConfigElement(object):
        def addNotifier(self, notifier):
                assert callable(notifier), "notifiers must be callable"
                self.notifiers.append(notifier)
+               
+               # CHECKME:
+               # do we want to call the notifier
+               #  - at all when adding it? (yes)
+               #  - when the default is active? (yes)
+               #  - when no value *yet* has been set,
+               #    because no config has ever been read (currently yes)
+               #    (though that's not so easy to detect.
+               #     the entry could just be new.)
+               notifier(self)
 
        def disableSave(self):
                self.save_disabled = True
@@ -124,7 +135,10 @@ class ConfigSelection(ConfigElement):
                else:
                        assert False, "ConfigSelection choices must be dict or list!"
                
-               assert len(self.choices), "you can't have an empty configselection"
+               #assert len(self.choices), "you can't have an empty configselection"
+               if len(self.choices) == 0:
+                       self.choices = [""]
+                       self.description[""] = ""
 
                if default is None:
                        default = self.choices[0]
@@ -164,9 +178,6 @@ class ConfigSelection(ConfigElement):
                        self.value = self.choices[(i + nchoices - 1) % nchoices]
                elif key == KEY_RIGHT:
                        self.value = self.choices[(i + 1) % nchoices]
-               elif key == KEY_TIMEOUT:
-                       self.timeout()
-                       return
 
        def getMulti(self, selected):
                return ("text", self.description[self.value])
@@ -280,7 +291,8 @@ class ConfigSequence(ConfigElement):
                self.limits = limits
                self.censor_char = censor_char
                
-               self.value = self.default = default
+               self.default = default
+               self.value = copy.copy(default)
 
        def validate(self):
                max_pos = 0
@@ -321,7 +333,6 @@ class ConfigSequence(ConfigElement):
                        self.validatePos()
                
                if key in KEY_NUMBERS:
-                       print "is number"
                        block_len = []
                        for x in self.limits:
                                block_len.append(len(str(x[1])))
@@ -357,8 +368,6 @@ class ConfigSequence(ConfigElement):
                        self.validate()
                        self.changed()
                        
-                       print "res:", self._value
-
        def getMulti(self, selected):
                value = ""
                mPos = self.marked_pos
@@ -504,8 +513,6 @@ class ConfigText(ConfigElement, NumericalTextInput):
                return ("mtext"[1-selected:], self.value, [self.marked_pos])
 
        def helpWindow(self):
-               print "helpWindow for text!"
-
                from Screens.NumericalTextInputHelpDialog import NumericalTextInputHelpDialog
                return (NumericalTextInputHelpDialog,self)
 
@@ -554,11 +561,11 @@ class ConfigSatlist(ConfigSelection):
        def __init__(self, list, default = None):
                if default is not None:
                        default = str(default)
-               if list == [ ]:
-                       list = [0, "N/A"]
                ConfigSelection.__init__(self, choices = [(str(orbpos), desc) for (orbpos, desc) in list], default = default)
 
        def getOrbitalPosition(self):
+               if self.value == "":
+                       return None
                return int(self.value)
        
        orbital_position = property(getOrbitalPosition)
@@ -624,8 +631,8 @@ class ConfigSubList(list, object):
        saved_value = property(getSavedValue, setSavedValue)
        
        def append(self, item):
-               list.append(self, item)
                i = str(len(self))
+               list.append(self, item)
                if i in self.stored_values:
                        item.saved_value = self.stored_values[i]
                        item.load()