From 2db3e8afead0a9ee14871c8436691755be22a5ca Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Thu, 6 Nov 2008 00:17:52 +0100 Subject: [PATCH] Patch by Anders Holst: * ConfigElement.addNotifier takes a new optional argument immediate_feedback (which is True by default). If True the notifier is called whenever an editing key is pressed in the element. When False, the notifier is only called when editing is finished, i.e the element is deselected or the dialog closed. * ConfigSet is updated in accordance with Teros suggestion so that it behaves like the others and feedback can be given immediately. * All ConfigElements are modified to check whether they have changed since last selected (by a new variable last_value). * UsageConfig.py is updated to use immediate_feedback=False in the case of validating the speeds. (The only case so far where this setting is needed, but with the possibility more uses may follow.) --- lib/python/Components/UsageConfig.py | 8 ++--- lib/python/Components/config.py | 53 ++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/lib/python/Components/UsageConfig.py b/lib/python/Components/UsageConfig.py index 6ed87840..2ea91aeb 100644 --- a/lib/python/Components/UsageConfig.py +++ b/lib/python/Components/UsageConfig.py @@ -89,8 +89,8 @@ def InitUsageConfig(): config.seek.speeds_backward = ConfigSet(default=[8, 16, 32, 64, 128], choices=[1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128]) config.seek.speeds_slowmotion = ConfigSet(default=[2, 4, 8], choices=[2, 4, 6, 8, 12, 16, 25]) - config.seek.enter_forward = ConfigSelection(default = "2", choices = ["2"]) - config.seek.enter_backward = ConfigSelection(default = "2", choices = ["2"]) + config.seek.enter_forward = ConfigSelection(default = "2", choices = ["2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"]) + config.seek.enter_backward = ConfigSelection(default = "1", choices = ["1", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"]) config.seek.stepwise_minspeed = ConfigSelection(default = "16", choices = ["Never", "2", "4", "6", "8", "12", "16", "24", "32", "48", "64", "96", "128"]) config.seek.stepwise_repeat = ConfigSelection(default = "3", choices = ["2", "3", "4", "5", "6"]) @@ -104,14 +104,14 @@ def InitUsageConfig(): configElement.value = [2] updateChoices(config.seek.enter_forward, configElement.value) - config.seek.speeds_forward.addNotifier(updateEnterForward) + config.seek.speeds_forward.addNotifier(updateEnterForward, immediate_feedback = False) def updateEnterBackward(configElement): if not configElement.value: configElement.value = [2] updateChoices(config.seek.enter_backward, configElement.value) - config.seek.speeds_backward.addNotifier(updateEnterBackward) + config.seek.speeds_backward.addNotifier(updateEnterBackward, immediate_feedback = False) def updateChoices(sel, choices): if choices: diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index cfa4318c..1efb8a56 100755 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -31,8 +31,10 @@ class ConfigElement(object): object.__init__(self) self.saved_value = None + self.last_value = None self.save_disabled = False self.notifiers = [] + self.notifiers_final = [] self.enabled = True self.callNotifiersOnSaveAndCancel = False @@ -85,10 +87,16 @@ class ConfigElement(object): for x in self.notifiers: x(self) - def addNotifier(self, notifier, initial_call = True): + def changedFinal(self): + 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" - self.notifiers.append(notifier) - + if immediate_feedback: + self.notifiers.append(notifier) + else: + self.notifiers_final.append(notifier) # CHECKME: # do we want to call the notifier # - at all when adding it? (yes, though optional) @@ -110,7 +118,9 @@ class ConfigElement(object): pass def onDeselect(self, session): - pass + if not self.last_value == self.value: + self.changedFinal() + self.last_value = self.value KEY_LEFT = 0 KEY_RIGHT = 1 @@ -143,6 +153,7 @@ class ConfigSelection(ConfigElement): ConfigElement.__init__(self) self._value = None self.setChoices(choices, default) + self.last_value = self._value def setChoices(self, choices, default = None): self.choices = [] @@ -262,7 +273,8 @@ class ConfigBoolean(ConfigElement): def __init__(self, default = False, descriptions = {False: "false", True: "true"}): ConfigElement.__init__(self) self.descriptions = descriptions - self.value = self.default = default + self.value = self.last_value = self.default = default + def handleKey(self, key): if key in [KEY_LEFT, KEY_RIGHT]: self.value = not self.value @@ -309,6 +321,11 @@ class ConfigBoolean(ConfigElement): else: self.value = False + def onDeselect(self, session): + if not self.last_value == self.value: + self.changedFinal() + self.last_value = self.value + class ConfigYesNo(ConfigBoolean): def __init__(self, default = False): ConfigBoolean.__init__(self, default = default, descriptions = {False: _("no"), True: _("yes")}) @@ -326,7 +343,7 @@ class ConfigDateTime(ConfigElement): ConfigElement.__init__(self) self.increment = increment self.formatstring = formatstring - self.value = self.default = int(default) + self.value = self.last_value = self.default = int(default) def handleKey(self, key): if key == KEY_LEFT: @@ -367,6 +384,7 @@ class ConfigSequence(ConfigElement): self.default = default self.value = copy.copy(default) + self.last_value = copy.copy(default) self.endNotifier = [] @@ -507,6 +525,11 @@ class ConfigSequence(ConfigElement): def fromstring(self, value): return [int(x) for x in value.split(self.seperator)] + def onDeselect(self, session): + if not self.last_value == self._value: + self.changedFinal() + self.last_value = copy.copy(self._value) + class ConfigIP(ConfigSequence): def __init__(self, default, auto_jump = False): ConfigSequence.__init__(self, seperator = ".", limits = [(0,255),(0,255),(0,255),(0,255)], default = default) @@ -685,7 +708,7 @@ class ConfigText(ConfigElement, NumericalTextInput): self.offset = 0 self.overwrite = fixed_size self.help_window = None - self.value = self.default = default + self.value = self.last_value = self.default = default def validateMarker(self): if self.fixed_size: @@ -851,6 +874,9 @@ class ConfigText(ConfigElement, NumericalTextInput): if self.help_window: session.deleteDialog(self.help_window) self.help_window = None + if not self.last_value == self.value: + self.changedFinal() + self.last_value = self.value def getHTML(self, id): return '
\n' @@ -925,6 +951,9 @@ class ConfigNumber(ConfigText): def onDeselect(self, session): self.marked_pos = 0 self.offset = 0 + if not self.last_value == self.value: + self.changedFinal() + self.last_value = self.value class ConfigSearchText(ConfigText): def __init__(self, default = "", fixed_size = False, visible_width = False): @@ -955,7 +984,7 @@ class ConfigDirectory(ConfigText): class ConfigSlider(ConfigElement): def __init__(self, default = 0, increment = 1, limits = (0, 100)): ConfigElement.__init__(self) - self.value = self.default = default + self.value = self.last_value = self.default = default self.min = limits[0] self.max = limits[1] self.increment = increment @@ -1027,7 +1056,7 @@ class ConfigSet(ConfigElement): default = [] self.pos = -1 default.sort() - self.default = default + self.last_value = self.default = default self.value = default+[] def toggleChoice(self, choice): @@ -1036,6 +1065,7 @@ class ConfigSet(ConfigElement): else: self.value.append(choice) self.value.sort() + self.changed() def handleKey(self, key): if key in KEY_NUMBERS + [KEY_DELETE, KEY_BACKSPACE]: @@ -1082,7 +1112,9 @@ class ConfigSet(ConfigElement): def onDeselect(self, session): self.pos = -1 - self.changed() + if not self.last_value == self.value: + self.changedFinal() + self.last_value = self.value+[] def tostring(self, value): return str(value) @@ -1099,6 +1131,7 @@ class ConfigLocations(ConfigElement): self.locations = [] self.mountpoints = [] harddiskmanager.on_partition_list_change.append(self.mountpointsChanged) + self.value = default+[] def setValue(self, value): loc = [x[0] for x in self.locations if x[3]] -- 2.30.2