some NumericalInput and uncode/utf-8 fixes
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 24 Aug 2006 12:16:56 +0000 (12:16 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 24 Aug 2006 12:16:56 +0000 (12:16 +0000)
RecordTimer.py
lib/python/Components/Input.py
lib/python/Components/config.py
lib/python/Screens/ChannelSelection.py
lib/python/Tools/NumericalTextInput.py

index da629ee..25c2b03 100644 (file)
@@ -338,7 +338,7 @@ class RecordTimer(timer.Timer):
                        list.append(' end="' + str(int(timer.end)) + '"')
                        list.append(' serviceref="' + str(timer.service_ref) + '"')
                        list.append(' repeated="' + str(int(timer.repeated)) + '"')
-                       list.append(' name="' + str(stringToXML(timer.name)) + '"')
+                       list.append(' name="' + str(stringToXML(timer.name.encode("utf-8"))) + '"')
                        list.append(' description="' + str(stringToXML(timer.description)) + '"')
                        list.append(' afterevent="' + str(stringToXML({ AFTEREVENT.NONE: "nothing", AFTEREVENT.STANDBY: "standby", AFTEREVENT.DEEPSTANDBY: "deepstandby" }[timer.afterEvent])) + '"')
                        if timer.eit is not None:
index e7713d6..710ad0b 100644 (file)
@@ -6,19 +6,19 @@ from enigma import eLabel
 
 from Tools.NumericalTextInput import NumericalTextInput
 
-class Input(VariableText, HTMLComponent, GUIComponent):
+class Input(VariableText, HTMLComponent, GUIComponent, NumericalTextInput):
        TEXT = 0
        PIN = 1
        NUMBER = 2
 
        def __init__(self, text="", maxSize = False, type = TEXT):
+               NumericalTextInput.__init__(self, self.right)
                GUIComponent.__init__(self)
                VariableText.__init__(self)
                self.type = type
                self.maxSize = maxSize
                self.currPos = 0
                self.overwrite = 0
-               self.numericalTextInput = NumericalTextInput(self.right)
                self.setText(text)
 
        def update(self):
@@ -122,7 +122,7 @@ class Input(VariableText, HTMLComponent, GUIComponent):
 
        def number(self, number):
                if self.type == self.TEXT:
-                       newChar = self.numericalTextInput.getKey(number)
+                       newChar = self.getKey(number)
                elif self.type == self.PIN or self.type == self.NUMBER:
                        newChar = str(number)
                self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
index c17e5aa..7478653 100644 (file)
@@ -1,5 +1,5 @@
 from time import *
-from Tools.NumericalTextInput import *
+from Tools.NumericalTextInput import NumericalTextInput
 from Tools.Directories import *
 
 class configFile:
@@ -335,30 +335,34 @@ class configNothing:
        def __call__(self, selected):                   #needed by configlist
                return ("text", "")
 
-class configText:
+class configText(NumericalTextInput):
        # 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):
+               NumericalTextInput.__init__(self, self.nextEntry)
                self.parent = parent
                self.markedPos = 0
                self.mode = self.parent.vals[0]
-               self.textInput = NumericalTextInput(self.nextEntry)
+               try:
+                       self.parent.value = self.parent.value.decode("utf-8")
+               except UnicodeDecodeError:
+                       print "utf8 kaputt!"
 
        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 nextEntry(self):
                self.parent.vals[1](self.parent.getConfigPath())
 
@@ -367,30 +371,25 @@ class configText:
                #so we can handle it here in gui element
                if key == config.key["delete"]:
                        self.parent.value = self.parent.value[0:self.markedPos] + self.parent.value[self.markedPos + 1:]
-               if key == config.key["prevElement"]:
-                       self.textInput.nextKey()
+               elif key == config.key["prevElement"]:
+                       self.nextKey()
                        self.markedPos -= 1
-
-               if key == config.key["nextElement"]:
-                       self.textInput.nextKey()
+               elif key == config.key["nextElement"]:
+                       self.nextKey()
                        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"]:
+               elif key >= config.key["0"] and key <= config.key["9"]:
                        number = 9 - config.key["9"] + key
+                       self.parent.value = self.parent.value[0:self.markedPos] + self.getKey(number) + self.parent.value[self.markedPos + 1:]
 
-                       self.parent.value = self.parent.value[0:self.markedPos] + str(self.textInput.getKey(number)) + self.parent.value[self.markedPos + 1:]
-               
-               self.checkValues()                      
-               
-               self.parent.change()    
+               self.checkValues()
+               self.parent.change()
 
        def __call__(self, selected):                   #needed by configlist
-               return ("mtext"[1-selected:], str(self.parent.value), [self.markedPos])
-               
+               return ("mtext"[1-selected:], self.parent.value.encode("utf-8"), [self.markedPos])
+
 class configValue:
        def __init__(self, obj):
                self.obj = obj
index 01feaab..a8d605e 100644 (file)
@@ -480,6 +480,7 @@ class ChannelSelectionBase(Screen):
                self.servicelist = self["list"]
 
                self.numericalTextInput = NumericalTextInput()
+               self.numericalTextInput.setUseableChars(u'1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ')
 
                self.servicePathTV = [ ]
                self.servicePathRadio = [ ]
@@ -799,8 +800,10 @@ class ChannelSelectionBase(Screen):
                                                self.enterPath(self.bouquet_root)
 
        def keyNumberGlobal(self, number):
-               char = self.numericalTextInput.getKey(number)
-               self.servicelist.moveToChar(char)
+               unichar = self.numericalTextInput.getKey(number)
+               charstr = unichar.encode("utf-8")
+               if len(charstr) == 1:
+                       self.servicelist.moveToChar(charstr[0])
 
        def getRoot(self):
                return self.servicelist.getRoot()
index 1acd254..87ac548 100644 (file)
@@ -3,9 +3,11 @@ from enigma import *
 from Components.Language import language
 
 class NumericalTextInput:
-       def __init__(self, nextFunction = None):
+       def __init__(self, nextFunc=None):
                self.mapping = []
                self.lang = language.getLanguage()
+               self.useableChars=None
+               self.nextFunction=nextFunc
                
                if self.lang == 'de_DE':
                        self.mapping.append (u".,?'\"0-()@/:_") # 0
@@ -40,22 +42,34 @@ class NumericalTextInput:
                        self.mapping.append (u"pqrs7PQRS") # 7
                        self.mapping.append (u"tuv8TUV") # 8
                        self.mapping.append (u"wxyz9WXYZ") # 9
-               
-               self.nextFunction = nextFunction
+
                self.Timer = eTimer()
                self.Timer.timeout.get().append(self.nextChar)
                self.lastKey = -1
-               self.pos = 0
+               self.pos = -1
+
+       def setUseableChars(self, useable):
+               self.useableChars = useable
 
        def getKey(self, num):
+               cnt=0
                self.Timer.start(1000, True)
                if (self.lastKey != num):
                        self.lastKey = num
-                       self.pos = 0
-               else:
+                       self.pos = -1
+               while(True):
                        self.pos += 1
                        if (len(self.mapping[num]) <= self.pos):
                                self.pos = 0
+                       if self.useableChars:
+                               pos = self.useableChars.find(self.mapping[num][self.pos])
+                               if pos == -1:
+                                       cnt += 1
+                                       if cnt < len(self.mapping[num]):
+                                               continue
+                                       else:
+                                               return None
+                       break
                return self.mapping[num][self.pos]
 
        def nextKey(self):
@@ -63,10 +77,6 @@ class NumericalTextInput:
                self.lastKey = -1
 
        def nextChar(self):
-               print "Timer done"
-               try:
-                       self.nextKey()
-                       if (self.nextFunction != None):
-                               self.nextFunction()
-               except AttributeError:
-                       print "Text Input object deleted with running nextChar timer?"
+               self.nextKey()
+               if self.nextFunction:
+                       self.nextFunction()