check ConfigPIN default
[vuplus_dvbapp] / lib / python / Components / config.py
index 10f112c..7ab7814 100644 (file)
@@ -26,6 +26,7 @@ import copy
 #
 class ConfigElement(object):
        def __init__(self):
+
                object.__init__(self)
                self.saved_value = None
                self.save_disabled = False
@@ -73,6 +74,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
@@ -148,7 +159,7 @@ class ConfigSelection(ConfigElement):
                self.changed()
 
        def tostring(self, val):
-               return (val, ','.join(self.choices))
+               return val
 
        def getValue(self):
                return self._value
@@ -428,6 +439,7 @@ class ConfigInteger(ConfigSequence):
 
 class ConfigPIN(ConfigSequence):
        def __init__(self, default, len = 4, censor = ""):
+               assert isinstance(default, int), "ConfigPIN default must be an integer"
                ConfigSequence.__init__(self, seperator = ":", limits = [(0, (10**len)-1)], censor_char = censor, default = [default])
 
 class ConfigFloat(ConfigSequence):
@@ -561,7 +573,7 @@ class ConfigSatlist(ConfigSelection):
        orbital_position = property(getOrbitalPosition)
 
 # nothing.
-class ConfigDummy(ConfigSelection):
+class ConfigNothing(ConfigSelection):
        def __init__(self):
                ConfigSelection.__init__(self, choices = [""])
 
@@ -621,8 +633,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()
@@ -687,6 +699,7 @@ class ConfigSubsection(object):
        def __setattr__(self, name, value):
                if name == "saved_value":
                        return self.setSavedValue(value)
+               assert isinstance(value, ConfigSubsection) or isinstance(value, ConfigElement) or isinstance(value, ConfigSubList) or isinstance(value, ConfigSubDict), "ConfigSubsections can only store ConfigSubsections, ConfigSubLists, ConfigSubDicts or ConfigElements"
                self.content.items[name] = value
                if name in self.content.stored_values:
                        #print "ok, now we have a new item,", name, "and have the following value for it:", self.content.stored_values[name]
@@ -701,6 +714,9 @@ class ConfigSubsection(object):
                for (key, val) in self.content.items.items():
                        if val.saved_value is not None:
                                res[key] = val.saved_value
+                       elif key in res:
+                               del res[key]
+                               
                return res
 
        def setSavedValue(self, values):