config rewrite. some extensions still need to be updated.
[enigma2.git] / lib / python / Components / config.py
1 import time
2 from Tools.NumericalTextInput import NumericalTextInput
3 from Tools.Directories import resolveFilename, SCOPE_CONFIG
4
5
6 # ConfigElement, the base class of all ConfigElements.
7
8 # it stores:
9 #   value    the current value, usefully encoded.
10 #            usually a property which retrieves _value,
11 #            and maybe does some reformatting
12 #   _value   the value as it's going to be saved in the configfile,
13 #            though still in non-string form.
14 #            this is the object which is actually worked on.
15 #   default  the initial value. If _value is equal to default,
16 #            it will not be stored in the config file
17 #   saved_value is a text representation of _value, stored in the config file
18 #
19 # and has (at least) the following methods:
20 #   save()   stores _value into saved_value, 
21 #            (or stores 'None' if it should not be stored)
22 #   load()   loads _value from saved_value, or loads
23 #            the default if saved_value is 'None' (default)
24 #            or invalid.
25 #
26 class ConfigElement(object):
27         def __init__(self):
28                 object.__init__(self)
29                 self.saved_value = None
30                 self.save_disabled = False
31                 self.notifiers = []
32                 self.enabled = True
33
34         # you need to override this to do input validation
35         def setValue(self, value):
36                 self._value = value
37                 self.changed()
38
39         def getValue(self):
40                 return self._value
41         
42         value = property(getValue, setValue)
43
44         # you need to override this if self.value is not a string
45         def fromstring(self, value):
46                 return value
47
48         # you can overide this for fancy default handling
49         def load(self):
50                 if self.saved_value is None:
51                         self.value = self.default
52                 else:
53                         self.value = self.fromstring(self.saved_value)
54
55         def tostring(self, value):
56                 return str(value)
57
58         # you need to override this if str(self.value) doesn't work
59         def save(self):
60                 if self.save_disabled or self.value == self.default:
61                         self.saved_value = None
62                 else:
63                         self.saved_value = self.tostring(self.value)
64
65         def cancel(self):
66                 self.load()
67
68         def changed(self):
69                 for x in self.notifiers:
70                         x(self)
71                         
72         def addNotifier(self, notifier):
73                 assert callable(notifier), "notifiers must be callable"
74                 self.notifiers.append(notifier)
75
76         def disableSave(self):
77                 self.save_disabled = True
78
79         def __call__(self, selected):
80                 return self.getMulti(selected)
81
82         def helpWindow(self):
83                 return None
84
85 KEY_LEFT = 0
86 KEY_RIGHT = 1
87 KEY_OK = 2
88 KEY_DELETE = 3
89 KEY_TIMEOUT = 4
90 KEY_NUMBERS = range(12, 12+10)
91 KEY_0 = 12
92 KEY_9 = 12+9
93
94 def getKeyNumber(key):
95         assert key in KEY_NUMBERS
96         return key - KEY_0
97
98 #
99 # ConfigSelection is a "one of.."-type.
100 # it has the "choices", usually a list, which contains
101 # (id, desc)-tuples (or just only the ids, in case the id
102 # will be used as description)
103 #
104 # all ids MUST be plain strings.
105 #
106 class ConfigSelection(ConfigElement):
107         def __init__(self, choices, default = None):
108                 ConfigElement.__init__(self)
109                 self.choices = []
110                 self.description = {}
111                 
112                 if isinstance(choices, list):
113                         for x in choices:
114                                 if isinstance(x, tuple):
115                                         self.choices.append(x[0])
116                                         self.description[x[0]] = x[1]
117                                 else:
118                                         self.choices.append(x)
119                                         self.description[x] = x
120                 elif isinstance(choices, dict):
121                         for (key, val) in choices.items():
122                                 self.choices.append(key)
123                                 self.description[key] = val
124                 else:
125                         assert False, "ConfigSelection choices must be dict or list!"
126                 
127                 assert len(self.choices), "you can't have an empty configselection"
128
129                 if default is None:
130                         default = self.choices[0]
131
132                 assert default in self.choices, "default must be in choice list, but " + repr(default) + " is not!"
133                 for x in self.choices:
134                         assert isinstance(x, str), "ConfigSelection choices must be strings"
135                 
136                 self.value = self.default = default
137
138         def setValue(self, value):
139                 if value in self.choices:
140                         self._value = value
141                 else:
142                         self._value = self.default
143                 
144                 self.changed()
145
146         def tostring(self, val):
147                 return (val, ','.join(self.choices))
148
149         def getValue(self):
150                 return self._value
151
152         value = property(getValue, setValue)
153         
154         def getIndex(self):
155                 return self.choices.index(self.value)
156         
157         index = property(getIndex)
158
159         # GUI
160         def handleKey(self, key):
161                 nchoices = len(self.choices)
162                 i = self.choices.index(self.value)
163                 if key == KEY_LEFT:
164                         self.value = self.choices[(i + nchoices - 1) % nchoices]
165                 elif key == KEY_RIGHT:
166                         self.value = self.choices[(i + 1) % nchoices]
167                 elif key == KEY_TIMEOUT:
168                         self.timeout()
169                         return
170
171         def getMulti(self, selected):
172                 return ("text", self.description[self.value])
173
174         # HTML
175         def getHTML(self, id):
176                 res = ""
177                 for v in self.choices:
178                         if self.value == v:
179                                 checked = 'checked="checked" '
180                         else:
181                                 checked = ''
182                         res += '<input type="radio" name="' + id + '" ' + checked + 'value="' + v + '">' + self.description[v] + "</input></br>\n"
183                 return res;
184
185         def unsafeAssign(self, value):
186                 # setValue does check if value is in choices. This is safe enough.
187                 self.value = value
188
189 # a binary decision.
190 #
191 # several customized versions exist for different
192 # descriptions.
193 #
194 class ConfigBoolean(ConfigElement):
195         def __init__(self, default = False, descriptions = {False: "false", True: "true"}):
196                 ConfigElement.__init__(self)
197                 self.descriptions = descriptions
198                 self.value = self.default = default
199         def handleKey(self, key):
200                 if key in [KEY_LEFT, KEY_RIGHT]:
201                         self.value = not self.value
202
203         def getMulti(self, selected):
204                 return ("text", _(self.descriptions[self.value]))
205
206         def tostring(self, value):
207                 if not value:
208                         return "false"
209                 else:
210                         return "true"
211
212         def fromstring(self, val):
213                 if val == "true":
214                         return True
215                 else:
216                         return False
217
218         def getHTML(self, id):
219                 if self.value:
220                         checked = ' checked="checked"'
221                 else:
222                         checked = ''
223                 return '<input type="checkbox" name="' + id + '" value="1" ' + checked + " />"
224
225         # this is FLAWED. and must be fixed.
226         def unsafeAssign(self, value):
227                 if value == "1":
228                         self.value = True
229                 else:
230                         self.value = False
231
232 class ConfigYesNo(ConfigBoolean):
233         def __init__(self, default = False):
234                 ConfigBoolean.__init__(self, default = default, descriptions = {False: _("no"), True: _("yes")})
235
236 class ConfigOnOff(ConfigBoolean):
237         def __init__(self, default = False):
238                 ConfigBoolean.__init__(self, default = default, descriptions = {False: _("off"), True: _("on")})
239
240 class ConfigEnableDisable(ConfigBoolean):
241         def __init__(self, default = False):
242                 ConfigBoolean.__init__(self, default = default, descriptions = {False: _("disable"), True: _("enable")})
243
244 class ConfigDateTime(ConfigElement):
245         def __init__(self, default, formatstring, increment = 86400):
246                 ConfigElement.__init__(self)
247                 self.increment = increment
248                 self.formatstring = formatstring
249                 self.value = self.default = int(default)
250
251         def handleKey(self, key):
252                 if key == KEY_LEFT:
253                         self.value = self.value - self.increment
254                 if key == KEY_RIGHT:
255                         self.value = self.value + self.increment
256
257         def getMulti(self, selected):
258                 return ("text", time.strftime(self.formatstring, time.localtime(self.value)))
259
260         def fromstring(self, val):
261                 return int(val)
262
263 # *THE* mighty config element class
264 #
265 # allows you to store/edit a sequence of values.
266 # can be used for IP-addresses, dates, plain integers, ...
267 # several helper exist to ease this up a bit.
268 #
269 class ConfigSequence(ConfigElement):
270         def __init__(self, seperator, limits, censor_char = "", default = None):
271                 ConfigElement.__init__(self)
272                 assert isinstance(limits, list) and len(limits[0]) == 2, "limits must be [(min, max),...]-tuple-list"
273                 assert censor_char == "" or len(censor_char) == 1, "censor char must be a single char (or \"\")"
274                 #assert isinstance(default, list), "default must be a list"
275                 #assert isinstance(default[0], int), "list must contain numbers"
276                 #assert len(default) == len(limits), "length must match"
277
278                 self.marked_pos = 0
279                 self.seperator = seperator
280                 self.limits = limits
281                 self.censor_char = censor_char
282                 
283                 self.value = self.default = default
284
285         def validate(self):
286                 max_pos = 0
287                 num = 0
288                 for i in self._value:
289                         max_pos += len(str(self.limits[num][1]))
290
291                         while self._value[num] < self.limits[num][0]:
292                                 self.value[num] += 1
293
294                         while self._value[num] > self.limits[num][1]:
295                                 self._value[num] -= 1
296
297                         num += 1
298
299                 if self.marked_pos >= max_pos:
300                         self.marked_pos = max_pos - 1
301
302                 if self.marked_pos < 0:
303                         self.marked_pos = 0
304
305         def validatePos(self):
306                 if self.marked_pos < 0:
307                         self.marked_pos = 0
308                         
309                 total_len = sum([len(str(x[1])) for x in self.limits])
310
311                 if self.marked_pos >= total_len:
312                         self.marked_pos = total_len - 1
313
314         def handleKey(self, key):
315                 if key == KEY_LEFT:
316                         self.marked_pos -= 1
317                         self.validatePos()
318
319                 if key == KEY_RIGHT:
320                         self.marked_pos += 1
321                         self.validatePos()
322                 
323                 if key in KEY_NUMBERS:
324                         print "is number"
325                         block_len = []
326                         for x in self.limits:
327                                 block_len.append(len(str(x[1])))
328                         
329                         total_len = sum(block_len)
330
331                         pos = 0
332                         blocknumber = 0
333                         block_len_total = [0, ]
334                         for x in block_len:
335                                 pos += block_len[blocknumber]
336                                 block_len_total.append(pos)
337                                 if pos - 1 >= self.marked_pos:
338                                         pass
339                                 else:
340                                         blocknumber += 1
341
342                         number = getKeyNumber(key)
343                         
344                         # length of numberblock
345                         number_len = len(str(self.limits[blocknumber][1]))
346
347                         # position in the block
348                         posinblock = self.marked_pos - block_len_total[blocknumber]
349                         
350                         oldvalue = self._value[blocknumber]
351                         olddec = oldvalue % 10 ** (number_len - posinblock) - (oldvalue % 10 ** (number_len - posinblock - 1))
352                         newvalue = oldvalue - olddec + (10 ** (number_len - posinblock - 1) * number)
353                         
354                         self._value[blocknumber] = newvalue
355                         self.marked_pos += 1
356                 
357                         self.validate()
358                         self.changed()
359                         
360                         print "res:", self._value
361
362         def getMulti(self, selected):
363                 value = ""
364                 mPos = self.marked_pos
365                 num = 0;
366                 for i in self._value:
367                         if len(value):  #fixme no heading separator possible
368                                 value += self.seperator
369                                 if mPos >= len(value) - 1:
370                                         mPos += 1
371
372                         if self.censor_char == "":
373                                 value += ("%0" + str(len(str(self.limits[num][1]))) + "d") % i
374                         else:
375                                 value += (self.censorChar * len(str(self.limits[num][1])))
376                         num += 1
377
378                         # only mark cursor when we are selected
379                         # (this code is heavily ink optimized!)
380                 if self.enabled:
381                         return ("mtext"[1-selected:], value, [mPos])
382                 else:
383                         return ("text", value)
384
385         def tostring(self, val):
386                 return self.seperator.join([self.saveSingle(x) for x in val])
387         
388         def saveSingle(self, v):
389                 return str(v)
390
391         def fromstring(self, value):
392                 return [int(x) for x in self.saved_value.split(self.seperator)]
393
394 class ConfigIP(ConfigSequence):
395         def __init__(self, default):
396                 ConfigSequence.__init__(self, seperator = ".", limits = [(0,255),(0,255),(0,255),(0,255)], default = default)
397
398 class ConfigMAC(ConfigSequence):
399         def __init__(self, default):
400                 ConfigSequence.__init__(self, seperator = ":", limits = [(1,255),(1,255),(1,255),(1,255),(1,255),(1,255)], default = default)
401
402 class ConfigPosition(ConfigSequence):
403         def __init__(self, default, args):
404                 ConfigSequence.__init__(self, seperator = ",", limits = [(0,args[0]),(0,args[1]),(0,args[2]),(0,args[3])], default = default)
405
406 class ConfigClock(ConfigSequence):
407         def __init__(self, default):
408                 ConfigSequence.__init__(self, seperator = ":", limits = [(0,23),(0,59)], default = default)
409
410 class ConfigInteger(ConfigSequence):
411         def __init__(self, default, limits):
412                 ConfigSequence.__init__(self, seperator = ":", limits = [limits], default = default)
413         
414         # you need to override this to do input validation
415         def setValue(self, value):
416                 self._value = [value]
417                 self.changed()
418
419         def getValue(self):
420                 return self._value[0]
421         
422         value = property(getValue, setValue)
423
424         def fromstring(self, value):
425                 return int(value)
426
427         def tostring(self, value):
428                 return str(value)
429
430 class ConfigPIN(ConfigSequence):
431         def __init__(self, default, len = 4, censor = ""):
432                 ConfigSequence.__init__(self, seperator = ":", limits = [(0, (10**len)-1)], censor_char = censor, default = [default])
433
434 class ConfigFloat(ConfigSequence):
435         def __init__(self, default, limits):
436                 ConfigSequence.__init__(self, seperator = ".", limits = limits, default = default)
437
438         def getFloat(self):
439                 return float(self.value[1] / float(self.limits[1][1] + 1) + self.value[0])
440
441         float = property(getFloat)
442
443 # an editable text...
444 class ConfigText(ConfigElement, NumericalTextInput):
445         def __init__(self, default = "", fixed_size = True):
446                 ConfigElement.__init__(self)
447                 NumericalTextInput.__init__(self, nextFunc = self.nextFunc, handleTimeout = False)
448                 
449                 self.marked_pos = 0
450                 self.fixed_size = fixed_size
451
452                 self.value = self.default = default
453
454         def validateMarker(self):
455                 if self.marked_pos < 0:
456                         self.marked_pos = 0
457                 if self.marked_pos >= len(self.text):
458                         self.marked_pos = len(self.text) - 1
459
460         #def nextEntry(self):
461         #       self.vals[1](self.getConfigPath())
462
463         def handleKey(self, key):
464                 # this will no change anything on the value itself
465                 # so we can handle it here in gui element
466                 if key == KEY_DELETE:
467                         self.text = self.text[0:self.marked_pos] + self.text[self.marked_pos + 1:]
468                 elif key == KEY_LEFT:
469                         self.marked_pos -= 1
470                 elif key == KEY_RIGHT:
471                         self.marked_pos += 1
472                         if not self.fixed_size:
473                                 if self.marked_pos >= len(self.text):
474                                         self.text = self.text.ljust(len(self.text) + 1)
475                 elif key in KEY_NUMBERS:
476                         number = self.getKey(getKeyNumber(key))
477                         self.text = self.text[0:self.marked_pos] + str(number) + self.text[self.marked_pos + 1:]
478                 elif key == KEY_TIMEOUT:
479                         self.timeout()
480                         return
481
482                 self.validateMarker()
483                 self.changed()
484
485         def nextFunc(self):
486                 self.marked_pos += 1
487                 self.validateMarker()
488                 self.changed()
489
490         def getValue(self):
491                 return self.text.encode("utf-8")
492                 
493         def setValue(self, val):
494                 try:
495                         self.text = val.decode("utf-8")
496                 except UnicodeDecodeError:
497                         self.text = val
498                         print "Broken UTF8!"
499
500         value = property(getValue, setValue)
501         _value = property(getValue, setValue)
502
503         def getMulti(self, selected):
504                 return ("mtext"[1-selected:], self.value, [self.marked_pos])
505
506         def helpWindow(self):
507                 print "helpWindow for text!"
508
509                 from Screens.NumericalTextInputHelpDialog import NumericalTextInputHelpDialog
510                 return (NumericalTextInputHelpDialog,self)
511
512         def getHTML(self, id):
513                 return '<input type="text" name="' + id + '" value="' + self.value + '" /><br>\n'
514
515         def unsafeAssign(self, value):
516                 self.value = str(value)
517
518 # a slider.
519 class ConfigSlider(ConfigElement):
520         def __init__(self, default = 0, increment = 1, limits = (0, 100)):
521                 ConfigElement.__init__(self)
522                 self.value = self.default = default
523                 self.min = limits[0]
524                 self.max = limits[1]
525                 self.increment = increment
526
527         def checkValues(self):
528                 if self.value < self.min:
529                         self.value = self.min
530
531                 if self.value > self.max:
532                         self.value = self.max
533
534         def handleKey(self, key):
535                 if key == KEY_LEFT:
536                         self.value -= self.increment
537                 elif key == KEY_RIGHT:
538                         self.value += self.increment
539                 else:
540                         return
541
542                 self.checkValues()
543                 self.changed()
544
545         def getMulti(self, selected):
546                 self.checkValues()
547                 return ("slider", self.value, self.max)
548
549         def fromstring(self, value):
550                 return int(value)
551
552 # a satlist. in fact, it's a ConfigSelection.
553 class ConfigSatlist(ConfigSelection):
554         def __init__(self, list, default = None):
555                 if default is not None:
556                         default = str(default)
557                 if list == [ ]:
558                         list = [0, "N/A"]
559                 ConfigSelection.__init__(self, choices = [(str(orbpos), desc) for (orbpos, desc) in list], default = default)
560
561         def getOrbitalPosition(self):
562                 return int(self.value)
563         
564         orbital_position = property(getOrbitalPosition)
565
566 # nothing.
567 class ConfigDummy(ConfigSelection):
568         def __init__(self):
569                 ConfigSelection.__init__(self, choices = [""])
570
571 # until here, 'saved_value' always had to be a *string*.
572 # now, in ConfigSubsection, and only there, saved_value
573 # is a dict, essentially forming a tree.
574 #
575 # config.foo.bar=True
576 # config.foobar=False
577 #
578 # turns into:
579 # config.saved_value == {"foo": {"bar": "True"}, "foobar": "False"}
580 #
581
582
583 class ConfigSubsectionContent(object):
584         pass
585
586 # we store a backup of the loaded configuration
587 # data in self.stored_values, to be able to deploy
588 # them when a new config element will be added,
589 # so non-default values are instantly available
590
591 # A list, for example:
592 # config.dipswitches = ConfigSubList()
593 # config.dipswitches.append(ConfigYesNo())
594 # config.dipswitches.append(ConfigYesNo())
595 # config.dipswitches.append(ConfigYesNo())
596 class ConfigSubList(list, object):
597         def __init__(self):
598                 object.__init__(self)
599                 list.__init__(self)
600                 self.stored_values = {}
601
602         def save(self):
603                 for x in self:
604                         x.save()
605         
606         def load(self):
607                 for x in self:
608                         x.load()
609
610         def getSavedValue(self):
611                 res = {}
612                 for i in range(len(self)):
613                         sv = self[i].saved_value
614                         if sv is not None:
615                                 res[str(i)] = sv
616                 return res
617
618         def setSavedValue(self, values):
619                 self.stored_values = dict(values)
620                 for (key, val) in self.stored_values.items():
621                         if int(key) < len(self):
622                                 self[int(key)].saved_value = val
623
624         saved_value = property(getSavedValue, setSavedValue)
625         
626         def append(self, item):
627                 list.append(self, item)
628                 i = str(len(self))
629                 if i in self.stored_values:
630                         item.saved_value = self.stored_values[i]
631                         item.load()
632
633 # same as ConfigSubList, just as a dictionary.
634 # care must be taken that the 'key' has a proper
635 # str() method, because it will be used in the config
636 # file.
637 class ConfigSubDict(dict, object):
638         def __init__(self):
639                 object.__init__(self)
640                 dict.__init__(self)
641                 self.stored_values = {}
642
643         def save(self):
644                 for x in self.values():
645                         x.save()
646         
647         def load(self):
648                 for x in self.values():
649                         x.load()
650
651         def getSavedValue(self):
652                 res = {}
653                 for (key, val) in self.items():
654                         if val.saved_value is not None:
655                                 res[str(key)] = val.saved_value
656                 return res
657
658         def setSavedValue(self, values):
659                 self.stored_values = dict(values)
660                 for (key, val) in self.items():
661                         if str(key) in self.stored_values:
662                                 val = self.stored_values[str(key)]
663
664         saved_value = property(getSavedValue, setSavedValue)
665
666         def __setitem__(self, key, item):
667                 dict.__setitem__(self, key, item)
668                 if str(key) in self.stored_values:
669                         item.saved_value = self.stored_values[str(key)]
670                         item.load()
671
672 # Like the classes above, just with a more "native"
673 # syntax.
674 #
675 # some evil stuff must be done to allow instant
676 # loading of added elements. this is why this class
677 # is so complex.
678 #
679 # we need the 'content' because we overwrite 
680 # __setattr__.
681 # If you don't understand this, try adding
682 # __setattr__ to a usual exisiting class and you will.
683 class ConfigSubsection(object):
684         def __init__(self):
685                 object.__init__(self)
686                 self.__dict__["content"] = ConfigSubsectionContent()
687                 self.content.items = { }
688                 self.content.stored_values = { }
689         
690         def __setattr__(self, name, value):
691                 if name == "saved_value":
692                         return self.setSavedValue(value)
693                 self.content.items[name] = value
694                 if name in self.content.stored_values:
695                         #print "ok, now we have a new item,", name, "and have the following value for it:", self.content.stored_values[name]
696                         value.saved_value = self.content.stored_values[name]
697                         value.load()
698
699         def __getattr__(self, name):
700                 return self.content.items[name]
701
702         def getSavedValue(self):
703                 res = self.content.stored_values
704                 for (key, val) in self.content.items.items():
705                         if val.saved_value is not None:
706                                 res[key] = val.saved_value
707                 return res
708
709         def setSavedValue(self, values):
710                 values = dict(values)
711                 
712                 self.content.stored_values = values
713                 
714                 for (key, val) in self.content.items.items():
715                         if key in values:
716                                 val.setSavedValue(values[key])
717
718         saved_value = property(getSavedValue, setSavedValue)
719
720         def save(self):
721                 for x in self.content.items.values():
722                         x.save()
723
724         def load(self):
725                 for x in self.content.items.values():
726                         x.load()
727
728 # the root config object, which also can "pickle" (=serialize)
729 # down the whole config tree.
730 #
731 # we try to keep non-existing config entries, to apply them whenever
732 # a new config entry is added to a subsection
733 # also, non-existing config entries will be saved, so they won't be
734 # lost when a config entry disappears.
735 class Config(ConfigSubsection):
736         def __init__(self):
737                 ConfigSubsection.__init__(self)
738
739         def pickle_this(self, prefix, topickle, result):
740                 for (key, val) in topickle.items():
741                         name = prefix + "." + key
742                         
743                         if isinstance(val, dict):
744                                 self.pickle_this(name, val, result)
745                         elif isinstance(val, tuple):
746                                 result.append(name + "=" + val[0]) # + " ; " + val[1])
747                         else:
748                                 result.append(name + "=" + val)
749
750         def pickle(self):
751                 result = [ ]
752                 self.pickle_this("config", self.saved_value, result)
753                 return '\n'.join(result) + "\n"
754
755         def unpickle(self, lines):
756                 tree = { }
757                 for l in lines:
758                         if not len(l) or l[0] == '#':
759                                 continue
760                         
761                         n = l.find('=')
762                         val = l[n+1:].strip()
763
764                         names = l[:n].split('.')
765 #                       if val.find(' ') != -1:
766 #                               val = val[:val.find(' ')]
767
768                         base = tree
769                         
770                         for n in names[:-1]:
771                                 base = base.setdefault(n, {})
772                         
773                         base[names[-1]] = val
774
775                 # we inherit from ConfigSubsection, so ...
776                 #object.__setattr__(self, "saved_value", tree["config"])
777                 self.setSavedValue(tree["config"])
778
779         def saveToFile(self, filename):
780                 f = open(filename, "w")
781                 f.write(self.pickle())
782                 f.close()
783
784         def loadFromFile(self, filename):
785                 f = open(filename, "r")
786                 self.unpickle(f.readlines())
787                 f.close()
788
789 config = Config()
790 config.misc = ConfigSubsection()
791
792 class ConfigFile:
793         CONFIG_FILE = resolveFilename(SCOPE_CONFIG, "config2")
794
795         def load(self):
796                 try:
797                         config.loadFromFile(self.CONFIG_FILE)
798                 except IOError, e:
799                         print "unable to load config (%s), assuming defaults..." % str(e)
800         
801         def save(self):
802                 config.save()
803                 config.saveToFile(self.CONFIG_FILE)
804         
805         def getResolvedKey(self, key):
806                 return None # FIXME
807
808 def NoSave(element):
809         element.disableSave()
810         return element
811
812 configfile = ConfigFile()
813
814 configfile.load()
815
816 def getConfigListEntry(desc, config):
817         return (desc, config)
818
819 #def _(x):
820 #       return x
821 #
822 #config.bla = ConfigSubsection()
823 #config.bla.test = ConfigYesNo()
824 #config.nim = ConfigSubList()
825 #config.nim.append(ConfigSubsection())
826 #config.nim[0].bla = ConfigYesNo()
827 #config.nim.append(ConfigSubsection())
828 #config.nim[1].bla = ConfigYesNo()
829 #config.nim[1].blub = ConfigYesNo()
830 #config.arg = ConfigSubDict()
831 #config.arg["Hello"] = ConfigYesNo()
832 #
833 #config.arg["Hello"].handleKey(KEY_RIGHT)
834 #config.arg["Hello"].handleKey(KEY_RIGHT)
835 #
836 ##config.saved_value
837 #
838 ##configfile.save()
839 #config.save()
840 #print config.pickle()