+ def execBegin(self):
+ for ctx in self.contexts:
+ self.p.bindAction(ctx, self.prio, self.action)
+
+ def execEnd(self):
+ for ctx in self.contexts:
+ self.p.unbindAction(ctx, self.action)
+
+ def action(self, context, action):
+ print " ".join(("action -> ", context, action))
+ try:
+ self.actions[action]()
+ except KeyError:
+ print "unknown action %s/%s! typo in keymap?" % (context, action)
+
+class PerServiceDisplay(GUIComponent, VariableText):
+ """Mixin for building components which display something which changes on navigation events, for example "service name" """
+
+ def __init__(self, navcore, eventmap):
+ GUIComponent.__init__(self)
+ VariableText.__init__(self)
+ self.eventmap = eventmap
+ navcore.m_event.get().append(self.event)
+ self.navcore = navcore
+
+ # start with stopped state, so simulate that
+ self.event(pNavigation.evStopService)
+
+ def event(self, ev):
+ # loop up if we need to handle this event
+ if self.eventmap.has_key(ev):
+ # call handler
+ self.eventmap[ev]()
+
+ def createWidget(self, parent, skindata):
+ # by default, we use a label to display our data.
+ g = eLabel(parent)
+ return g
+
+class EventInfo(PerServiceDisplay):
+ Now = 0
+ Next = 1
+ Now_Duration = 2
+ Next_Duration = 3
+
+ def __init__(self, navcore, now_or_next):
+ # listen to evUpdatedEventInfo and evStopService
+ # note that evStopService will be called once to establish a known state
+ self.now_or_next = now_or_next
+ PerServiceDisplay.__init__(self, navcore,
+ {
+ pNavigation.evUpdatedEventInfo: self.ourEvent,
+ pNavigation.evStopService: self.stopEvent
+ })
+
+ def ourEvent(self):
+ info = iServiceInformationPtr()
+ service = iPlayableServicePtr()
+
+ if not self.navcore.getCurrentService(service):
+ if not service.info(info):
+ ev = eServiceEventPtr()
+ info.getEvent(ev, self.now_or_next & 1)
+ if self.now_or_next & 2:
+ self.setText("%d min" % (ev.m_duration / 60))
+ else:
+ self.setText(ev.m_event_name)
+ print "new event info in EventInfo! yeah!"
+
+ def stopEvent(self):
+ self.setText(
+ ("waiting for event data...", "", "--:--", "--:--")[self.now_or_next]);
+
+class ServiceName(PerServiceDisplay):
+ def __init__(self, navcore):
+ PerServiceDisplay.__init__(self, navcore,
+ {
+ pNavigation.evNewService: self.newService,
+ pNavigation.evStopService: self.stopEvent
+ })
+
+ def newService(self):
+ info = iServiceInformationPtr()
+ service = iPlayableServicePtr()
+
+ if not self.navcore.getCurrentService(service):
+ if not service.info(info):
+ self.setText("no name known, but it should be here :)")
+
+ def stopEvent(self):
+ self.setText("");