2 def __init__(self, steal_current_service = False):
3 if steal_current_service:
4 ServiceEventTracker.setActiveInfoBar(self, None, None)
7 ServiceEventTracker.setActiveInfoBar(self, not steal_current_service and nav.getCurrentService(), nav.getCurrentlyPlayingServiceReference())
8 self.onClose.append(self.__close)
11 ServiceEventTracker.popActiveInfoBar()
13 class ServiceEventTracker:
14 """Tracks service events into a screen"""
19 def __init__(self, screen, eventmap):
20 self.__eventmap = eventmap
22 screen.session.nav.event.append(self.__event)
23 screen.onClose.append(self.__del_event)
25 def __del_event(self):
26 self.screen.session.nav.event.remove(self.__event)
28 def __event(self, ev):
29 set = ServiceEventTracker
31 nav = screen.session.nav
32 cur_ref = nav.getCurrentlyPlayingServiceReference()
33 old_service_running = set.oldRef and cur_ref and cur_ref == set.oldRef and set.oldService and set.oldService == str(nav.getCurrentService())
34 if not old_service_running:
37 # print "old_service_running", old_service_running
38 if ev in self.__eventmap:
39 ssize = set.InfoBarStackSize
40 stack = set.InfoBarStack
41 if (not isinstance(screen, InfoBarBase) or # let pass all events to screens not derived from InfoBarBase
42 (not old_service_running and ssize and stack[ssize-1] == screen) or # let pass events from currently running service just to current active screen (derived from InfoBarBase)
43 (old_service_running and ssize > 1 and stack[ssize-2] == screen)): # let pass events from old running service just to previous active screen (derived from InfoBarBase)
46 # print "ignore event", ev, "for inactive infobar '" + str(self.screen) + "'"
49 def setActiveInfoBar(infobar, old_service, old_ref):
50 set = ServiceEventTracker
52 set.oldService = old_service and str(old_service)
53 assert infobar not in set.InfoBarStack, "FATAL: Infobar '" + str(infobar) + "' is already active!"
54 set.InfoBarStack.append(infobar)
55 set.InfoBarStackSize += 1
56 # print "ServiceEventTracker set active '" + str(infobar) + "'"
59 def popActiveInfoBar():
60 set = ServiceEventTracker
61 stack = set.InfoBarStack
62 if set.InfoBarStackSize:
63 set.InfoBarStackSize -= 1
64 del stack[set.InfoBarStackSize]
65 # if set.InfoBarStackSize:
66 # print "ServiceEventTracker reset active '" + str(stack[set.InfoBarStackSize-1]) + "'"