5 # some helper classes first:
13 def __init__(self, order):
16 def produceHTML(self):
18 for name in self.order:
19 res += self[name].produceHTML()
27 def createGUIScreen(self, parent):
28 for (name, val) in self.items():
29 if isinstance(val, GUIComponent):
30 val.GUIcreate(parent, None)
32 def deleteGUIScreen(self):
33 for (name, val) in self.items():
34 if isinstance(val, GUIComponent):
41 # note: you'll probably run into this assert. if this happens, don't panic!
42 # yes, it's evil. I told you that programming in python is just fun, and
43 # suddently, you have to care about things you don't even know.
45 # but calm down, the solution is easy, at least on paper:
47 # Each Component, which is a GUIComponent, owns references to each
48 # instantiated eWidget (namely in screen.data[name]["instance"], in case
50 # on deleteGUIscreen, all eWidget *must* (!) be deleted (otherwise,
51 # well, problems appear. I don't want to go into details too much,
52 # but this would be a memory leak anyway.)
53 # The assert beyond checks for that. It asserts that the corresponding
54 # eWidget is about to be removed (i.e., that the refcount becomes 0 after
55 # running deleteGUIscreen).
56 # (You might wonder why the refcount is checked for 2 and not for 1 or 0 -
57 # one reference is still hold by the local variable 'w', another one is
58 # hold be the function argument to sys.getrefcount itself. So only if it's
59 # 2 at this point, the object will be destroyed after leaving deleteGUIscreen.)
61 # Now, how to fix this problem? You're holding a reference somewhere. (References
62 # can only be hold from Python, as eWidget itself isn't related to the c++
63 # way of having refcounted objects. So it must be in python.)
65 # It could be possible that you're calling deleteGUIscreen trough a call of
66 # a PSignal. For example, you could try to call screen.doClose() in response
67 # to a Button::click. This will fail. (It wouldn't work anyway, as you would
68 # remove a dialog while running it. It never worked - enigma1 just set a
69 # per-mainloop variable on eWidget::close() to leave the exec()...)
70 # That's why Session supports delayed closes. Just call Session.close() and
73 # Another reason is that you just stored the data["instance"] somewhere. or
74 # added it into a notifier list and didn't removed it.
76 # If you can't help yourself, just ask me. I'll be glad to help you out.
77 # Sorry for not keeping this code foolproof. I really wanted to archive
78 # that, but here I failed miserably. All I could do was to add this assert.
79 # assert sys.getrefcount(w) == 2, "too many refs hold to " + str(w)
82 self.deleteGUIScreen()
97 """VariableText can be used for components which have a variable text, based on any widget with setText call"""
103 def setText(self, text):
106 self.instance.setText(self.message)
111 def GUIcreate(self, parent, skindata):
112 self.instance = self.createWidget(parent, skindata)
113 self.instance.setText(self.message)
116 self.removeWidget(self.instance)
119 def removeWidget(self, instance):
123 """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
129 def setValue(self, value):
132 self.instance.setValue(self.value)
137 def GUIcreate(self, parent, skindata):
138 self.instance = self.createWidget(parent, skindata)
139 self.instance.setValue(self.value)
142 self.removeWidget(self.instance)
145 def removeWidget(self, instance):
148 # now some "real" components:
150 class Clock(HTMLComponent, GUIComponent, VariableText):
152 VariableText.__init__(self)
153 GUIComponent.__init__(self)
156 self.clockTimer = eTimer()
157 self.clockTimer.timeout.get().append(self.doClock)
158 self.clockTimer.start(1000)
162 self.setText("clock: " + time.asctime())
164 # realisierung als GUI
165 def createWidget(self, parent, skindata):
166 return eLabel(parent)
168 def removeWidget(self, w):
172 def produceHTML(self):
173 return self.getText()
175 class Button(HTMLComponent, GUIComponent, VariableText):
176 def __init__(self, text="", onClick = [ ]):
177 GUIComponent.__init__(self)
178 VariableText.__init__(self)
180 self.onClick = onClick
183 for x in self.onClick:
188 # self.instance.hide()
192 # self.instance.show()
196 def produceHTML(self):
197 return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
200 def createWidget(self, parent, skindata):
202 g.selected.get().append(self.push)
205 def removeWidget(self, w):
206 w.selected.get().remove(self.push)
208 class Label(HTMLComponent, GUIComponent, VariableText):
209 def __init__(self, text=""):
210 GUIComponent.__init__(self)
211 VariableText.__init__(self)
215 def produceHTML(self):
216 return self.getText()
219 def createWidget(self, parent, skindata):
220 return eLabel(parent)
222 class Header(HTMLComponent, GUIComponent, VariableText):
224 def __init__(self, message):
225 GUIComponent.__init__(self)
226 VariableText.__init__(self)
227 self.setText(message)
229 def produceHTML(self):
230 return "<h2>" + self.getText() + "</h2>\n"
232 def createWidget(self, parent, skindata):
236 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
239 GUIComponent.__init__(self)
240 VariableValue.__init__(self)
242 def createWidget(self, parent, skindata):
247 # a general purpose progress bar
248 class ProgressBar(HTMLComponent, GUIComponent, VariableValue):
250 GUIComponent.__init__(self)
251 VariableValue.__init__(self)
253 def createWidget(self, parent, skindata):
258 class MenuList(HTMLComponent, GUIComponent):
259 def __init__(self, list):
260 GUIComponent.__init__(self)
261 self.l = eListboxPythonStringContent()
264 def getCurrent(self):
265 return self.l.getCurrentSelection()
267 def GUIcreate(self, parent, skindata):
268 self.instance = eListbox(parent)
269 self.instance.setContent(self.l)
272 self.instance.setContent(None)
274 class ServiceList(HTMLComponent, GUIComponent):
276 GUIComponent.__init__(self)
277 self.l = eListboxServiceContent()
279 def getCurrent(self):
280 r = eServiceReference()
284 def GUIcreate(self, parent, skindata):
285 self.instance = eListbox(parent)
286 self.instance.setContent(self.l)
291 def setRoot(self, root):
301 def scanStatusChanged(self):
302 if self.state == self.Running:
303 self.progressbar.setValue(self.scan.getProgress())
304 if self.scan.isDone():
305 self.state = self.Done
307 self.text.setText("scan in progress - %d %% done!\n%d services found!" % (self.scan.getProgress(), self.scan.getNumServices()))
309 if self.state == self.Done:
310 self.text.setText("scan done!")
312 if self.state == self.Error:
313 self.text.setText("ERROR - failed to scan!")
315 def __init__(self, progressbar, text):
316 self.progressbar = progressbar
318 self.scan = eComponentScan()
319 if self.scan.start():
320 self.state = self.Error
322 self.state = self.Running
323 self.scan.statusChanged.get().append(self.scanStatusChanged)
324 self.scanStatusChanged()
327 return self.state == self.Done
330 self.scan.statusChanged.get().remove(self.scanStatusChanged)
333 def __init__(self, context, actions = { }, prio=0):
334 self.actions = actions
335 self.context = context
337 self.p = eActionMapPtr()
338 eActionMap.getInstance(self.p)
341 self.p.bindAction(self.context, self.prio, self.action)
344 self.p.unbindAction(self.context, self.action)
346 def action(self, context, action):
348 self.actions[action]()
350 print "unknown action %s/%s! typo in keymap?" % (context, action)
352 class PerServiceDisplay(GUIComponent, VariableText):
353 """Mixin for building components which display something which changes on navigation events, for example "service name" """
355 def __init__(self, navcore, eventmap):
356 GUIComponent.__init__(self)
357 VariableText.__init__(self)
358 self.eventmap = eventmap
359 navcore.m_event.get().append(self.event)
360 self.navcore = navcore
362 # start with stopped state, so simulate that
363 self.event(pNavigation.evStopService)
366 # loop up if we need to handle this event
367 if self.eventmap.has_key(ev):
371 def createWidget(self, parent, skindata):
372 # by default, we use a label to display our data.
376 class EventInfo(PerServiceDisplay):
379 def __init__(self, navcore, now_or_next):
380 # listen to evUpdatedEventInfo and evStopService
381 # note that evStopService will be called once to establish a known state
382 PerServiceDisplay.__init__(self, navcore,
384 pNavigation.evUpdatedEventInfo: self.ourEvent,
385 pNavigation.evStopService: self.stopEvent
387 self.now_or_next = now_or_next
390 info = iServiceInformationPtr()
391 service = iPlayableServicePtr()
393 if not self.navcore.getCurrentService(service):
394 if not service.info(info):
396 ev = eServiceEventPtr()
397 info.getEvent(ev, self.now_or_next)
398 self.setText(ev.m_event_name)
399 print "new event info in EventInfo! yeah!"
402 self.setText("waiting for event data...");
404 class ServiceName(PerServiceDisplay):
405 def __init__(self, navcore):
406 PerServiceDisplay.__init__(self, navcore,
408 pNavigation.evNewService: self.newService,
409 pNavigation.evStopService: self.stopEvent
412 def newService(self):
413 info = iServiceInformationPtr()
414 service = iPlayableServicePtr()
416 if not self.navcore.getCurrentService(service):
417 if not service.info(info):
418 self.setText("no name known, but it should be here :)")