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.oldService and set.oldService == str(nav.getCurrentService())
29 # print "old_service_running", old_service_running
30 if not old_service_running and set.oldService:
33 ssize = set.InfoBarStackSize
34 stack = set.InfoBarStack
35 for func in func_list:
36 if (func[0] or # let pass all events to screens not derived from InfoBarBase
37 (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)
38 (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 # print "ignore event", ev, "for inactive infobar '" + str(self.screen) + "'"
44 def setActiveInfoBar(infobar, old_service, old_ref):
45 set = ServiceEventTracker
47 set.oldService = old_service and str(old_service)
48 assert infobar not in set.InfoBarStack, "FATAL: Infobar '" + str(infobar) + "' is already active!"
49 set.InfoBarStack.append(infobar)
50 set.InfoBarStackSize += 1
51 # print "ServiceEventTracker set active '" + str(infobar) + "'"
54 def popActiveInfoBar():
55 set = ServiceEventTracker
56 stack = set.InfoBarStack
57 if set.InfoBarStackSize:
58 set.InfoBarStackSize -= 1
59 del stack[set.InfoBarStackSize]
60 # if set.InfoBarStackSize:
61 # print "ServiceEventTracker reset active '" + str(stack[set.InfoBarStackSize-1]) + "'"
63 def __init__(self, screen, eventmap):
64 self.__screen = screen
65 self.__eventmap = eventmap
66 self.__passall = not isinstance(screen, InfoBarBase) # let pass all events to screens not derived from InfoBarBase
67 EventMap = ServiceEventTracker.EventMap
69 screen.session.nav.event.append(ServiceEventTracker.event)
70 ServiceEventTracker.navcore = screen.session.nav
71 EventMap = EventMap.setdefault
72 for x in eventmap.iteritems():
73 EventMap(x[0], []).append((self.__passall, screen, x[1]))
74 screen.onClose.append(self.__del_event)
76 def __del_event(self):
77 EventMap = ServiceEventTracker.EventMap.setdefault
78 for x in self.__eventmap.iteritems():
79 EventMap(x[0], []).remove((self.__passall, self.__screen, x[1]))