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
5 from Components.Sources.StaticText import StaticText
7 class ChoiceBox(Screen):
8 def __init__(self, session, title = "", list = [], keys = None, selection = 0):
9 Screen.__init__(self, session)
11 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]
26 self.summarylist.append((self.__keys[pos],x[0]))
28 self["list"] = ChoiceList(list = self.list, selection = selection)
29 self["summary_list"] = StaticText()
32 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
36 "1": self.keyNumberGlobal,
37 "2": self.keyNumberGlobal,
38 "3": self.keyNumberGlobal,
39 "4": self.keyNumberGlobal,
40 "5": self.keyNumberGlobal,
41 "6": self.keyNumberGlobal,
42 "7": self.keyNumberGlobal,
43 "8": self.keyNumberGlobal,
44 "9": self.keyNumberGlobal,
45 "0": self.keyNumberGlobal,
47 "green": self.keyGreen,
48 "yellow": self.keyYellow,
61 if len(self["list"].list) > 0:
63 self["list"].instance.moveSelection(self["list"].instance.moveUp)
64 self.updateSummary(self["list"].l.getCurrentSelectionIndex())
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 self.updateSummary(self["list"].l.getCurrentSelectionIndex())
73 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
76 # runs a number shortcut
77 def keyNumberGlobal(self, number):
78 self.goKey(str(number))
80 # runs the current selected entry
82 cursel = self["list"].l.getCurrentSelection()
84 self.goEntry(cursel[0])
88 # runs a specific entry
89 def goEntry(self, entry):
90 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
91 # CALLFUNC wants to have the current selection as argument
92 arg = self["list"].l.getCurrentSelection()[0]
97 # lookups a key in the keymap, then runs it
99 if self.keymap.has_key(key):
100 entry = self.keymap[key]
103 # runs a color shortcut
116 def updateSummary(self, curpos=0):
119 for entry in self.summarylist:
120 if pos > curpos-2 and pos < curpos+5:
124 summarytext += entry[0]
125 summarytext += ' ' + entry[1] + '\n'
127 self["summary_list"].setText(summarytext)