+ def pickle_this(self, prefix, topickle, result):
+ for (key, val) in topickle.items():
+ name = prefix + "." + key
+
+ if isinstance(val, dict):
+ self.pickle_this(name, val, result)
+ elif isinstance(val, tuple):
+ result.append(name + "=" + val[0]) # + " ; " + val[1])
+ else:
+ result.append(name + "=" + val)
+
+ def pickle(self):
+ result = [ ]
+ self.pickle_this("config", self.saved_value, result)
+ return '\n'.join(result) + "\n"
+
+ def unpickle(self, lines):
+ tree = { }
+ for l in lines:
+ if not len(l) or l[0] == '#':
+ continue
+
+ n = l.find('=')
+ val = l[n+1:].strip()
+
+ names = l[:n].split('.')
+# if val.find(' ') != -1:
+# val = val[:val.find(' ')]
+
+ base = tree
+
+ for n in names[:-1]:
+ base = base.setdefault(n, {})
+
+ base[names[-1]] = val
+
+ # we inherit from ConfigSubsection, so ...
+ #object.__setattr__(self, "saved_value", tree["config"])
+ self.setSavedValue(tree["config"])
+
+ def saveToFile(self, filename):
+ f = open(filename, "w")
+ f.write(self.pickle())
+ f.close()
+
+ def loadFromFile(self, filename):
+ f = open(filename, "r")
+ self.unpickle(f.readlines())
+ f.close()
+
+config = Config()
+config.misc = ConfigSubsection()
+
+class ConfigFile:
+ CONFIG_FILE = resolveFilename(SCOPE_CONFIG, "config2")
+
+ def load(self):
+ try:
+ config.loadFromFile(self.CONFIG_FILE)
+ except IOError, e:
+ print "unable to load config (%s), assuming defaults..." % str(e)
+
+ def save(self):
+ config.save()
+ config.saveToFile(self.CONFIG_FILE)
+
+ def getResolvedKey(self, key):
+ return None # FIXME
+
+def NoSave(element):
+ element.disableSave()
+ return element
+
+configfile = ConfigFile()
+
+configfile.load()
+
+def getConfigListEntry(desc, config):
+ return (desc, config)
+
+#def _(x):
+# return x
+#
+#config.bla = ConfigSubsection()
+#config.bla.test = ConfigYesNo()
+#config.nim = ConfigSubList()
+#config.nim.append(ConfigSubsection())
+#config.nim[0].bla = ConfigYesNo()
+#config.nim.append(ConfigSubsection())
+#config.nim[1].bla = ConfigYesNo()
+#config.nim[1].blub = ConfigYesNo()
+#config.arg = ConfigSubDict()
+#config.arg["Hello"] = ConfigYesNo()
+#
+#config.arg["Hello"].handleKey(KEY_RIGHT)
+#config.arg["Hello"].handleKey(KEY_RIGHT)
+#
+##config.saved_value
+#
+##configfile.save()
+#config.save()
+#print config.pickle()