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 # DIESER KOMMENTAR IST NUTZLOS UND MITTLERWEILE VERALTET! (glaub ich)
43 # note: you'll probably run into this assert. if this happens, don't panic!
44 # yes, it's evil. I told you that programming in python is just fun, and
45 # suddently, you have to care about things you don't even know.
47 # but calm down, the solution is easy, at least on paper:
49 # Each Component, which is a GUIComponent, owns references to each
50 # instantiated eWidget (namely in screen.data[name]["instance"], in case
52 # on deleteGUIscreen, all eWidget *must* (!) be deleted (otherwise,
53 # well, problems appear. I don't want to go into details too much,
54 # but this would be a memory leak anyway.)
55 # The assert beyond checks for that. It asserts that the corresponding
56 # eWidget is about to be removed (i.e., that the refcount becomes 0 after
57 # running deleteGUIscreen).
58 # (You might wonder why the refcount is checked for 2 and not for 1 or 0 -
59 # one reference is still hold by the local variable 'w', another one is
60 # hold be the function argument to sys.getrefcount itself. So only if it's
61 # 2 at this point, the object will be destroyed after leaving deleteGUIscreen.)
63 # Now, how to fix this problem? You're holding a reference somewhere. (References
64 # can only be hold from Python, as eWidget itself isn't related to the c++
65 # way of having refcounted objects. So it must be in python.)
67 # It could be possible that you're calling deleteGUIscreen trough a call of
68 # a PSignal. For example, you could try to call screen.doClose() in response
69 # to a Button::click. This will fail. (It wouldn't work anyway, as you would
70 # remove a dialog while running it. It never worked - enigma1 just set a
71 # per-mainloop variable on eWidget::close() to leave the exec()...)
72 # That's why Session supports delayed closes. Just call Session.close() and
75 # Another reason is that you just stored the data["instance"] somewhere. or
76 # added it into a notifier list and didn't removed it.
78 # If you can't help yourself, just ask me. I'll be glad to help you out.
79 # Sorry for not keeping this code foolproof. I really wanted to archive
80 # that, but here I failed miserably. All I could do was to add this assert.
81 # assert sys.getrefcount(w) == 2, "too many refs hold to " + str(w)
84 self.deleteGUIScreen()
99 """VariableText can be used for components which have a variable text, based on any widget with setText call"""
105 def setText(self, text):
108 self.instance.setText(self.message)
113 def GUIcreate(self, parent, skindata):
114 self.instance = self.createWidget(parent, skindata)
115 self.instance.setText(self.message)
118 self.removeWidget(self.instance)
121 def removeWidget(self, instance):
125 """VariableValue can be used for components which have a variable value (like eSlider), based on any widget with setValue call"""
131 def setValue(self, value):
134 self.instance.setValue(self.value)
139 def GUIcreate(self, parent, skindata):
140 self.instance = self.createWidget(parent, skindata)
141 self.instance.setValue(self.value)
144 self.removeWidget(self.instance)
147 def removeWidget(self, instance):
150 # now some "real" components:
152 class Clock(HTMLComponent, GUIComponent, VariableText):
154 VariableText.__init__(self)
155 GUIComponent.__init__(self)
158 self.clockTimer = eTimer()
159 self.clockTimer.timeout.get().append(self.doClock)
160 self.clockTimer.start(1000)
165 self.setText("%2d:%02d:%02d" % (t[3], t[4], t[5]))
167 # realisierung als GUI
168 def createWidget(self, parent, skindata):
169 return eLabel(parent)
171 def removeWidget(self, w):
175 def produceHTML(self):
176 return self.getText()
178 class Button(HTMLComponent, GUIComponent, VariableText):
179 def __init__(self, text="", onClick = [ ]):
180 GUIComponent.__init__(self)
181 VariableText.__init__(self)
183 self.onClick = onClick
186 for x in self.onClick:
191 # self.instance.hide()
195 # self.instance.show()
199 def produceHTML(self):
200 return "<input type=\"submit\" text=\"" + self.getText() + "\">\n"
203 def createWidget(self, parent, skindata):
205 g.selected.get().append(self.push)
208 def removeWidget(self, w):
209 w.selected.get().remove(self.push)
211 class Label(HTMLComponent, GUIComponent, VariableText):
212 def __init__(self, text=""):
213 GUIComponent.__init__(self)
214 VariableText.__init__(self)
218 def produceHTML(self):
219 return self.getText()
222 def createWidget(self, parent, skindata):
223 return eLabel(parent)
225 class Header(HTMLComponent, GUIComponent, VariableText):
227 def __init__(self, message):
228 GUIComponent.__init__(self)
229 VariableText.__init__(self)
230 self.setText(message)
232 def produceHTML(self):
233 return "<h2>" + self.getText() + "</h2>\n"
235 def createWidget(self, parent, skindata):
239 class VolumeBar(HTMLComponent, GUIComponent, VariableValue):
242 GUIComponent.__init__(self)
243 VariableValue.__init__(self)
245 def createWidget(self, parent, skindata):
250 # a general purpose progress bar
251 class ProgressBar(HTMLComponent, GUIComponent, VariableValue):
253 GUIComponent.__init__(self)
254 VariableValue.__init__(self)
256 def createWidget(self, parent, skindata):
261 class MenuList(HTMLComponent, GUIComponent):
262 def __init__(self, list):
263 GUIComponent.__init__(self)
264 self.l = eListboxPythonStringContent()
267 def getCurrent(self):
268 return self.l.getCurrentSelection()
270 def GUIcreate(self, parent, skindata):
271 self.instance = eListbox(parent)
272 self.instance.setContent(self.l)
275 self.instance.setContent(None)
281 def __init__(self, reg):
290 return ("NO", "YES", "MAYBE")[self.val]
293 def __init__(self, obj):
299 def configEntry(obj):
300 # das hier ist ein zugriff auf die registry...
301 if obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/SDTV/FLASHES/GREEN":
302 return ("SDTV green flashes", configBoolean(obj))
303 elif obj == "HKEY_LOCAL_ENIGMA/IMPORTANT/USER_ANNOYING_STUFF/HDTV/FLASHES/GREEN":
304 return ("HDTV reen flashes", configBoolean(obj))
306 return ("invalid", "")
308 class ConfigList(HTMLComponent, GUIComponent):
309 def __init__(self, list):
310 GUIComponent.__init__(self)
311 self.l = eListboxPythonConfigContent()
313 self.l.setSeperation(100)
316 selection = self.getCurrent()
317 selection[1].toggle()
318 self.invalidateCurrent()
320 def getCurrent(self):
321 return self.l.getCurrentSelection()
323 def invalidateCurrent(self):
324 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
326 def GUIcreate(self, parent, skindata):
327 self.instance = eListbox(parent)
328 self.instance.setContent(self.l)
331 self.instance.setContent(None)
334 class ServiceList(HTMLComponent, GUIComponent):
336 GUIComponent.__init__(self)
337 self.l = eListboxServiceContent()
339 def getCurrent(self):
340 r = eServiceReference()
345 self.instance.moveSelection(self.instance.moveUp)
348 self.instance.moveSelection(self.instance.moveDown)
350 def GUIcreate(self, parent, skindata):
351 self.instance = eListbox(parent)
352 self.instance.setContent(self.l)
357 def setRoot(self, root):
361 def clearMarked(self):
364 def isMarked(self, ref):
365 return self.l.isMarked(ref)
367 def addMarked(self, ref):
368 self.l.addMarked(ref)
370 def removeMarked(self, ref):
371 self.l.removeMarked(ref)
381 0: "error starting scanning",
382 1: "error while scanning",
383 2: "no resource manager",
387 def scanStatusChanged(self):
388 if self.state == self.Running:
389 self.progressbar.setValue(self.scan.getProgress())
390 if self.scan.isDone():
391 errcode = self.scan.getError()
394 self.state = self.Done
396 self.state = self.Error
397 self.errorcode = errcode
399 self.text.setText("scan in progress - %d %% done!\n%d services found!" % (self.scan.getProgress(), self.scan.getNumServices()))
401 if self.state == self.Done:
402 self.text.setText("scan done!")
404 if self.state == self.Error:
405 self.text.setText("ERROR - failed to scan (%s)!" % (self.Errors[self.errorcode]) )
407 def __init__(self, progressbar, text):
408 self.progressbar = progressbar
410 self.scan = eComponentScan()
411 self.state = self.Idle
412 self.scanStatusChanged()
415 self.scan.statusChanged.get().append(self.scanStatusChanged)
416 self.state = self.Running
417 err = self.scan.start()
419 self.state = self.Error
422 self.scanStatusChanged()
425 self.scan.statusChanged.get().remove(self.scanStatusChanged)
426 if not self.isDone():
427 print "*** warning *** scan was not finished!"
430 print "state is %d " % (self.state)
431 return self.state == self.Done or self.state == self.Error
434 def __init__(self, contexts = [ ], actions = { }, prio=0):
435 self.actions = actions
436 self.contexts = contexts
438 self.p = eActionMapPtr()
439 eActionMap.getInstance(self.p)
442 for ctx in self.contexts:
443 self.p.bindAction(ctx, self.prio, self.action)
446 for ctx in self.contexts:
447 self.p.unbindAction(ctx, self.action)
449 def action(self, context, action):
450 print " ".join(("action -> ", context, action))
451 if self.actions.has_key(action):
452 self.actions[action]()
454 print "unknown action %s/%s! typo in keymap?" % (context, action)
456 class PerServiceDisplay(GUIComponent, VariableText):
457 """Mixin for building components which display something which changes on navigation events, for example "service name" """
459 def __init__(self, navcore, eventmap):
460 GUIComponent.__init__(self)
461 VariableText.__init__(self)
462 self.eventmap = eventmap
463 navcore.m_event.get().append(self.event)
464 self.navcore = navcore
466 # start with stopped state, so simulate that
467 self.event(pNavigation.evStopService)
470 # loop up if we need to handle this event
471 if self.eventmap.has_key(ev):
475 def createWidget(self, parent, skindata):
476 # by default, we use a label to display our data.
480 class EventInfo(PerServiceDisplay):
486 def __init__(self, navcore, now_or_next):
487 # listen to evUpdatedEventInfo and evStopService
488 # note that evStopService will be called once to establish a known state
489 self.now_or_next = now_or_next
490 PerServiceDisplay.__init__(self, navcore,
492 pNavigation.evUpdatedEventInfo: self.ourEvent,
493 pNavigation.evStopService: self.stopEvent
497 info = iServiceInformationPtr()
498 service = iPlayableServicePtr()
500 if not self.navcore.getCurrentService(service):
501 if not service.info(info):
502 ev = eServiceEventPtr()
503 info.getEvent(ev, self.now_or_next & 1)
504 if self.now_or_next & 2:
505 self.setText("%d min" % (ev.m_duration / 60))
507 self.setText(ev.m_event_name)
508 print "new event info in EventInfo! yeah!"
512 ("waiting for event data...", "", "--:--", "--:--")[self.now_or_next]);
514 class ServiceName(PerServiceDisplay):
515 def __init__(self, navcore):
516 PerServiceDisplay.__init__(self, navcore,
518 pNavigation.evNewService: self.newService,
519 pNavigation.evStopService: self.stopEvent
522 def newService(self):
523 info = iServiceInformationPtr()
524 service = iPlayableServicePtr()
526 if not self.navcore.getCurrentService(service):
527 if not service.info(info):
528 self.setText("no name known, but it should be here :)")