From 7b9d3432c8b671621bba5803a0e44cb295f7f6f8 Mon Sep 17 00:00:00 2001 From: Stefan Pluecken Date: Fri, 11 Nov 2005 23:16:40 +0000 Subject: [PATCH] add configText for entering text in the configList (numbers only at the moment) --- data/skin.xml | 8 ++-- lib/python/Components/config.py | 64 +++++++++++++++++++++++++++++--- lib/python/Screens/TimerEntry.py | 2 + 3 files changed, 64 insertions(+), 10 deletions(-) diff --git a/data/skin.xml b/data/skin.xml index 6716acf3..6e62b1c5 100644 --- a/data/skin.xml +++ b/data/skin.xml @@ -83,8 +83,8 @@ - - + + @@ -116,8 +116,8 @@ - - + + diff --git a/lib/python/Components/config.py b/lib/python/Components/config.py index b5a767a2..75dee0ce 100644 --- a/lib/python/Components/config.py +++ b/lib/python/Components/config.py @@ -265,6 +265,53 @@ class configSequence: # (this code is heavily ink optimized!) return ("mtext"[1-selected:], value, [mPos]) +class configText: + # used as first parameter + # is the text of a fixed size or is the user able to extend the length of the text + extendableSize = 1 + fixedSize = 2 + + def __init__(self, parent): + self.parent = parent + self.markedPos = 0 + self.mode = self.parent.vals[0] + + def checkValues(self): + if (self.markedPos < 0): + self.markedPos = 0 + if (self.markedPos >= len(self.parent.value)): + self.markedPos = len(self.parent.value) - 1 + + def cancel(self): + self.parent.reload() + + def save(self): + self.parent.save() + + def handleKey(self, key): + #this will no change anything on the value itself + #so we can handle it here in gui element + if key == config.key["prevElement"]: + self.markedPos -= 1 + if key == config.key["nextElement"]: + self.markedPos += 1 + if (self.mode == self.extendableSize): + if (self.markedPos >= len(self.parent.value)): + self.parent.value = self.parent.value.ljust(len(self.parent.value) + 1) + + + if key >= config.key["0"] and key <= config.key["9"]: + number = 9 - config.key["9"] + key + + self.parent.value = self.parent.value[0:self.markedPos] + str(number) + self.parent.value[self.markedPos + 1:] + + self.checkValues() + + self.parent.change() + + def __call__(self, selected): #needed by configlist + return ("mtext"[1-selected:], str(self.parent.value), [self.markedPos]) + class configValue: def __init__(self, obj): self.obj = obj @@ -342,11 +389,13 @@ class configElement: def datafromFile(self, control, data): if control == ConfigSlider: - return int(data); + return int(data) elif control == configSelection: - return int(data); + return int(data) elif control == configDateTime: - return int(data); + return int(data) + elif control == configText: + return str(data) elif control == configSequence: list = [ ] part = data.split(self.vals[0]) @@ -360,11 +409,14 @@ class configElement: def datatoFile(self, control, data): if control == ConfigSlider: - return str(data); + return str(data) elif control == configSelection: - return str(data); + return str(data) elif control == configDateTime: - return str(data); + return str(data) + elif control == configText: + return str(data.strip()) + elif control == configSequence: value = ((len(data) * ("%d" + self.vals[0]))[0:-1]) % tuple(data) # just in case you don't understand the above, here an equivalent: diff --git a/lib/python/Screens/TimerEntry.py b/lib/python/Screens/TimerEntry.py index c61e9ab3..000e8c28 100644 --- a/lib/python/Screens/TimerEntry.py +++ b/lib/python/Screens/TimerEntry.py @@ -40,6 +40,7 @@ class TimerEntry(Screen): config.timerentry = ConfigSubsection() config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, 0, ("once", "repeated")) + config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, timer.description, (configText.extendableSize,)) config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, timer.begin, ("%d.%B %Y", 86400)) config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configSequence, [int(strftime("%H", localtime(timer.begin))), int(strftime("%M", localtime(timer.begin)))], configsequencearg.get("CLOCK")) #config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configDateTime, timer.begin, ("%H:%M", 60)) @@ -50,6 +51,7 @@ class TimerEntry(Screen): def createSetup(self): self.list = [] + self.list.append(getConfigListEntry("Description", config.timerentry.description)) self.list.append(getConfigListEntry("TimerType", config.timerentry.type)) if (config.timerentry.type.value == 0): -- 2.30.2