config rewrite. some extensions still need to be updated.
[enigma2.git] / lib / python / Tools / NumericalTextInput.py
index d923290..7c61d26 100644 (file)
@@ -1,74 +1,90 @@
 # -*- coding: latin-1 -*-
-from enigma import *
+from enigma import eTimer
 from Components.Language import language
 
 class NumericalTextInput:
-       def __init__(self, nextFunction = None):
+       def __init__(self, nextFunc=None, handleTimeout = True):
                self.mapping = []
                self.lang = language.getLanguage()
+               self.useableChars=None
+               self.nextFunction=nextFunc
                
                if self.lang == 'de_DE':
-                       self.mapping.append (".,?'\"0-()@/:_") # 0
-                       self.mapping.append (" 1") # 1
-                       self.mapping.append ("aäbc2AÄBC") # 2
-                       self.mapping.append ("def3DEF") # 3
-                       self.mapping.append ("ghi4GHI") # 4
-                       self.mapping.append ("jkl5JKL") # 5
-                       self.mapping.append ("mnoö6MNOÖ") # 6
-                       self.mapping.append ("pqrsß7PQRSß") # 7
-                       self.mapping.append ("tuüv8TUÜV") # 8
-                       self.mapping.append ("wxyz9WXYZ") # 9
+                       self.mapping.append (u".,?'\"0-()@/:_") # 0
+                       self.mapping.append (u" 1") # 1
+                       self.mapping.append (u"aäbc2AÄBC") # 2
+                       self.mapping.append (u"def3DEF") # 3
+                       self.mapping.append (u"ghi4GHI") # 4
+                       self.mapping.append (u"jkl5JKL") # 5
+                       self.mapping.append (u"mnoö6MNOÖ") # 6
+                       self.mapping.append (u"pqrsß7PQRSß") # 7
+                       self.mapping.append (u"tuüv8TUÜV") # 8
+                       self.mapping.append (u"wxyz9WXYZ") # 9
                elif self.lang == 'es_ES':
-                       self.mapping.append (".,?'\"0-()@/:_") # 0
-                       self.mapping.append (" 1") # 1
-                       self.mapping.append ("abcáà2ABCÁÀ") # 2
-                       self.mapping.append ("deéèf3DEFÉÈ") # 3
-                       self.mapping.append ("ghiíì4GHIÍÌ") # 4
-                       self.mapping.append ("jkl5JKL") # 5
-                       self.mapping.append ("mnñoóò6MNÑOÓÒ") # 6
-                       self.mapping.append ("pqrs7PQRS") # 7
-                       self.mapping.append ("tuvúù8TUVÚÙ") # 8
-                       self.mapping.append ("wxyz9WXYZ") # 9
+                       self.mapping.append (u".,?'\"0-()@/:_") # 0
+                       self.mapping.append (u" 1") # 1
+                       self.mapping.append (u"abcáà2ABCÁÀ") # 2
+                       self.mapping.append (u"deéèf3DEFÉÈ") # 3
+                       self.mapping.append (u"ghiíì4GHIÍÌ") # 4
+                       self.mapping.append (u"jkl5JKL") # 5
+                       self.mapping.append (u"mnñoóò6MNÑOÓÒ") # 6
+                       self.mapping.append (u"pqrs7PQRS") # 7
+                       self.mapping.append (u"tuvúù8TUVÚÙ") # 8
+                       self.mapping.append (u"wxyz9WXYZ") # 9
                else:
-                       self.mapping.append (".,?'\"0-()@/:_") # 0
-                       self.mapping.append (" 1") # 1
-                       self.mapping.append ("abc2ABC") # 2
-                       self.mapping.append ("def3DEF") # 3
-                       self.mapping.append ("ghi4GHI") # 4
-                       self.mapping.append ("jkl5JKL") # 5
-                       self.mapping.append ("mno6MNO") # 6
-                       self.mapping.append ("pqrs7PQRS") # 7
-                       self.mapping.append ("tuv8TUV") # 8
-                       self.mapping.append ("wxyz9WXYZ") # 9
-               
-               self.nextFunction = nextFunction
-               self.Timer = eTimer()
-               self.Timer.timeout.get().append(self.nextChar)
+                       self.mapping.append (u".,?'\"0-()@/:_") # 0
+                       self.mapping.append (u" 1") # 1
+                       self.mapping.append (u"abc2ABC") # 2
+                       self.mapping.append (u"def3DEF") # 3
+                       self.mapping.append (u"ghi4GHI") # 4
+                       self.mapping.append (u"jkl5JKL") # 5
+                       self.mapping.append (u"mno6MNO") # 6
+                       self.mapping.append (u"pqrs7PQRS") # 7
+                       self.mapping.append (u"tuv8TUV") # 8
+                       self.mapping.append (u"wxyz9WXYZ") # 9
+
+               if handleTimeout:
+                       self.timer = eTimer()
+                       self.timer.timeout.get().append(self.timeout)
+               else:
+                       self.timer = None
                self.lastKey = -1
-               self.pos = 0
+               self.pos = -1
+
+       def setUseableChars(self, useable):
+               self.useableChars = useable
 
        def getKey(self, num):
-               self.Timer.stop()
-               self.Timer.start(1000)
-               if (self.lastKey != num):
+               cnt=0
+               if self.timer is not None:
+                       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):
+                       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):
-               self.Timer.stop()
+               if self.timer is not None:
+                       self.timer.stop()
                self.lastKey = -1
 
        def nextChar(self):
-               self.Timer.stop()
-               print "Timer done"
-               try:
-                       self.nextKey()
-                       if (self.nextFunction != None):
-                               self.nextFunction()
-               except:
-                       pass
+               self.nextKey()
+               if self.nextFunction:
+                       self.nextFunction()
+
+       def timeout(self):
+               self.nextChar()