ChoiceBox is now usable with number keys
[enigma2.git] / lib / python / Screens / ChoiceBox.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.MenuList import MenuList
7 from Components.GUIComponent import *
8 from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
9
10 import os
11
12 class ChoiceBox(Screen):
13         def __init__(self, session, title = "", list = [], keys = None):
14                 Screen.__init__(self, session)
15
16                 self["text"] = Label(title)
17                 self.list = []
18                 if keys is None:
19                         self.keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ] + (len(list) - 10) * [""]
20                 else:
21                         self.keys = keys
22                         
23                 self.keymap = {}
24                 pos = 0
25                 for x in list:
26                         strpos = str(self.keys[pos])
27                         self.list.append(ChoiceEntryComponent(strpos, x))
28                         if self.keys[pos] != "":
29                                 self.keymap[self.keys[pos]] = list[pos]
30                         pos += 1
31                 self["list"] = ChoiceList(self.list)
32                                 
33                 self["actions"] = NumberActionMap(["WizardActions", "InputActions"], 
34                 {
35                         "ok": self.go,
36                         "back": self.cancel,
37                         "1": self.keyNumberGlobal,
38                         "2": self.keyNumberGlobal,
39                         "3": self.keyNumberGlobal,
40                         "4": self.keyNumberGlobal,
41                         "5": self.keyNumberGlobal,
42                         "6": self.keyNumberGlobal,
43                         "7": self.keyNumberGlobal,
44                         "8": self.keyNumberGlobal,
45                         "9": self.keyNumberGlobal,
46                         "0": self.keyNumberGlobal
47                 }, -1)
48                 
49         def keyLeft(self):
50                 pass
51         
52         def keyRight(self):
53                 pass
54         
55         def keyNumberGlobal(self, number):
56                 print "pressed", number
57                 if self.keymap.has_key(str(number)):
58                         self.close(self.keymap[str(number)])
59                 
60         def go(self):
61                 self.close(self["list"].l.getCurrentSelection()[0])
62                 #self.close(self["input"].getText())
63                 
64         def cancel(self):
65                 self.close(None)