dont open epglist when no epg is avail
[enigma2.git] / lib / python / Screens / InfoBar.py
1 from Screen import Screen
2 from EpgSelection import EPGSelection
3 from ChannelSelection import ChannelSelection
4 from Components.Clock import Clock
5 from Components.ActionMap import ActionMap
6 from Components.ActionMap import NumberActionMap
7 from Components.Button import Button
8 from Components.ServiceName import ServiceName
9 from Components.EventInfo import EventInfo
10 from Components.ServicePosition import ServicePosition
11 from Components.config import configfile
12 from Components.Label import Label
13
14 from Screens.MessageBox import MessageBox
15 from Screens.MovieSelection import MovieSelection
16 from Screens.Volume import Volume
17 from Screens.Mute import Mute
18 from Screens.Standby import Standby
19
20 from enigma import *
21
22 import time
23
24 # hack alert!
25 from Menu import MainMenu, mdom
26
27 class NumberZap(Screen):
28         def quit(self):
29                 self.Timer.stop()
30                 self.close()
31
32         def keyOK(self):
33                 self.Timer.stop()
34                 print "do the action here"
35                 self.close()
36
37         def keyNumberGlobal(self, number):
38                 self.Timer.start(3000)          #reset timer
39                 self.field = self.field + str(number)
40                 self["number"].setText(self.field)
41                 if len(self.field) >= 4:
42                         self.keyOK()
43
44         def __init__(self, session, number):
45                 Screen.__init__(self, session)
46                 self.field = str(number)
47                 
48                 self["number"] = Label(self.field)
49
50                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
51                         {
52                                 "cancel": self.quit,
53                                 "ok": self.keyOK,
54                                 "1": self.keyNumberGlobal,
55                                 "2": self.keyNumberGlobal,
56                                 "3": self.keyNumberGlobal,
57                                 "4": self.keyNumberGlobal,
58                                 "5": self.keyNumberGlobal,
59                                 "6": self.keyNumberGlobal,
60                                 "7": self.keyNumberGlobal,
61                                 "8": self.keyNumberGlobal,
62                                 "9": self.keyNumberGlobal,
63                                 "0": self.keyNumberGlobal
64                         })
65
66                 self.Timer = eTimer()
67                 self.Timer.timeout.get().append(self.keyOK)
68                 self.Timer.start(3000)
69
70
71 class InfoBar(Screen):
72         STATE_HIDDEN = 0
73         STATE_HIDING = 1
74         STATE_SHOWING = 2
75         STATE_SHOWN = 3
76         
77         def __init__(self, session):
78                 Screen.__init__(self, session)
79
80                 #instantiate forever
81                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
82                 
83                 self.state = self.STATE_HIDDEN
84                 
85                 self.volumeDialog = self.session.instantiateDialog(Volume)
86                 self.muteDialog = self.session.instantiateDialog(Mute)
87                 
88                 self.hideTimer = eTimer()
89                 self.hideTimer.timeout.get().append(self.doTimerHide)
90                 #self.hideTimer.start(1000)
91                 
92                 self.hideVolTimer = eTimer()
93                 self.hideVolTimer.timeout.get().append(self.volHide)
94
95                 #self["actions"] = ActionMap( [ "InfobarActions" ], 
96                 self["actions"] = NumberActionMap( [ "InfobarActions" ], 
97                         {
98                                 "switchChannelUp": self.switchChannelUp,
99                                 "switchChannelDown": self.switchChannelDown,
100                                 "mainMenu": self.mainMenu,
101                                 "zapUp": self.zapUp,
102                                 "zapDown": self.zapDown,
103                                 "volumeUp": self.volUp,
104                                 "volumeDown": self.volDown,
105                                 "volumeMute": self.volMute,
106                                 "instantRecord": self.instantRecord,
107                                 "hide": self.hide,
108                                 "toggleShow": self.toggleShow,
109                                 "showMovies": self.showMovies,
110                                 "quit": self.quit,
111                                 "1": self.keyNumberGlobal,
112                                 "2": self.keyNumberGlobal,
113                                 "3": self.keyNumberGlobal,
114                                 "4": self.keyNumberGlobal,
115                                 "5": self.keyNumberGlobal,
116                                 "6": self.keyNumberGlobal,
117                                 "7": self.keyNumberGlobal,
118                                 "8": self.keyNumberGlobal,
119                                 "9": self.keyNumberGlobal,
120                                 "0": self.keyNumberGlobal,
121                                 "showEPGList": self.showEPGList,
122                                 
123                                 "pauseService": self.pauseService,
124                                 "unPauseService": self.unPauseService,
125                         })
126 #               self["okbutton"] = Button("mainMenu", [self.mainMenu])
127                 
128                 self["CurrentTime"] = Clock()
129                 # ServicePosition(self.session.nav, ServicePosition.TYPE_REMAINING)
130                 # Clock()
131
132                 self["ServiceName"] = ServiceName(self.session.nav)
133                 
134                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
135                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
136                                 
137                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
138                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
139
140                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
141                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
142                 
143                 self.recording = None
144                 
145                 self.pos = 0
146         
147         def mainMenu(self):
148                 print "loading mainmenu XML..."
149                 menu = mdom.childNodes[0]
150                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
151                 self.session.open(MainMenu, menu, menu.childNodes)
152
153         def keyNumberGlobal(self, number):
154                 print "You pressed number " + str(number)
155                 self.session.open(NumberZap, number)
156
157         def switchChannelUp(self):      
158                 self.servicelist.moveUp()
159                 self.session.execDialog(self.servicelist)
160
161         def switchChannelDown(self):    
162                 self.servicelist.moveDown()
163                 self.session.execDialog(self.servicelist)
164
165         def hide(self): 
166                 self.instance.hide()
167
168         def doTimerHide(self):
169                 if self.state == self.STATE_SHOWN:
170                         self.instance.hide()
171                         self.state = self.STATE_HIDDEN
172
173         def toggleShow(self):
174                 if self.state == self.STATE_SHOWN:
175                         self.instance.hide()
176                         #pls check animation support, sorry
177 #                       self.startHide()
178                         self.state = self.STATE_HIDDEN
179                 else:
180                         self.instance.show()
181 #                       self.startShow()
182                         self.state = self.STATE_SHOWN
183                         #TODO: make it customizable
184                         self.hideTimer.start(5000)
185
186         def     zapUp(self):
187                 self.servicelist.moveUp()
188                 self.servicelist.zap()
189
190         def     zapDown(self):
191                 self.servicelist.moveDown()
192                 self.servicelist.zap()
193
194         def     volUp(self):
195                 eDVBVolumecontrol.getInstance().volumeUp()
196                 self.volumeDialog.instance.show()
197                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
198                 self.hideVolTimer.start(3000)
199
200         def     volDown(self):
201                 eDVBVolumecontrol.getInstance().volumeDown()
202                 self.volumeDialog.instance.show()
203                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
204                 self.hideVolTimer.start(3000)
205                 
206         def volHide(self):
207                 self.volumeDialog.instance.hide()
208
209         def startShow(self):
210                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
211                 self.state = self.STATE_SHOWN
212         
213         def startHide(self):
214                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
215                 self.state = self.STATE_HIDDEN
216
217         def     volMute(self):
218                 eDVBVolumecontrol.getInstance().volumeToggleMute()
219                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
220                 
221                 if (eDVBVolumecontrol.getInstance().isMuted()):
222                         self.muteDialog.instance.show()
223                 else:
224                         self.muteDialog.instance.hide()
225
226         def showEPGList(self):
227                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
228                 ptr=eEPGCache.getInstance()
229                 if ptr.startTimeQuery(ref) != -1:
230                         self.session.open(EPGSelection, ref)
231                 else:
232                         print 'no epg for service', ref.toString()
233
234         def quit(self):
235                 self.session.open(Standby)
236                 #configfile.save()
237                 #quitMainloop()
238         
239         def stopCurrentRecording(self): 
240                 print "remove entry"
241                 self.session.nav.RecordTimer.removeEntry(self.recording)
242                 self.recording = None
243         
244         def startInstantRecording(self):
245                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
246                         
247                 # try to get event info
248                 epg = None
249                 try:
250                         service = self.session.nav.getCurrentService()
251                         info = service.info()
252                         ev = info.getEvent(0)
253                         epg = ev
254                 except:
255                         pass
256                 
257                 # fix me, description. 
258                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
259
260         def recordQuestionCallback(self, answer):
261                 if answer == False:
262                         return
263                 
264                 if self.recording != None:
265                         self.stopCurrentRecording()
266                 else:
267                         self.startInstantRecording()
268
269         def instantRecord(self):
270                 if self.recording != None:
271                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
272                 else:
273                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
274
275         def showMovies(self):
276                 self.session.open(MovieSelection)
277
278         def pauseService(self):
279                 self.session.nav.pause(1)
280                 
281         def unPauseService(self):
282                 self.session.nav.pause(0)