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"""
23 set = ServiceEventTracker
24 func_list = set.EventMap.setdefault(evt, [])
27 cur_ref = nav.getCurrentlyPlayingServiceReference()
28 old_service_running = set.oldRef and cur_ref and cur_ref == set.oldRef and set.oldServiceStr == nav.getCurrentService().getPtrString()
29 if not old_service_running and set.oldServiceStr:
30 set.oldServiceStr = None
32 ssize = set.InfoBarStackSize
33 stack = set.InfoBarStack
34 for func in func_list:
35 if (func[0] or # let pass all events to screens not derived from InfoBarBase
36 (not old_service_running and stack[ssize-1] == func[1]) or # let pass events from currently running service just to current active screen (derived from InfoBarBase)
37 (old_service_running and ssize > 1 and stack[ssize-2] == func[1])): # let pass events from old running service just to previous active screen (derived from InfoBarBase)
41 def setActiveInfoBar(infobar, old_service, old_ref):
42 set = ServiceEventTracker
44 set.oldServiceStr = old_service and old_service.getPtrString()
45 assert infobar not in set.InfoBarStack, "FATAL: Infobar '" + str(infobar) + "' is already active!"
46 set.InfoBarStack.append(infobar)
47 set.InfoBarStackSize += 1
48 # print "ServiceEventTracker set active '" + str(infobar) + "'"
51 def popActiveInfoBar():
52 set = ServiceEventTracker
53 stack = set.InfoBarStack
54 if set.InfoBarStackSize:
56 set.InfoBarStackSize -= 1
57 del stack[set.InfoBarStackSize]
58 old_service = nav.getCurrentService()
59 set.oldServiceStr = old_service and old_service.getPtrString()
60 set.oldRef = nav.getCurrentlyPlayingServiceReference()
61 # if set.InfoBarStackSize:
62 # print "ServiceEventTracker reset active '" + str(stack[set.InfoBarStackSize-1]) + "'"
64 def __init__(self, screen, eventmap):
65 self.__screen = screen
66 self.__eventmap = eventmap
67 self.__passall = not isinstance(screen, InfoBarBase) # let pass all events to screens not derived from InfoBarBase
68 EventMap = ServiceEventTracker.EventMap
70 screen.session.nav.event.append(ServiceEventTracker.event)
71 ServiceEventTracker.navcore = screen.session.nav
72 EventMap = EventMap.setdefault
73 for x in eventmap.iteritems():
74 EventMap(x[0], []).append((self.__passall, screen, x[1]))
75 screen.onClose.append(self.__del_event)
77 def __del_event(self):
78 EventMap = ServiceEventTracker.EventMap.setdefault
79 for x in self.__eventmap.iteritems():
80 EventMap(x[0], []).remove((self.__passall, self.__screen, x[1]))