|
@@ -1,233 +0,0 @@
|
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
|
6
|
|
-from Components.Pixmap import Pixmap
|
7
|
|
-import enigma
|
8
|
|
-
|
9
|
|
-class ChoiceBox2(Screen):
|
10
|
|
- skin = """
|
11
|
|
-<screen name="ChoiceBox2" position="center,center" size="720,480" title="ChoiceBox" zPosition="5">
|
12
|
|
- <widget name="text" position="0,0" size="720,0" font="Regular;30"/>
|
13
|
|
- <widget name="list" font="Regular;22" position="10,10" size="710,460" scrollbarMode="showOnDemand" enableWrapAround="1"/>
|
14
|
|
- <applet type="onLayoutFinish">
|
15
|
|
- self["list"].instance.setItemHeight(25)
|
16
|
|
- </applet>
|
17
|
|
-
|
18
|
|
-</screen>
|
19
|
|
-"""
|
20
|
|
- #<applet type="onLayoutFinish">
|
21
|
|
- #self.autoResize()
|
22
|
|
- #</applet>
|
23
|
|
-
|
24
|
|
- def __init__(self, session, title="", list=None, keys=None, selection=0, skin_name=None, text=""):
|
25
|
|
- Screen.__init__(self, session)
|
26
|
|
- #self.setTitle(_("Choice Box"))
|
27
|
|
- if not list: list = []
|
28
|
|
- if not skin_name: skin_name = []
|
29
|
|
- #if isinstance(skin_name, str):
|
30
|
|
- # skin_name = [skin_name]
|
31
|
|
- #self.skinName = skin_name + ["ChoiceBox"]
|
32
|
|
- self["text"] = Label()
|
33
|
|
- self.var = ""
|
34
|
|
-
|
35
|
|
- if title:
|
36
|
|
- title = _(title)
|
37
|
|
- if len(title) < 55 and title.find('\n') == -1:
|
38
|
|
- Screen.setTitle(self, title)
|
39
|
|
- elif title.find('\n') != -1:
|
40
|
|
- temptext = title.split('\n')
|
41
|
|
- if len(temptext[0]) < 55:
|
42
|
|
- Screen.setTitle(self, temptext[0])
|
43
|
|
- count = 2
|
44
|
|
- labeltext = ""
|
45
|
|
- while len(temptext) >= count:
|
46
|
|
- if labeltext:
|
47
|
|
- labeltext += '\n'
|
48
|
|
- labeltext = labeltext + temptext[count-1]
|
49
|
|
- count += 1
|
50
|
|
- print 'count',count
|
51
|
|
- self["text"].setText(labeltext)
|
52
|
|
- else:
|
53
|
|
- self["text"] = Label(title)
|
54
|
|
- else:
|
55
|
|
- self["text"] = Label(title)
|
56
|
|
- elif text:
|
57
|
|
- self["text"] = Label(_(text))
|
58
|
|
- self.list = []
|
59
|
|
- self.summarylist = []
|
60
|
|
- if keys is None:
|
61
|
|
- self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
|
62
|
|
- else:
|
63
|
|
- self.__keys = keys + (len(list) - len(keys)) * [""]
|
64
|
|
-
|
65
|
|
- self.keymap = {}
|
66
|
|
- pos = 0
|
67
|
|
- for x in list:
|
68
|
|
- strpos = str(self.__keys[pos])
|
69
|
|
- self.list.append(ChoiceEntryComponent(key = strpos, text = x))
|
70
|
|
- if self.__keys[pos] != "":
|
71
|
|
- self.keymap[self.__keys[pos]] = list[pos]
|
72
|
|
- self.summarylist.append((self.__keys[pos], x[0]))
|
73
|
|
- pos += 1
|
74
|
|
- self["list"] = ChoiceList(list = self.list, selection = selection)
|
75
|
|
- self["summary_list"] = StaticText()
|
76
|
|
- self["summary_selection"] = StaticText()
|
77
|
|
- self.updateSummary(selection)
|
78
|
|
-
|
79
|
|
- self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions"],
|
80
|
|
- {
|
81
|
|
- "ok": self.go,
|
82
|
|
- "1": self.keyNumberGlobal,
|
83
|
|
- "2": self.keyNumberGlobal,
|
84
|
|
- "3": self.keyNumberGlobal,
|
85
|
|
- "4": self.keyNumberGlobal,
|
86
|
|
- "5": self.keyNumberGlobal,
|
87
|
|
- "6": self.keyNumberGlobal,
|
88
|
|
- "7": self.keyNumberGlobal,
|
89
|
|
- "8": self.keyNumberGlobal,
|
90
|
|
- "9": self.keyNumberGlobal,
|
91
|
|
- "0": self.keyNumberGlobal,
|
92
|
|
- "red": self.keyRed,
|
93
|
|
- "green": self.keyGreen,
|
94
|
|
- "yellow": self.keyYellow,
|
95
|
|
- "blue": self.keyBlue,
|
96
|
|
- "up": self.up,
|
97
|
|
- "down": self.down,
|
98
|
|
- "left": self.left,
|
99
|
|
- "right": self.right
|
100
|
|
- }, -1)
|
101
|
|
-
|
102
|
|
- self["cancelaction"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions"],
|
103
|
|
- {
|
104
|
|
- "back": self.cancel,
|
105
|
|
- }, -1)
|
106
|
|
- #self.onShown.append(self.onshow)
|
107
|
|
-
|
108
|
|
- def autoResize(self):
|
109
|
|
- desktop_w = enigma.getDesktop(0).size().width()
|
110
|
|
- desktop_h = enigma.getDesktop(0).size().height()
|
111
|
|
- count = len(self.list)
|
112
|
|
- itemheight = self["list"].getItemHeight()
|
113
|
|
- if count > 15:
|
114
|
|
- count = 15
|
115
|
|
- if not self["text"].text:
|
116
|
|
- # move list
|
117
|
|
- textsize = (520, 0)
|
118
|
|
- listsize = (520, itemheight*count)
|
119
|
|
- self["list"].instance.move(enigma.ePoint(0, 0))
|
120
|
|
- self["list"].instance.resize(enigma.eSize(*listsize))
|
121
|
|
- else:
|
122
|
|
- textsize = self["text"].getSize()
|
123
|
|
- if textsize[0] < textsize[1]:
|
124
|
|
- textsize = (textsize[1],textsize[0]+10)
|
125
|
|
- if textsize[0] > 520:
|
126
|
|
- textsize = (textsize[0], textsize[1]+itemheight)
|
127
|
|
- else:
|
128
|
|
- textsize = (520, textsize[1]+itemheight)
|
129
|
|
- listsize = (textsize[0], itemheight*count)
|
130
|
|
- # resize label
|
131
|
|
- self["text"].instance.resize(enigma.eSize(*textsize))
|
132
|
|
- self["text"].instance.move(enigma.ePoint(10, 10))
|
133
|
|
- # move list
|
134
|
|
- self["list"].instance.move(enigma.ePoint(0, textsize[1]))
|
135
|
|
- self["list"].instance.resize(enigma.eSize(*listsize))
|
136
|
|
-
|
137
|
|
- wsizex = textsize[0]
|
138
|
|
- wsizey = textsize[1]+listsize[1]
|
139
|
|
- wsize = (wsizex, wsizey)
|
140
|
|
- self.instance.resize(enigma.eSize(*wsize))
|
141
|
|
-
|
142
|
|
- # center window
|
143
|
|
- self.instance.move(enigma.ePoint((desktop_w-wsizex)/2, (desktop_h-wsizey)/2))
|
144
|
|
-
|
145
|
|
- def left(self):
|
146
|
|
- if len(self["list"].list) > 0:
|
147
|
|
- while 1:
|
148
|
|
- self["list"].instance.moveSelection(self["list"].instance.pageUp)
|
149
|
|
- self.updateSummary(self["list"].l.getCurrentSelectionIndex())
|
150
|
|
- if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
|
151
|
|
- break
|
152
|
|
-
|
153
|
|
- def right(self):
|
154
|
|
- if len(self["list"].list) > 0:
|
155
|
|
- while 1:
|
156
|
|
- self["list"].instance.moveSelection(self["list"].instance.pageDown)
|
157
|
|
- self.updateSummary(self["list"].l.getCurrentSelectionIndex())
|
158
|
|
- if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
|
159
|
|
- break
|
160
|
|
-
|
161
|
|
- def up(self):
|
162
|
|
- if len(self["list"].list) > 0:
|
163
|
|
- while 1:
|
164
|
|
- self["list"].instance.moveSelection(self["list"].instance.moveUp)
|
165
|
|
- self.updateSummary(self["list"].l.getCurrentSelectionIndex())
|
166
|
|
- if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0:
|
167
|
|
- break
|
168
|
|
-
|
169
|
|
- def down(self):
|
170
|
|
- if len(self["list"].list) > 0:
|
171
|
|
- while 1:
|
172
|
|
- self["list"].instance.moveSelection(self["list"].instance.moveDown)
|
173
|
|
- self.updateSummary(self["list"].l.getCurrentSelectionIndex())
|
174
|
|
- if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1:
|
175
|
|
- break
|
176
|
|
-
|
177
|
|
- # runs a number shortcut
|
178
|
|
- def keyNumberGlobal(self, number):
|
179
|
|
- self.goKey(str(number))
|
180
|
|
-
|
181
|
|
- # runs the current selected entry
|
182
|
|
- def go(self):
|
183
|
|
- cursel = self["list"].l.getCurrentSelection()
|
184
|
|
- if cursel:
|
185
|
|
- self.goEntry(cursel[0])
|
186
|
|
- else:
|
187
|
|
- self.cancel()
|
188
|
|
-
|
189
|
|
- # runs a specific entry
|
190
|
|
- def goEntry(self, entry):
|
191
|
|
- if entry and len(entry) > 3 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
|
192
|
|
- arg = entry[3]
|
193
|
|
- entry[2](arg)
|
194
|
|
- elif entry and len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
|
195
|
|
- entry[2](None)
|
196
|
|
- else:
|
197
|
|
- self.close(entry)
|
198
|
|
-
|
199
|
|
- # lookups a key in the keymap, then runs it
|
200
|
|
- def goKey(self, key):
|
201
|
|
- if self.keymap.has_key(key):
|
202
|
|
- entry = self.keymap[key]
|
203
|
|
- self.goEntry(entry)
|
204
|
|
-
|
205
|
|
- # runs a color shortcut
|
206
|
|
- def keyRed(self):
|
207
|
|
- self.goKey("red")
|
208
|
|
-
|
209
|
|
- def keyGreen(self):
|
210
|
|
- self.goKey("green")
|
211
|
|
-
|
212
|
|
- def keyYellow(self):
|
213
|
|
- self.goKey("yellow")
|
214
|
|
-
|
215
|
|
- def keyBlue(self):
|
216
|
|
- self.goKey("blue")
|
217
|
|
-
|
218
|
|
- def updateSummary(self, curpos=0):
|
219
|
|
- pos = 0
|
220
|
|
- summarytext = ""
|
221
|
|
- for entry in self.summarylist:
|
222
|
|
- if curpos-2 < pos < curpos+5:
|
223
|
|
- if pos == curpos:
|
224
|
|
- summarytext += ">"
|
225
|
|
- self["summary_selection"].setText(entry[1])
|
226
|
|
- else:
|
227
|
|
- summarytext += entry[0]
|
228
|
|
- summarytext += ' ' + entry[1] + '\n'
|
229
|
|
- pos += 1
|
230
|
|
- self["summary_list"].setText(summarytext)
|
231
|
|
-
|
232
|
|
- def cancel(self):
|
233
|
|
- self.close(None)
|