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
12 class ChoiceBox(Screen):
13 def __init__(self, session, title = "", list = [], keys = None, selection = 0):
14 Screen.__init__(self, session)
16 self["text"] = Label(title)
19 self.keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
21 self.keys = keys + (len(list) - len(keys)) * [""]
26 strpos = str(self.keys[pos])
27 self.list.append(ChoiceEntryComponent(key = strpos, text = x))
28 if self.keys[pos] != "":
29 self.keymap[self.keys[pos]] = list[pos]
31 self["list"] = ChoiceList(list = self.list, selection = selection)
33 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
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,
48 "green": self.keyGreen,
49 "yellow": self.keyYellow,
62 if len(self["list"].list) > 0:
64 self["list"].instance.moveSelection(self["list"].instance.moveUp)
65 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
69 if len(self["list"].list) > 0:
71 self["list"].instance.moveSelection(self["list"].instance.moveDown)
72 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
76 def keyNumberGlobal(self, number):
77 print "pressed", number
78 if self.keymap.has_key(str(number)):
79 self.close(self.keymap[str(number)])
82 if len(self["list"].list) > 0:
83 self.close(self["list"].l.getCurrentSelection()[0])
88 if self.keymap.has_key("red"):
89 self.close(self.keymap["red"])
92 if self.keymap.has_key("green"):
93 self.close(self.keymap["green"])
96 if self.keymap.has_key("yellow"):
97 self.close(self.keymap["yellow"])
100 if self.keymap.has_key("blue"):
101 self.close(self.keymap["blue"])