revert to 750ms delay for motor powerup.. 200ms is not really enough
[enigma2.git] / lib / python / Screens / ChoiceBox.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
5 from Components.MenuList import MenuList
6 from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
7
8 class ChoiceBox(Screen):
9         def __init__(self, session, title = "", list = [], keys = None, selection = 0):
10                 Screen.__init__(self, session)
11
12                 self["text"] = Label(title)
13                 self.list = []
14                 if keys is None:
15                         self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
16                 else:
17                         self.__keys = keys + (len(list) - len(keys)) * [""]
18                         
19                 self.keymap = {}
20                 pos = 0
21                 for x in list:
22                         strpos = str(self.__keys[pos])
23                         self.list.append(ChoiceEntryComponent(key = strpos, text = x))
24                         if self.__keys[pos] != "":
25                                 self.keymap[self.__keys[pos]] = list[pos]
26                         pos += 1
27                 self["list"] = ChoiceList(list = self.list, selection = selection)
28                                 
29                 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"], 
30                 {
31                         "ok": self.go,
32                         "back": self.cancel,
33                         "1": self.keyNumberGlobal,
34                         "2": self.keyNumberGlobal,
35                         "3": self.keyNumberGlobal,
36                         "4": self.keyNumberGlobal,
37                         "5": self.keyNumberGlobal,
38                         "6": self.keyNumberGlobal,
39                         "7": self.keyNumberGlobal,
40                         "8": self.keyNumberGlobal,
41                         "9": self.keyNumberGlobal,
42                         "0": self.keyNumberGlobal,
43                         "red": self.keyRed,
44                         "green": self.keyGreen,
45                         "yellow": self.keyYellow,
46                         "blue": self.keyBlue,
47                         "up": self.up,
48                         "down": self.down
49                 }, -1)
50                 
51         def keyLeft(self):
52                 pass
53         
54         def keyRight(self):
55                 pass
56         
57         def up(self):
58                 if len(self["list"].list) > 0:
59                         while 1:
60                                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
61                                 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
62                                         break
63
64         def down(self):
65                 if len(self["list"].list) > 0:
66                         while 1:
67                                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
68                                 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
69                                         break
70
71         # runs a number shortcut
72         def keyNumberGlobal(self, number):
73                 self.goKey(str(number))
74
75         # runs the current selected entry
76         def go(self):
77                 cursel = self["list"].l.getCurrentSelection()
78                 if cursel:
79                         self.goEntry(cursel[0])
80                 else:
81                         self.cancel()
82
83         # runs a specific entry
84         def goEntry(self, entry):
85                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
86                         # CALLFUNC wants to have the current selection as argument
87                         arg = self["list"].l.getCurrentSelection()[0]
88                         entry[2](arg)
89                 else:
90                         self.close(entry)
91
92         # lookups a key in the keymap, then runs it
93         def goKey(self, key):
94                 if self.keymap.has_key(key):
95                         entry = self.keymap[key]
96                         self.goEntry(entry)
97
98         # runs a color shortcut
99         def keyRed(self):
100                 self.goKey("red")
101
102         def keyGreen(self):
103                 self.goKey("green")
104
105         def keyYellow(self):
106                 self.goKey("yellow")
107
108         def keyBlue(self):
109                 self.goKey("blue")
110
111         def cancel(self):
112                 self.close(None)