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