deliver service events only to last created class which is based on
[enigma2.git] / lib / python / Screens / SubservicesQuickzap.py
1 from Screens.Screen import Screen
2 from Components.ActionMap import NumberActionMap
3 from Components.Label import Label
4
5 from Screens.ChoiceBox import ChoiceBox
6 from Screens.MessageBox import MessageBox
7 from InfoBarGenerics import InfoBarShowHide, InfoBarMenu, InfoBarInstantRecord, InfoBarTimeshift, InfoBarSeek, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, InfoBarAudioSelection
8
9 from enigma import eTimer
10
11 class SubservicesQuickzap(InfoBarShowHide, InfoBarMenu, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarExtensions, InfoBarSubtitleSupport, InfoBarAudioSelection, Screen):
12         def __init__(self, session, subservices):
13                 Screen.__init__(self, session)
14                 for x in [InfoBarShowHide, InfoBarMenu, InfoBarInstantRecord, InfoBarSeek, InfoBarTimeshift, InfoBarTimeshiftState, InfoBarSubtitleSupport, InfoBarExtensions, InfoBarAudioSelection]:
15                         x.__init__(self)
16
17                 self.restoreService = self.session.nav.getCurrentlyPlayingServiceReference()
18                 
19                 self["CurrentSubserviceNumber"] = Label("")
20                 self.currentSubserviceNumberLabel = self["CurrentSubserviceNumber"]
21                 
22                 self.updateSubservices()
23                 self.currentlyPlayingSubservice = 0
24
25                 self.timer = eTimer()
26                 self.timer.callback.append(self.playSubservice)
27                 self.onLayoutFinish.append(self.onLayoutFinished)
28
29                 self["actions"] = NumberActionMap( [ "InfobarSubserviceQuickzapActions", "NumberActions", "DirectionActions", "ColorActions" ], 
30                         {
31                                 "up": self.showSelection,
32                                 "down": self.showSelection,
33                                 "right": self.nextSubservice,
34                                 "left": self.previousSubservice,
35                                 "green": self.showSelection,
36                                 "exit": self.quitQuestion,
37                                 "1": self.keyNumberGlobal,
38                                 "2": self.keyNumberGlobal,
39                                 "3": self.keyNumberGlobal,
40                                 "4": self.keyNumberGlobal,
41                                 "5": self.keyNumberGlobal,
42                                 "6": self.keyNumberGlobal,
43                                 "7": self.keyNumberGlobal,
44                                 "8": self.keyNumberGlobal,
45                                 "9": self.keyNumberGlobal,
46                                 "0": self.keyNumberGlobal
47                         }, 0)
48
49         def onLayoutFinished(self):
50                 self.timer.start(0,True)
51
52         def updateSubservices(self):
53                 self.service = self.session.nav.getCurrentService()
54                 self.subservices = self.service and self.service.subServices()
55                 self.n = self.subservices and self.subservices.getNumberOfSubservices()
56         
57         def nextSubservice(self):
58                 self.updateSubservices()
59                 if self.n:
60                         if self.currentlyPlayingSubservice >= self.n - 1:
61                                 self.playSubservice(0)
62                         else:
63                                 self.playSubservice(self.currentlyPlayingSubservice + 1)
64         
65         def previousSubservice(self):
66                 self.updateSubservices()
67                 if self.n:
68                         if self.currentlyPlayingSubservice > self.n:
69                                 self.currentlyPlayingSubservice = self.n
70                         if self.currentlyPlayingSubservice == 0:
71                                 self.playSubservice(self.n - 1)
72                         else:
73                                 self.playSubservice(self.currentlyPlayingSubservice - 1)
74
75         def getSubserviceIndex(self, service):
76                 self.updateSubservices()
77                 if self.n is None:
78                         return -1
79                 for x in range(self.n):
80                         if service == self.subservices.getSubservice(x):
81                                 return x
82         
83         def keyNumberGlobal(self, number):
84                 print number, "pressed"
85                 self.updateSubservices()
86                 if number == 0:
87                         self.playSubservice(self.lastservice)
88                 elif self.n is not None and number <= self.n - 1:
89                         self.playSubservice(number)
90         
91         def showSelection(self):
92                 self.updateSubservices()
93                 tlist = []
94                 if self.n is not None:
95                         for x in range(self.n):
96                                 i = self.subservices.getSubservice(x)
97                                 tlist.append((i.getName(), x))
98
99                 keys = [ "", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * self.n
100                 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice..."), list = tlist, selection = self.currentlyPlayingSubservice, keys = keys)
101         
102         def subserviceSelected(self, service):
103                 print "playing subservice number", service
104                 if service is not None:
105                         self.playSubservice(service[1])
106         
107         def keyOK(self):
108                 pass
109         
110         def quitQuestion(self):
111                 self.session.openWithCallback(self.quit, MessageBox, _("Really exit the subservices quickzap?"))
112         
113         def quit(self, answer):
114                 if answer:
115                         self.session.nav.playService(self.restoreService)
116                         self.close()
117                 
118         def playSubservice(self, number = 0):
119                 newservice = self.subservices.getSubservice(number)
120                 if newservice.valid():
121                         del self.subservices
122                         del self.service
123                         self.lastservice = self.currentlyPlayingSubservice
124                         self.session.nav.playService(newservice)
125                         self.currentlyPlayingSubservice = number
126                         self.currentSubserviceNumberLabel.setText(str(number))
127                         self.doShow()