1 from Screens.Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.Label import Label
4 from Components.ChoiceList import ChoiceEntryComponent, ChoiceList
6 class ChoiceBox(Screen):
7 def __init__(self, session, title = "", list = [], keys = None, selection = 0):
8 Screen.__init__(self, session)
10 self["text"] = Label(title)
13 self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
15 self.__keys = keys + (len(list) - len(keys)) * [""]
20 strpos = str(self.__keys[pos])
21 self.list.append(ChoiceEntryComponent(key = strpos, text = x))
22 if self.__keys[pos] != "":
23 self.keymap[self.__keys[pos]] = list[pos]
25 self["list"] = ChoiceList(list = self.list, selection = selection)
27 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
31 "1": self.keyNumberGlobal,
32 "2": self.keyNumberGlobal,
33 "3": self.keyNumberGlobal,
34 "4": self.keyNumberGlobal,
35 "5": self.keyNumberGlobal,
36 "6": self.keyNumberGlobal,
37 "7": self.keyNumberGlobal,
38 "8": self.keyNumberGlobal,
39 "9": self.keyNumberGlobal,
40 "0": self.keyNumberGlobal,
42 "green": self.keyGreen,
43 "yellow": self.keyYellow,
56 if len(self["list"].list) > 0:
58 self["list"].instance.moveSelection(self["list"].instance.moveUp)
59 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
63 if len(self["list"].list) > 0:
65 self["list"].instance.moveSelection(self["list"].instance.moveDown)
66 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
69 # runs a number shortcut
70 def keyNumberGlobal(self, number):
71 self.goKey(str(number))
73 # runs the current selected entry
75 cursel = self["list"].l.getCurrentSelection()
77 self.goEntry(cursel[0])
81 # runs a specific entry
82 def goEntry(self, entry):
83 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
84 # CALLFUNC wants to have the current selection as argument
85 arg = self["list"].l.getCurrentSelection()[0]
90 # lookups a key in the keymap, then runs it
92 if self.keymap.has_key(key):
93 entry = self.keymap[key]
96 # runs a color shortcut