some keyboard fixes (thanks to luke_s)
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 29 Jun 2006 22:58:04 +0000 (22:58 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Thu, 29 Jun 2006 22:58:04 +0000 (22:58 +0000)
data/keymap.xml
lib/python/Components/Input.py
lib/python/Screens/InputBox.py

index 41b7dda..047e074 100644 (file)
                <key id="2" mapto="moveDown" flags="mr" />
        </map>
        
-       <map context="InputActions">
+       <map context="KeyboardInputActions">
                <key id="KEY_LEFT" mapto="moveLeft" flags="mr" />
                <key id="KEY_RIGHT" mapto="moveRight" flags="mr" />
                <key id="KEY_HOME" mapto="moveHome" flags="mr" />
                <key id="KEY_END" mapto="moveEnd" flags="mr" />
                <key id="KEY_DELETE" mapto="deleteForward" flags="mr" />
                <key id="KEY_BACKSPACE" mapto="deleteBackward" flags="mr" />
-               
+               <key id="KEY_TAB" mapto="tab" flags="mr" />
                <key id="KEY_INSERT" mapto="toggleOverwrite" flags="m" />
                <key id="KEY_ENTER" mapto="accept" flags="m" />
        </map>
index e6e27fa..b140ef5 100644 (file)
@@ -19,8 +19,8 @@ class Input(VariableText, HTMLComponent, GUIComponent):
                self.maxSize = maxSize
                self.currPos = 0
                self.Text = text
+               self.overwrite = 0
                self.update()
-
        def update(self):
                self.setMarkedPos(self.currPos)
                if self.type == self.PIN:
@@ -79,14 +79,45 @@ class Input(VariableText, HTMLComponent, GUIComponent):
                        newNumber = str(int(self.Text[self.currPos]) - 1)
                self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
                self.update()
-
+               
+       def home(self):
+               self.currPos = 0
+               self.update()
+       
+       def end(self):
+               self.currPos = len(self.Text) - 1
+               self.update()
+               
+       def tab(self):
+               if self.currPos == len(self.Text) - 1:
+                       self.Text=self.Text+ " "
+                       self.end()
+               else:
+                       self.Text = self.Text[0:self.currPos] + " " + self.Text[self.currPos:]
+               self.update()
+               
        def delete(self):
                self.Text = self.Text[:self.currPos] + self.Text[self.currPos + 1:]
                self.update()
+               
+       def toggleOverwrite(self):
+               if self.overwrite==1:
+                       self.overwrite=0
+               else:
+                       self.overwrite=1
+               self.update()
+
+       def deleteBackward(self):
+               self.Text = self.Text[:self.currPos - 1] + self.Text[self.currPos:]
+               self.left()
+               self.update()
 
        def handleAscii(self, code):
                newChar = chr(code)
-               self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
+               if self.overwrite==1:
+                       self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
+               else:
+                       self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos:]
                self.right()
 
        def number(self, number):
index 9d54135..558cbc0 100644 (file)
@@ -14,8 +14,8 @@ class InputBox(Screen):
 
                self["text"] = Label(title)
                self["input"] = Input(**kwargs)
-                               
-               self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions"], 
+
+               self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"], 
                {
                        "gotAsciiCode": self.gotAsciiCode,
                        "ok": self.go,
@@ -23,6 +23,15 @@ class InputBox(Screen):
                        "left": self.keyLeft,
                        "right": self.keyRight,
                        "delete": self.keyDelete,
+                       "moveLeft": self.keyLeft,
+                       "moveRight": self.keyRight,
+                       "moveHome": self.keyHome,
+                       "moveEnd": self.keyEnd,
+                       "deleteForward": self.keyDelete,
+                       "deleteBackward": self.keyBackspace,
+                       "tab": self.keyTab,
+                       "toggleOverwrite": self.keyInsert,
+                       "accept": self.go,
                        "1": self.keyNumberGlobal,
                        "2": self.keyNumberGlobal,
                        "3": self.keyNumberGlobal,
@@ -42,22 +51,37 @@ class InputBox(Screen):
 
        def keyLeft(self):
                self["input"].left()
-       
+
        def keyRight(self):
                self["input"].right()
-       
+
        def keyNumberGlobal(self, number):
                self["input"].number(number)
-               
+
        def keyDelete(self):
                self["input"].delete()
-               
+
        def go(self):
                rcinput = eRCInput.getInstance()
                rcinput.setKeyboardMode(rcinput.kmNone)
                self.close(self["input"].getText())
-               
+
        def cancel(self):
                rcinput = eRCInput.getInstance()
                rcinput.setKeyboardMode(rcinput.kmNone)
                self.close(None)
+
+       def keyHome(self):
+               self["input"].home()
+
+       def keyEnd(self):
+               self["input"].end()
+
+       def keyBackspace(self):
+               self["input"].deleteBackward()
+
+       def keyTab(self):
+               self["input"].tab()
+
+       def keyInsert(self):
+               self["input"].toggleOverwrite()