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, skin_name = []):
9 Screen.__init__(self, session)
11 if isinstance(skin_name, str):
12 skin_name = [skin_name]
13 self.skinName = skin_name + ["ChoiceBox"]
15 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]
30 self.summarylist.append((self.__keys[pos],x[0]))
32 self["list"] = ChoiceList(list = self.list, selection = selection)
33 self["summary_list"] = StaticText()
36 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
40 "1": self.keyNumberGlobal,
41 "2": self.keyNumberGlobal,
42 "3": self.keyNumberGlobal,
43 "4": self.keyNumberGlobal,
44 "5": self.keyNumberGlobal,
45 "6": self.keyNumberGlobal,
46 "7": self.keyNumberGlobal,
47 "8": self.keyNumberGlobal,
48 "9": self.keyNumberGlobal,
49 "0": self.keyNumberGlobal,
51 "green": self.keyGreen,
52 "yellow": self.keyYellow,
65 if len(self["list"].list) > 0:
67 self["list"].instance.moveSelection(self["list"].instance.moveUp)
68 self.updateSummary(self["list"].l.getCurrentSelectionIndex())
69 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
73 if len(self["list"].list) > 0:
75 self["list"].instance.moveSelection(self["list"].instance.moveDown)
76 self.updateSummary(self["list"].l.getCurrentSelectionIndex())
77 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
80 # runs a number shortcut
81 def keyNumberGlobal(self, number):
82 self.goKey(str(number))
84 # runs the current selected entry
86 cursel = self["list"].l.getCurrentSelection()
88 self.goEntry(cursel[0])
92 # runs a specific entry
93 def goEntry(self, entry):
94 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
95 # CALLFUNC wants to have the current selection as argument
96 arg = self["list"].l.getCurrentSelection()[0]
101 # lookups a key in the keymap, then runs it
102 def goKey(self, key):
103 if self.keymap.has_key(key):
104 entry = self.keymap[key]
107 # runs a color shortcut
120 def updateSummary(self, curpos=0):
123 for entry in self.summarylist:
124 if pos > curpos-2 and pos < curpos+5:
128 summarytext += entry[0]
129 summarytext += ' ' + entry[1] + '\n'
131 self["summary_list"].setText(summarytext)