move __init__ to top
[enigma2.git] / lib / python / Screens / InputBox.py
1 from enigma import *
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import NumberActionMap
5 from Components.Label import Label
6 from Components.Input import Input
7 from Components.GUIComponent import *
8
9 import os
10
11 class InputBox(Screen):
12         def __init__(self, session, title = "", **kwargs):
13                 Screen.__init__(self, session)
14
15                 self["text"] = Label(title)
16                 self["input"] = Input(**kwargs)
17
18                 self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"], 
19                 {
20                         "gotAsciiCode": self.gotAsciiCode,
21                         "ok": self.go,
22                         "back": self.cancel,
23                         "left": self.keyLeft,
24                         "right": self.keyRight,
25                         "delete": self.keyDelete,
26                         "moveLeft": self.keyLeft,
27                         "moveRight": self.keyRight,
28                         "moveHome": self.keyHome,
29                         "moveEnd": self.keyEnd,
30                         "deleteForward": self.keyDelete,
31                         "deleteBackward": self.keyBackspace,
32                         "tab": self.keyTab,
33                         "toggleOverwrite": self.keyInsert,
34                         "accept": self.go,
35                         "1": self.keyNumberGlobal,
36                         "2": self.keyNumberGlobal,
37                         "3": self.keyNumberGlobal,
38                         "4": self.keyNumberGlobal,
39                         "5": self.keyNumberGlobal,
40                         "6": self.keyNumberGlobal,
41                         "7": self.keyNumberGlobal,
42                         "8": self.keyNumberGlobal,
43                         "9": self.keyNumberGlobal,
44                         "0": self.keyNumberGlobal
45                 }, -1)
46                 rcinput = eRCInput.getInstance()
47                 rcinput.setKeyboardMode(rcinput.kmAscii)
48
49         def gotAsciiCode(self):
50                 self["input"].handleAscii(getPrevAsciiCode())
51
52         def keyLeft(self):
53                 self["input"].left()
54
55         def keyRight(self):
56                 self["input"].right()
57
58         def keyNumberGlobal(self, number):
59                 self["input"].number(number)
60
61         def keyDelete(self):
62                 self["input"].delete()
63
64         def go(self):
65                 rcinput = eRCInput.getInstance()
66                 rcinput.setKeyboardMode(rcinput.kmNone)
67                 self.close(self["input"].getText())
68
69         def cancel(self):
70                 rcinput = eRCInput.getInstance()
71                 rcinput.setKeyboardMode(rcinput.kmNone)
72                 self.close(None)
73
74         def keyHome(self):
75                 self["input"].home()
76
77         def keyEnd(self):
78                 self["input"].end()
79
80         def keyBackspace(self):
81                 self["input"].deleteBackward()
82
83         def keyTab(self):
84                 self["input"].tab()
85
86         def keyInsert(self):
87                 self["input"].toggleOverwrite()