From 6d7d1767d32a95d94c817129be77147885e850fa Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 15:20:10 +0100 Subject: fix possible crash --- lib/python/Components/config.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index eaf07180..f72a4c4e 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -198,12 +198,15 @@ class choicesList(object): # XXX: we might want a better name for this self.choices[value] = orig def default(self): + choices = self.choices + if not choices: + return "" if self.type is choicesList.LIST_TYPE_LIST: - default = self.choices[0] + default = choices[0] if isinstance(default, tuple): default = default[0] else: - default = self.choices.keys()[0] + default = choices.keys()[0] return default class descriptionList(choicesList): # XXX: we might want a better name for this -- cgit v1.2.3 From 4f709fe4fbf9d959b4b6ab00059afa1074c6276b Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 17:17:05 +0100 Subject: small speedups --- lib/python/Components/config.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index f72a4c4e..5cbd23e2 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -317,13 +317,13 @@ class ConfigSelection(ConfigElement): def getText(self): descr = self.description[self.value] - if len(descr): + if descr: return _(descr) return descr def getMulti(self, selected): descr = self.description[self.value] - if len(descr): + if descr: return ("text", _(descr)) return ("text", descr) @@ -367,13 +367,13 @@ class ConfigBoolean(ConfigElement): def getText(self): descr = self.descriptions[self.value] - if len(descr): + if descr: return _(descr) return descr def getMulti(self, selected): descr = self.descriptions[self.value] - if len(descr): + if descr: return ("text", _(descr)) return ("text", descr) @@ -577,7 +577,7 @@ class ConfigSequence(ConfigElement): mPos = self.marked_pos num = 0; for i in self._value: - if len(value): #fixme no heading separator possible + if value: #fixme no heading separator possible value += self.seperator if mPos >= len(value) - 1: mPos += 1 @@ -680,7 +680,7 @@ class ConfigIP(ConfigSequence): block_strlen = [] for i in self._value: block_strlen.append(len(str(i))) - if len(value): + if value: value += self.seperator value += str(i) leftPos = sum(block_strlen[:(self.marked_block)])+self.marked_block @@ -1557,7 +1557,7 @@ class Config(ConfigSubsection): def unpickle(self, lines): tree = { } for l in lines: - if not len(l) or l[0] == '#': + if not l or l[0] == '#': continue n = l.find('=') -- cgit v1.2.3 From 7396199f41aea5f04d0bbf29398bd661abfc7533 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 18:39:56 +0100 Subject: another cleanup/speedup --- lib/python/Components/config.py | 51 +++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 5cbd23e2..1c8e0903 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -26,17 +26,30 @@ from time import localtime, strftime # the default if saved_value is 'None' (default) # or invalid. # -class ConfigElement(object): +class ConfigElement: def __init__(self): - object.__init__(self) self.saved_value = None self.last_value = None self.save_disabled = False - self.notifiers = [] - self.notifiers_final = [] + self.__notifiers = None + self.__notifiers_final = None self.enabled = True self.callNotifiersOnSaveAndCancel = False + def getNotifiers(self): + if self.__notifiers is None: + self.__notifiers = [ ] + return self.__notifiers + + notifiers = property(getNotifiers) + + def getNotifiersFinal(self): + if self.__notifiers_final is None: + self.__notifiers_final = [ ] + return self.__notifiers_final + + notifiers_final = property(getNotifiersFinal) + # you need to override this to do input validation def setValue(self, value): self._value = value @@ -83,12 +96,14 @@ class ConfigElement(object): return self.tostring(self.value) != sv def changed(self): - for x in self.notifiers: - x(self) + if self.__notifiers: + for x in self.notifiers: + x(self) def changedFinal(self): - for x in self.notifiers_final: - x(self) + if self.__notifiers_final: + for x in self.notifiers_final: + x(self) def addNotifier(self, notifier, initial_call = True, immediate_feedback = True): assert callable(notifier), "notifiers must be callable" @@ -139,12 +154,11 @@ def getKeyNumber(key): assert key in KEY_NUMBERS return key - KEY_0 -class choicesList(object): # XXX: we might want a better name for this +class choicesList: # XXX: we might want a better name for this LIST_TYPE_LIST = 1 LIST_TYPE_DICT = 2 def __init__(self, choices, type = None): - object.__init__(self) self.choices = choices if type is None: if isinstance(choices, list): @@ -1368,8 +1382,7 @@ class ConfigNothing(ConfigSelection): # config.saved_value == {"foo": {"bar": "True"}, "foobar": "False"} # - -class ConfigSubsectionContent(object): +class ConfigSubsectionContent: pass # we store a backup of the loaded configuration @@ -1382,9 +1395,8 @@ class ConfigSubsectionContent(object): # config.dipswitches.append(ConfigYesNo()) # config.dipswitches.append(ConfigYesNo()) # config.dipswitches.append(ConfigYesNo()) -class ConfigSubList(list, object): +class ConfigSubList(list): def __init__(self): - object.__init__(self) list.__init__(self) self.stored_values = {} @@ -1426,9 +1438,8 @@ class ConfigSubList(list, object): # care must be taken that the 'key' has a proper # str() method, because it will be used in the config # file. -class ConfigSubDict(dict, object): +class ConfigSubDict(dict): def __init__(self): - object.__init__(self) dict.__init__(self) self.stored_values = {} @@ -1476,9 +1487,8 @@ class ConfigSubDict(dict, object): # __setattr__. # If you don't understand this, try adding # __setattr__ to a usual exisiting class and you will. -class ConfigSubsection(object): +class ConfigSubsection: def __init__(self): - object.__init__(self) self.__dict__["content"] = ConfigSubsectionContent() self.content.items = { } self.content.stored_values = { } @@ -1487,8 +1497,9 @@ class ConfigSubsection(object): if name == "saved_value": return self.setSavedValue(value) assert isinstance(value, (ConfigSubsection, ConfigElement, ConfigSubList, ConfigSubDict)), "ConfigSubsections can only store ConfigSubsections, ConfigSubLists, ConfigSubDicts or ConfigElements" - self.content.items[name] = value - x = self.content.stored_values.get(name, None) + content = self.content + content.items[name] = value + x = content.stored_values.get(name, None) if x is not None: #print "ok, now we have a new item,", name, "and have the following value for it:", x value.saved_value = x -- cgit v1.2.3 From e6b1c147b24594ab5533511c1dce13407e7d0d0a Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 20:11:58 +0100 Subject: revert some changes --- lib/python/Components/config.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 1c8e0903..68fd0f74 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -26,7 +26,7 @@ from time import localtime, strftime # the default if saved_value is 'None' (default) # or invalid. # -class ConfigElement: +class ConfigElement(object): def __init__(self): self.saved_value = None self.last_value = None @@ -154,7 +154,7 @@ def getKeyNumber(key): assert key in KEY_NUMBERS return key - KEY_0 -class choicesList: # XXX: we might want a better name for this +class choicesList(object): # XXX: we might want a better name for this LIST_TYPE_LIST = 1 LIST_TYPE_DICT = 2 @@ -999,7 +999,7 @@ class ConfigPassword(ConfigText): if self.hidden: text = len(text) * self.censor_char return (mtext, text, mark) - + def onSelect(self, session): ConfigText.onSelect(self, session) self.hidden = False @@ -1382,7 +1382,7 @@ class ConfigNothing(ConfigSelection): # config.saved_value == {"foo": {"bar": "True"}, "foobar": "False"} # -class ConfigSubsectionContent: +class ConfigSubsectionContent(object): pass # we store a backup of the loaded configuration @@ -1395,7 +1395,7 @@ class ConfigSubsectionContent: # config.dipswitches.append(ConfigYesNo()) # config.dipswitches.append(ConfigYesNo()) # config.dipswitches.append(ConfigYesNo()) -class ConfigSubList(list): +class ConfigSubList(list, object): def __init__(self): list.__init__(self) self.stored_values = {} @@ -1438,7 +1438,7 @@ class ConfigSubList(list): # care must be taken that the 'key' has a proper # str() method, because it will be used in the config # file. -class ConfigSubDict(dict): +class ConfigSubDict(dict, object): def __init__(self): dict.__init__(self) self.stored_values = {} @@ -1487,7 +1487,7 @@ class ConfigSubDict(dict): # __setattr__. # If you don't understand this, try adding # __setattr__ to a usual exisiting class and you will. -class ConfigSubsection: +class ConfigSubsection(object): def __init__(self): self.__dict__["content"] = ConfigSubsectionContent() self.content.items = { } -- cgit v1.2.3 From 6533ba61374a744fdc01a39cef95d923ba2ab451 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 20:36:56 +0100 Subject: small fixes --- lib/python/Components/config.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 68fd0f74..3f438037 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -41,14 +41,20 @@ class ConfigElement(object): self.__notifiers = [ ] return self.__notifiers - notifiers = property(getNotifiers) + def setNotifiers(self, val): + self.__notifiers = val + + notifiers = property(getNotifiers, setNotifiers) def getNotifiersFinal(self): if self.__notifiers_final is None: self.__notifiers_final = [ ] return self.__notifiers_final - notifiers_final = property(getNotifiersFinal) + def setNotifiersFinal(self, val): + self.__notifiers_final = val + + notifiers_final = property(getNotifiersFinal, setNotifiersFinal) # you need to override this to do input validation def setValue(self, value): @@ -500,7 +506,7 @@ class ConfigSequence(ConfigElement): num += 1 if self.marked_pos >= max_pos: - if endNotifier: + if self.endNotifier: for x in self.endNotifier: x(self) self.marked_pos = max_pos - 1 @@ -518,8 +524,8 @@ class ConfigSequence(ConfigElement): self.marked_pos = total_len - 1 def addEndNotifier(self, notifier): - if endNotifier is None: - endNotifier = [] + if self.endNotifier is None: + self.endNotifier = [] self.endNotifier.append(notifier) def handleKey(self, key): -- cgit v1.2.3 From 8a83490dca1b493de60451d6969d126c7e42d80c Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 21:31:03 +0100 Subject: whitespace cleanups, small optimizations --- lib/python/Components/config.py | 179 +++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 84 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 3f438037..3b61909f 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -20,7 +20,7 @@ from time import localtime, strftime # saved_value is a text representation of _value, stored in the config file # # and has (at least) the following methods: -# save() stores _value into saved_value, +# save() stores _value into saved_value, # (or stores 'None' if it should not be stored) # load() loads _value from saved_value, or loads # the default if saved_value is 'None' (default) @@ -63,7 +63,7 @@ class ConfigElement(object): def getValue(self): return self._value - + value = property(getValue, setValue) # you need to override this if self.value is not a string @@ -105,12 +105,12 @@ class ConfigElement(object): if self.__notifiers: for x in self.notifiers: x(self) - + def changedFinal(self): if self.__notifiers_final: for x in self.notifiers_final: x(self) - + def addNotifier(self, notifier, initial_call = True, immediate_feedback = True): assert callable(notifier), "notifiers must be callable" if immediate_feedback: @@ -311,10 +311,10 @@ class ConfigSelection(ConfigElement): self._value = text value = property(getValue, setValue) - + def getIndex(self): return self.choices.index(self.value) - + index = property(getIndex) # GUI @@ -533,15 +533,15 @@ class ConfigSequence(ConfigElement): self.marked_pos -= 1 self.validatePos() - if key == KEY_RIGHT: + elif key == KEY_RIGHT: self.marked_pos += 1 self.validatePos() - if key == KEY_HOME: + elif key == KEY_HOME: self.marked_pos = 0 self.validatePos() - if key == KEY_END: + elif key == KEY_END: max_pos = 0 num = 0 for i in self._value: @@ -550,7 +550,7 @@ class ConfigSequence(ConfigElement): self.marked_pos = max_pos - 1 self.validatePos() - if key in KEY_NUMBERS or key == KEY_ASCII: + elif key in KEY_NUMBERS or key == KEY_ASCII: if key == KEY_ASCII: code = getPrevAsciiCode() if code < 48 or code > 57: @@ -559,10 +559,7 @@ class ConfigSequence(ConfigElement): else: number = getKeyNumber(key) - block_len = [] - for x in self.limits: - block_len.append(len(str(x[1]))) - + block_len = [len(str(x[1])) for x in self.limits] total_len = sum(block_len) pos = 0 @@ -639,46 +636,43 @@ ip_limits = [(0,255),(0,255),(0,255),(0,255)] class ConfigIP(ConfigSequence): def __init__(self, default, auto_jump = False): ConfigSequence.__init__(self, seperator = ".", limits = ip_limits, default = default) - self.block_len = [] - for x in self.limits: - self.block_len.append(len(str(x[1]))) + self.block_len = [len(str(x[1])) for x in self.limits] self.marked_block = 0 self.overwrite = True self.auto_jump = auto_jump def handleKey(self, key): - if key == KEY_LEFT: if self.marked_block > 0: self.marked_block -= 1 self.overwrite = True - if key == KEY_RIGHT: + elif key == KEY_RIGHT: if self.marked_block < len(self.limits)-1: self.marked_block += 1 self.overwrite = True - if key == KEY_HOME: + elif key == KEY_HOME: self.marked_block = 0 self.overwrite = True - if key == KEY_END: + elif key == KEY_END: self.marked_block = len(self.limits)-1 self.overwrite = True - if key in KEY_NUMBERS or key == KEY_ASCII: + elif key in KEY_NUMBERS or key == KEY_ASCII: if key == KEY_ASCII: code = getPrevAsciiCode() if code < 48 or code > 57: return number = code - 48 - else: + else: number = getKeyNumber(key) oldvalue = self._value[self.marked_block] - + if self.overwrite: self._value[self.marked_block] = number - self.overwrite = False + self.overwrite = False else: oldvalue *= 10 newvalue = oldvalue + number @@ -699,7 +693,7 @@ class ConfigIP(ConfigSequence): value = "" block_strlen = [] for i in self._value: - block_strlen.append(len(str(i))) + block_strlen.append(len(str(i))) if value: value += self.seperator value += str(i) @@ -707,7 +701,7 @@ class ConfigIP(ConfigSequence): rightPos = sum(block_strlen[:(self.marked_block+1)])+self.marked_block mBlock = range(leftPos, rightPos) return (value, mBlock) - + def getMulti(self, selected): (value, mBlock) = self.genText() if self.enabled: @@ -768,7 +762,7 @@ integer_limits = (0, 9999999999) class ConfigInteger(ConfigSequence): def __init__(self, default, limits = integer_limits): ConfigSequence.__init__(self, seperator = ":", limits = [limits], default = default) - + # you need to override this to do input validation def setValue(self, value): self._value = [value] @@ -810,7 +804,7 @@ class ConfigText(ConfigElement, NumericalTextInput): def __init__(self, default = "", fixed_size = True, visible_width = False): ConfigElement.__init__(self) NumericalTextInput.__init__(self, nextFunc = self.nextFunc, handleTimeout = False) - + self.marked_pos = 0 self.allmarked = (default != "") self.fixed_size = fixed_size @@ -821,24 +815,25 @@ class ConfigText(ConfigElement, NumericalTextInput): self.value = self.last_value = self.default = default def validateMarker(self): + textlen = len(self.text) if self.fixed_size: - if self.marked_pos > len(self.text)-1: - self.marked_pos = len(self.text)-1 + if self.marked_pos > textlen-1: + self.marked_pos = textlen-1 else: - if self.marked_pos > len(self.text): - self.marked_pos = len(self.text) + if self.marked_pos > textlen: + self.marked_pos = textlen if self.marked_pos < 0: self.marked_pos = 0 if self.visible_width: if self.marked_pos < self.offset: self.offset = self.marked_pos if self.marked_pos >= self.offset + self.visible_width: - if self.marked_pos == len(self.text): + if self.marked_pos == textlen: self.offset = self.marked_pos - self.visible_width else: self.offset = self.marked_pos - self.visible_width + 1 - if self.offset > 0 and self.offset + self.visible_width > len(self.text): - self.offset = max(0, len(self.text) - self.visible_width) + if self.offset > 0 and self.offset + self.visible_width > textlen: + self.offset = max(0, len - self.visible_width) def insertChar(self, ch, pos, owr): if owr or self.overwrite: @@ -1020,7 +1015,7 @@ class ConfigNumber(ConfigText): def getValue(self): return int(self.text) - + def setValue(self, val): self.text = str(val) @@ -1073,17 +1068,21 @@ class ConfigSearchText(ConfigText): class ConfigDirectory(ConfigText): def __init__(self, default="", visible_width=60): ConfigText.__init__(self, default, fixed_size = True, visible_width = visible_width) + def handleKey(self, key): pass + def getValue(self): if self.text == "": return None else: return ConfigText.getValue(self) + def setValue(self, val): if val == None: val = "" ConfigText.setValue(self, val) + def getMulti(self, selected): if self.text == "": return ("mtext"[1-selected:], _("List of Storage Devices"), range(0)) @@ -1140,7 +1139,7 @@ class ConfigSatlist(ConfigSelection): if self.value == "": return None return int(self.value) - + orbital_position = property(getOrbitalPosition) class ConfigSet(ConfigElement): @@ -1159,11 +1158,12 @@ class ConfigSet(ConfigElement): self.value = default[:] def toggleChoice(self, choice): - if choice in self.value: - self.value.remove(choice) + value = self.value + if choice in value: + value.remove(choice) else: - self.value.append(choice) - self.value.sort() + value.append(choice) + value.sort() self.changed() def handleKey(self, key): @@ -1171,13 +1171,15 @@ class ConfigSet(ConfigElement): if self.pos != -1: self.toggleChoice(self.choices[self.pos]) elif key == KEY_LEFT: - self.pos -= 1 - if self.pos < -1: - self.pos = len(self.choices)-1 + if self.pos < 0: + self.pos = len(self.choices)-1 + else: + self.pos -= 1 elif key == KEY_RIGHT: - self.pos += 1 - if self.pos >= len(self.choices): - self.pos = -1 + if self.pos >= len(self.choices)-1: + self.pos = -1 + else: + self.pos += 1 elif key in [KEY_HOME, KEY_END]: self.pos = -1 @@ -1207,14 +1209,15 @@ class ConfigSet(ConfigElement): chstr = " "+self.description[ch]+" " else: chstr = "("+self.description[ch]+")" - return ("mtext", val1+chstr+val2, range(len(val1),len(val1)+len(chstr))) + len_val1 = len(val1) + return ("mtext", val1+chstr+val2, range(len_val1, len_val1 + len(chstr))) def onDeselect(self, session): self.pos = -1 if not self.last_value == self.value: self.changedFinal() self.last_value = self.value[:] - + def tostring(self, value): return str(value) @@ -1232,22 +1235,25 @@ class ConfigLocations(ConfigElement): self.locations = [] self.mountpoints = [] harddiskmanager.on_partition_list_change.append(self.mountpointsChanged) - self.value = default+[] + self.value = default[:] def setValue(self, value): - loc = [x[0] for x in self.locations if x[3]] + locations = self.locations + loc = [x[0] for x in locations if x[3]] add = [x for x in value if not x in loc] diff = add + [x for x in loc if not x in value] - self.locations = [x for x in self.locations if not x[0] in diff] + [[x, self.getMountpoint(x), True, True] for x in add] - self.locations.sort(key = lambda x: x[0]) + locations = [x for x in locations if not x[0] in diff] + [[x, self.getMountpoint(x), True, True] for x in add] + locations.sort(key = lambda x: x[0]) + self.locations = locations self.changed() def getValue(self): self.checkChangedMountpoints() - for x in self.locations: + locations = self.locations + for x in locations: x[3] = x[2] - return [x[0] for x in self.locations if x[3]] - + return [x[0] for x in locations if x[3]] + value = property(getValue, setValue) def tostring(self, value): @@ -1262,24 +1268,27 @@ class ConfigLocations(ConfigElement): tmp = self.default else: tmp = self.fromstring(sv) - self.locations = [[x, None, False, False] for x in tmp] + locations = [[x, None, False, False] for x in tmp] self.refreshMountpoints() - for x in self.locations: + for x in locations: if os_path.exists(x[0]): x[1] = self.getMountpoint(x[0]) x[2] = True + self.locations = locations def save(self): - if self.save_disabled or self.locations == []: + locations = self.locations + if self.save_disabled or not locations: self.saved_value = None else: - self.saved_value = self.tostring([x[0] for x in self.locations]) + self.saved_value = self.tostring([x[0] for x in locations]) def isChanged(self): sv = self.saved_value - if val is None and self.locations == []: + locations = self.locations + if val is None and not locations: return False - return self.tostring([x[0] for x in self.locations]) != sv + return self.tostring([x[0] for x in locations]) != sv def mountpointsChanged(self, action, dev): print "Mounts changed: ", action, dev @@ -1302,7 +1311,7 @@ class ConfigLocations(ConfigElement): for x in self.locations: if x[1] == mp: x[2] = False - + def refreshMountpoints(self): self.mountpoints = [p.mountpoint + "/" for p in harddiskmanager.getMountedPartitions() if p.mountpoint != "/"] self.mountpoints.sort(key = lambda x: -len(x)) @@ -1310,12 +1319,13 @@ class ConfigLocations(ConfigElement): def checkChangedMountpoints(self): oldmounts = self.mountpoints self.refreshMountpoints() - if oldmounts == self.mountpoints: + newmounts = self.mountpoints + if oldmounts == newmounts: return for x in oldmounts: - if not x in self.mountpoints: + if not x in newmounts: self.removedMount(x) - for x in self.mountpoints: + for x in newmounts: if not x in oldmounts: self.addedMount(x) @@ -1330,11 +1340,11 @@ class ConfigLocations(ConfigElement): if key == KEY_LEFT: self.pos -= 1 if self.pos < -1: - self.pos = len(self.value)-1 + self.pos = len(self.value)-1 elif key == KEY_RIGHT: self.pos += 1 if self.pos >= len(self.value): - self.pos = -1 + self.pos = -1 elif key in [KEY_HOME, KEY_END]: self.pos = -1 @@ -1371,7 +1381,7 @@ class ConfigLocations(ConfigElement): def onDeselect(self, session): self.pos = -1 - + # nothing. class ConfigNothing(ConfigSelection): def __init__(self): @@ -1409,7 +1419,7 @@ class ConfigSubList(list, object): def save(self): for x in self: x.save() - + def load(self): for x in self: x.load() @@ -1452,7 +1462,7 @@ class ConfigSubDict(dict, object): def save(self): for x in self.values(): x.save() - + def load(self): for x in self.values(): x.load() @@ -1489,7 +1499,7 @@ class ConfigSubDict(dict, object): # loading of added elements. this is why this class # is so complex. # -# we need the 'content' because we overwrite +# we need the 'content' because we overwrite # __setattr__. # If you don't understand this, try adding # __setattr__ to a usual exisiting class and you will. @@ -1498,7 +1508,7 @@ class ConfigSubsection(object): self.__dict__["content"] = ConfigSubsectionContent() self.content.items = { } self.content.stored_values = { } - + def __setattr__(self, name, value): if name == "saved_value": return self.setSavedValue(value) @@ -1558,7 +1568,7 @@ class Config(ConfigSubsection): def pickle_this(self, prefix, topickle, result): for (key, val) in topickle.items(): - name = ''.join((prefix, '.', key)) + name = '.'.join((prefix, key)) if isinstance(val, dict): self.pickle_this(name, val, result) elif isinstance(val, tuple): @@ -1576,7 +1586,7 @@ class Config(ConfigSubsection): for l in lines: if not l or l[0] == '#': continue - + n = l.find('=') val = l[n+1:].strip() @@ -1585,10 +1595,10 @@ class Config(ConfigSubsection): # val = val[:val.find(' ')] base = tree - + for n in names[:-1]: base = base.setdefault(n, {}) - + base[names[-1]] = val # we inherit from ConfigSubsection, so ... @@ -1617,19 +1627,20 @@ class ConfigFile: 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 __resolveValue(self, pickles, cmap): - if cmap.has_key(pickles[0]): + key = pickles[0] + if cmap.has_key(key): if len(pickles) > 1: - return self.__resolveValue(pickles[1:], cmap[pickles[0]].dict()) + return self.__resolveValue(pickles[1:], cmap[key].dict()) else: - return str(cmap[pickles[0]].value) + return str(cmap[key].value) return None - + def getResolvedKey(self, key): names = key.split('.') if len(names) > 1: -- cgit v1.2.3 From cfb43dc930adbbf59879abf8f3f0297caa94a050 Mon Sep 17 00:00:00 2001 From: ghost Date: Wed, 11 Feb 2009 22:15:45 +0100 Subject: fix crash in manual scan (and other screens) since config speedups --- lib/python/Components/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index 3b61909f..c999f2aa 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -178,14 +178,14 @@ class choicesList(object): # XXX: we might want a better name for this def __list__(self): if self.type == choicesList.LIST_TYPE_LIST: - ret = [isinstance(x, tuple) and x[0] or x for x in self.choices] + ret = [not isinstance(x, tuple) and x or x[0] for x in self.choices] else: ret = self.choices.keys() return ret or [""] def __iter__(self): if self.type == choicesList.LIST_TYPE_LIST: - ret = [isinstance(x, tuple) and x[0] or x for x in self.choices] + ret = [not isinstance(x, tuple) and x or x[0] for x in self.choices] else: ret = self.choices return iter(ret or [""]) @@ -232,7 +232,7 @@ class choicesList(object): # XXX: we might want a better name for this class descriptionList(choicesList): # XXX: we might want a better name for this def __list__(self): if self.type == choicesList.LIST_TYPE_LIST: - ret = [isinstance(x, tuple) and x[1] or x for x in self.choices] + ret = [not isinstance(x, tuple) and x or x[1] for x in self.choices] else: ret = self.choices.values() return ret or [""] -- cgit v1.2.3 From 1bd22cc97199c878255925ef2a9032881acef470 Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Thu, 12 Feb 2009 16:48:39 +0100 Subject: allow extensions on blue button for movie player (usable on dm8000 rc) --- lib/python/Screens/InfoBar.py | 4 ++-- lib/python/Screens/InfoBarGenerics.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/python') diff --git a/lib/python/Screens/InfoBar.py b/lib/python/Screens/InfoBar.py index 01b77f3f..baa9e5f2 100644 --- a/lib/python/Screens/InfoBar.py +++ b/lib/python/Screens/InfoBar.py @@ -126,7 +126,7 @@ class MoviePlayer(InfoBarBase, InfoBarShowHide, \ InfoBarSeek, InfoBarShowMovies, InfoBarAudioSelection, HelpableScreen, InfoBarNotifications, InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, Screen, InfoBarTeletextPlugin, - InfoBarServiceErrorPopupSupport): + InfoBarServiceErrorPopupSupport, InfobarExtensions): ENABLE_RESUME_SUPPORT = True ALLOW_SUSPEND = True @@ -144,7 +144,7 @@ class MoviePlayer(InfoBarBase, InfoBarShowHide, \ InfoBarAudioSelection, InfoBarNotifications, InfoBarSimpleEventView, \ InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, \ InfoBarMoviePlayerSummarySupport, InfoBarSubtitleSupport, \ - InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport: + InfoBarTeletextPlugin, InfoBarServiceErrorPopupSupport, InfobarExtensions: x.__init__(self) self.lastservice = self.session.nav.getCurrentlyPlayingServiceReference() diff --git a/lib/python/Screens/InfoBarGenerics.py b/lib/python/Screens/InfoBarGenerics.py index 9e0e50af..3404e3f9 100644 --- a/lib/python/Screens/InfoBarGenerics.py +++ b/lib/python/Screens/InfoBarGenerics.py @@ -1221,7 +1221,7 @@ class InfoBarExtensions: self["InstantExtensionsActions"] = HelpableActionMap(self, "InfobarExtensions", { "extensions": (self.showExtensionSelection, _("view extensions...")), - }) + }, 1) # lower priority def addExtension(self, extension, key = None, type = EXTENSION_SINGLE): self.list.append((type, extension, key)) -- cgit v1.2.3