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.lcd_xres=self.readlcdxres()
16 self["text"] = Label(title)
20 self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
22 self.__keys = keys + (len(list) - len(keys)) * [""]
27 strpos = str(self.__keys[pos])
28 self.list.append(ChoiceEntryComponent(key = strpos, text = x))
29 if self.__keys[pos] != "":
30 self.keymap[self.__keys[pos]] = list[pos]
31 self.summarylist.append((self.__keys[pos],x[0]))
33 self["list"] = ChoiceList(list = self.list, selection = selection)
34 self["summary_list"] = StaticText()
35 self.updateSummary(selection)
37 self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"],
41 "1": self.keyNumberGlobal,
42 "2": self.keyNumberGlobal,
43 "3": self.keyNumberGlobal,
44 "4": self.keyNumberGlobal,
45 "5": self.keyNumberGlobal,
46 "6": self.keyNumberGlobal,
47 "7": self.keyNumberGlobal,
48 "8": self.keyNumberGlobal,
49 "9": self.keyNumberGlobal,
50 "0": self.keyNumberGlobal,
52 "green": self.keyGreen,
53 "yellow": self.keyYellow,
66 if len(self["list"].list) > 0:
68 self["list"].instance.moveSelection(self["list"].instance.moveUp)
69 self.updateSummary(self["list"].l.getCurrentSelectionIndex())
70 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
74 if len(self["list"].list) > 0:
76 self["list"].instance.moveSelection(self["list"].instance.moveDown)
77 self.updateSummary(self["list"].l.getCurrentSelectionIndex())
78 if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
81 # runs a number shortcut
82 def keyNumberGlobal(self, number):
83 self.goKey(str(number))
85 # runs the current selected entry
87 cursel = self["list"].l.getCurrentSelection()
89 self.goEntry(cursel[0])
93 # runs a specific entry
94 def goEntry(self, entry):
95 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
96 # CALLFUNC wants to have the current selection as argument
97 arg = self["list"].l.getCurrentSelection()[0]
102 # lookups a key in the keymap, then runs it
103 def goKey(self, key):
104 if self.keymap.has_key(key):
105 entry = self.keymap[key]
108 # runs a color shortcut
121 def updateSummary(self, curpos=0):
124 for entry in self.summarylist:
125 if self.lcd_xres is not None and self.lcd_xres > 140:
126 if pos > curpos-2 and pos < curpos+5:
130 summarytext += entry[0]
131 summarytext += ' ' + entry[1] + '\n'
134 summarytext += entry[0]+' '+ entry[1]
136 self["summary_list"].setText(summarytext)
141 def readlcdxres(self):
143 fd = open("/proc/stb/lcd/xres","r")
144 value = int(fd.read().strip(),16)