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