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
8 class ChoiceBox(Screen):
9 def __init__(self, session, title = "", list = [], keys = None, selection = 0):
10 Screen.__init__(self, session)
12 self["text"] = Label(title)
15 self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
17 self.__keys = keys + (len(list) - len(keys)) * [""]
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]
27 self["list"] = ChoiceList(list = self.list, selection = selection)
29 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
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,
44 "green": self.keyGreen,
45 "yellow": self.keyYellow,
58 if len(self["list"].list) > 0:
60 self["list"].instance.moveSelection(self["list"].instance.moveUp)
61 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
65 if len(self["list"].list) > 0:
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:
71 # runs a number shortcut
72 def keyNumberGlobal(self, number):
73 self.goKey(str(number))
75 # runs the current selected entry
77 self.goEntry(self["list"].l.getCurrentSelection()[0])
79 # runs a specific entry
80 def goEntry(self, entry):
81 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
82 # CALLFUNC wants to have the current selection as argument
83 arg = self["list"].l.getCurrentSelection()[0]
88 # lookups a key in the keymap, then runs it
90 if self.keymap.has_key(key):
91 entry = self.keymap[key]
94 # runs a color shortcut