fix off-by-one bug in ConfigSubList
[enigma2.git] / lib / python / Components / config.py
index 4da004e1bfa37c0862014ec66a3e65fde1bbe224..07186157768d97b9450cac0c67ee01a956b2e80f 100644 (file)
@@ -73,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
@@ -125,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]
@@ -165,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])
@@ -551,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)
@@ -621,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()