b218950d309545853fa6ca9d3f7b4f583565e2a9
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.ActionMap import NumberActionMap
4 from Components.Label import Label
5 from Components.config import configfile
6 from ChannelSelection import ChannelSelection
7
8 from Components.ServiceName import ServiceName
9 from Components.EventInfo import EventInfo
10
11 from EpgSelection import EPGSelection
12
13 from Screens.MessageBox import MessageBox
14 from Screens.Volume import Volume
15 from Screens.Mute import Mute
16 from Screens.Standby import Standby
17
18 #from enigma import eTimer, eDVBVolumecontrol, quitMainloop
19 from enigma import *
20
21 import time
22
23 # hack alert!
24 from Menu import MainMenu, mdom
25
26 class InfoBarVolumeControl:
27         """Volume control, handles volUp, volDown, volMute actions and display 
28         a corresponding dialog"""
29         
30         def __init__(self):
31                 self["VolumeActions"] = ActionMap( ["InfobarVolumeActions"] ,
32                         {
33                                 "volumeUp": self.volUp,
34                                 "volumeDown": self.volDown,
35                                 "volumeMute": self.volMute,
36                         })
37
38                 self.volumeDialog = self.session.instantiateDialog(Volume)
39                 self.muteDialog = self.session.instantiateDialog(Mute)
40
41                 self.hideVolTimer = eTimer()
42                 self.hideVolTimer.timeout.get().append(self.volHide)
43         
44         def     volUp(self):
45                 eDVBVolumecontrol.getInstance().volumeUp()
46                 self.volumeDialog.instance.show()
47                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
48                 self.hideVolTimer.start(3000)
49
50         def     volDown(self):
51                 eDVBVolumecontrol.getInstance().volumeDown()
52                 self.volumeDialog.instance.show()
53                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
54                 self.hideVolTimer.start(3000)
55                 
56         def volHide(self):
57                 self.volumeDialog.instance.hide()
58
59         def     volMute(self):
60                 eDVBVolumecontrol.getInstance().volumeToggleMute()
61                 self.volumeDialog.setValue(eDVBVolumecontrol.getInstance().getVolume())
62                 
63                 if (eDVBVolumecontrol.getInstance().isMuted()):
64                         self.muteDialog.instance.show()
65                 else:
66                         self.muteDialog.instance.hide()
67
68 class InfoBarShowHide:
69         """ InfoBar show/hide control, accepts toggleShow and hide actions, might start
70         fancy animations. """
71         STATE_HIDDEN = 0
72         STATE_HIDING = 1
73         STATE_SHOWING = 2
74         STATE_SHOWN = 3
75         
76         def __init__(self):
77                 self["ShowHideActions"] = ActionMap( ["InfobarShowHideActions"] ,
78                         {
79                                 "toggleShow": self.toggleShow,
80                                 "hide": self.hide,
81                         })
82
83                 self.state = self.STATE_HIDDEN
84                 
85                 self.hideTimer = eTimer()
86                 self.hideTimer.timeout.get().append(self.doTimerHide)
87                 #self.hideTimer.start(1000)
88
89         def hide(self): 
90                 self.instance.hide()
91
92         def doTimerHide(self):
93                 if self.state == self.STATE_SHOWN:
94                         self.instance.hide()
95                         self.state = self.STATE_HIDDEN
96
97         def toggleShow(self):
98                 if self.state == self.STATE_SHOWN:
99                         self.instance.hide()
100                         #pls check animation support, sorry
101 #                       self.startHide()
102                         self.state = self.STATE_HIDDEN
103                 else:
104                         self.instance.show()
105 #                       self.startShow()
106                         self.state = self.STATE_SHOWN
107                         #TODO: make it customizable
108                         self.hideTimer.start(5000)
109
110         def startShow(self):
111                 self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
112                 self.state = self.STATE_SHOWN
113         
114         def startHide(self):
115                 self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
116                 self.state = self.STATE_HIDDEN
117
118 class NumberZap(Screen):
119         def quit(self):
120                 self.Timer.stop()
121                 self.close()
122
123         def keyOK(self):
124                 self.Timer.stop()
125                 print "do the action here"
126                 self.close()
127
128         def keyNumberGlobal(self, number):
129                 self.Timer.start(3000)          #reset timer
130                 self.field = self.field + str(number)
131                 self["number"].setText(self.field)
132                 if len(self.field) >= 4:
133                         self.keyOK()
134
135         def __init__(self, session, number):
136                 Screen.__init__(self, session)
137                 self.field = str(number)
138                 
139                 self["number"] = Label(self.field)
140
141                 self["actions"] = NumberActionMap( [ "SetupActions" ], 
142                         {
143                                 "cancel": self.quit,
144                                 "ok": self.keyOK,
145                                 "1": self.keyNumberGlobal,
146                                 "2": self.keyNumberGlobal,
147                                 "3": self.keyNumberGlobal,
148                                 "4": self.keyNumberGlobal,
149                                 "5": self.keyNumberGlobal,
150                                 "6": self.keyNumberGlobal,
151                                 "7": self.keyNumberGlobal,
152                                 "8": self.keyNumberGlobal,
153                                 "9": self.keyNumberGlobal,
154                                 "0": self.keyNumberGlobal
155                         })
156
157                 self.Timer = eTimer()
158                 self.Timer.timeout.get().append(self.keyOK)
159                 self.Timer.start(3000)
160
161 class InfoBarPowerKey:
162         """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
163         
164         def __init__(self):
165                 self.powerKeyTimer = eTimer()
166                 self.powerKeyTimer.timeout.get().append(self.powertimer)
167                 self["PowerKeyActions"] = ActionMap( ["PowerKeyActions"],
168                         {
169                                 "powerdown": self.powerdown,
170                                 "powerup": self.powerup,
171                         })
172
173         def powertimer(self):   
174                 print "PowerOff - Now!"
175                 self.quit()
176         
177         def powerdown(self):
178                 self.standbyblocked = 0
179                 self.powerKeyTimer.start(3000)
180
181         def powerup(self):
182                 self.powerKeyTimer.stop()
183                 if self.standbyblocked == 0:
184                         self.standbyblocked = 1
185                         self.session.open(Standby, self)
186
187         def quit(self):
188                 quitMainloop(0)
189
190 class InfoBarNumberZap:
191         """ Handles an initial number for NumberZapping """
192         def __init__(self):
193                 self["NumberZapActions"] = NumberActionMap( [ "NumberZapActions"],
194                         {
195                                 "1": self.keyNumberGlobal,
196                                 "2": self.keyNumberGlobal,
197                                 "3": self.keyNumberGlobal,
198                                 "4": self.keyNumberGlobal,
199                                 "5": self.keyNumberGlobal,
200                                 "6": self.keyNumberGlobal,
201                                 "7": self.keyNumberGlobal,
202                                 "8": self.keyNumberGlobal,
203                                 "9": self.keyNumberGlobal,
204                                 "0": self.keyNumberGlobal,
205                         })
206
207         def keyNumberGlobal(self, number):
208                 print "You pressed number " + str(number)
209                 self.session.open(NumberZap, number)
210
211 class InfoBarChannelSelection:
212         """ ChannelSelection - handles the channelSelection dialog and the initial 
213         channelChange actions which open the channelSelection dialog """
214         def __init__(self):
215                 #instantiate forever
216                 self.servicelist = self.session.instantiateDialog(ChannelSelection)
217
218                 self["ChannelSelectActions"] = ActionMap( ["InfobarChannelSelection"],
219                         {
220                                 "switchChannelUp": self.switchChannelUp,
221                                 "switchChannelDown": self.switchChannelDown,
222                                 "zapUp": self.zapUp,
223                                 "zapDown": self.zapDown,
224                         })
225                         
226         def switchChannelUp(self):      
227                 self.servicelist.moveUp()
228                 self.session.execDialog(self.servicelist)
229
230         def switchChannelDown(self):    
231                 self.servicelist.moveDown()
232                 self.session.execDialog(self.servicelist)
233
234         def     zapUp(self):
235                 self.servicelist.moveUp()
236                 self.servicelist.zap()
237
238         def     zapDown(self):
239                 self.servicelist.moveDown()
240                 self.servicelist.zap()
241
242 class InfoBarMenu:
243         """ Handles a menu action, to open the (main) menu """
244         def __init__(self):
245                 self["MenuActions"] = ActionMap( [ "InfobarMenuActions" ], 
246                         {
247                                 "mainMenu": self.mainMenu,
248                         })
249
250         def mainMenu(self):
251                 print "loading mainmenu XML..."
252                 menu = mdom.childNodes[0]
253                 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
254                 self.session.open(MainMenu, menu, menu.childNodes)
255
256 class InfoBarEPG:
257         """ EPG - Opens an EPG list when the showEPGList action fires """
258         def __init__(self):
259                 self["EPGActions"] = ActionMap( [ "InfobarEPGActions" ], 
260                         {
261                                 "showEPGList": self.showEPGList,
262                         })
263
264         def showEPGList(self):
265                 ref=self.session.nav.getCurrentlyPlayingServiceReference()
266                 ptr=eEPGCache.getInstance()
267                 if ptr.startTimeQuery(ref) != -1:
268                         self.session.open(EPGSelection, ref)
269                 else:
270                         print 'no epg for service', ref.toString()
271
272 class InfoBarEvent:     
273         """provides a current/next event info display"""
274         def __init__(self):
275                 self["Event_Now_StartTime"] = EventInfo(self.session.nav, EventInfo.Now_StartTime)
276                 self["Event_Next_StartTime"] = EventInfo(self.session.nav, EventInfo.Next_StartTime)
277                                 
278                 self["Event_Now"] = EventInfo(self.session.nav, EventInfo.Now)
279                 self["Event_Next"] = EventInfo(self.session.nav, EventInfo.Next)
280
281                 self["Event_Now_Duration"] = EventInfo(self.session.nav, EventInfo.Now_Duration)
282                 self["Event_Next_Duration"] = EventInfo(self.session.nav, EventInfo.Next_Duration)
283
284 class InfoBarServiceName:
285         def __init__(self):
286                 self["ServiceName"] = ServiceName(self.session.nav)
287
288 class InfoBarPVR:
289         """handles PVR specific actions like seeking, pause"""
290         def __init__(self):
291                 self["PVRActions"] = ActionMap( [ "InfobarPVRActions" ], 
292                         {
293                                 "pauseService": self.pauseService,
294                                 "unPauseService": self.unPauseService,
295                                 
296                                 "seekFwd": self.seekFwd,
297                                 "seekBack": self.seekBack,
298                         })
299                 
300         def pauseService(self):
301                 self.session.nav.pause(1)
302                 
303         def unPauseService(self):
304                 self.session.nav.pause(0)
305         
306         def doSeek(self, dir, seektime):
307                 service = self.session.nav.getCurrentService()
308                 if service is None:
309                         return
310                 
311                 seekable = service.seek()
312                 if seekable is None:
313                         return
314                 seekable.seekRelative(dir, 90 * seektime)
315
316         def seekFwd(self):
317                 self.doSeek(+1, 60000)
318         
319         def seekBack(self):
320                 self.doSeek(-1, 60000)
321
322 class InfoBarInstantRecord:
323         """Instant Record - handles the instantRecord action in order to 
324         start/stop instant records"""
325         def __init__(self):
326                 self["InstnantRecordActions"] = ActionMap( [ "InfobarInstantRecord" ],
327                         {
328                                 "instantRecord": self.instantRecord,
329                         })
330                 self.recording = None
331
332         def stopCurrentRecording(self): 
333                 self.session.nav.RecordTimer.removeEntry(self.recording)
334                 self.recording = None
335         
336         def startInstantRecording(self):
337                 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
338                         
339                 # try to get event info
340                 epg = None
341                 try:
342                         service = self.session.nav.getCurrentService()
343                         info = service.info()
344                         ev = info.getEvent(0)
345                         epg = ev
346                 except:
347                         pass
348                 
349                 # fix me, description. 
350                 self.recording = self.session.nav.recordWithTimer(time.time(), time.time() + 3600, serviceref, epg, "instant record")
351
352         def recordQuestionCallback(self, answer):
353                 if answer == False:
354                         return
355                 
356                 if self.recording != None:
357                         self.stopCurrentRecording()
358                 else:
359                         self.startInstantRecording()
360
361         def instantRecord(self):
362                 if self.recording != None:
363                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Do you want to stop the current\n(instant) recording?")
364                 else:
365                         self.session.openWithCallback(self.recordQuestionCallback, MessageBox, "Start recording?")
366
367 from Screens.AudioSelection import AudioSelection
368
369 class InfoBarAudioSelection:
370         def __init__(self):
371                 self["AudioSelectionAction"] = ActionMap( [ "InfobarAudioSelectionActions" ], 
372                         {
373                                 "audioSelection": self.audioSelection,
374                         })
375
376         def audioSelection(self):
377                 service = self.session.nav.getCurrentService()
378                 audio = service.audioTracks()
379                 n = audio.getNumberOfTracks()
380                 if n > 0:
381                         self.session.open(AudioSelection, audio)