1 from ChannelSelection import ChannelSelection, BouquetSelector
3 from Components.ActionMap import ActionMap, HelpableActionMap
4 from Components.ActionMap import NumberActionMap
5 from Components.Harddisk import harddiskmanager
6 from Components.Input import Input
7 from Components.Label import Label
8 from Components.PluginComponent import plugins
9 from Components.ServiceEventTracker import ServiceEventTracker
10 from Components.Sources.Boolean import Boolean
11 from Components.config import config, ConfigBoolean, ConfigClock
12 from Components.SystemInfo import SystemInfo
13 from EpgSelection import EPGSelection
14 from Plugins.Plugin import PluginDescriptor
16 from Screen import Screen
17 from Screens.ChoiceBox import ChoiceBox
18 from Screens.Dish import Dish
19 from Screens.EventView import EventViewEPGSelect, EventViewSimple
20 from Screens.InputBox import InputBox
21 from Screens.MessageBox import MessageBox
22 from Screens.MinuteInput import MinuteInput
23 from Screens.TimerSelection import TimerSelection
24 from Screens.PictureInPicture import PictureInPicture
25 from Screens.SubtitleDisplay import SubtitleDisplay
26 from Screens.RdsDisplay import RdsInfoDisplay, RassInteractive
27 from Screens.SleepTimerEdit import SleepTimerEdit
28 from Screens.TimeDateInput import TimeDateInput
29 from ServiceReference import ServiceReference
31 from Tools import Notifications
32 from Tools.Directories import SCOPE_HDD, resolveFilename, pathExists
34 from enigma import eTimer, eServiceCenter, eDVBServicePMTHandler, iServiceInformation, \
35 iPlayableService, eServiceReference, eEPGCache
37 from time import time, localtime, strftime
38 from os import stat as os_stat
39 from bisect import insort
42 from Menu import MainMenu, mdom
46 self.dishDialog = self.session.instantiateDialog(Dish)
48 class InfoBarShowHide:
49 """ InfoBar show/hide control, accepts toggleShow and hide actions, might start
57 self["ShowHideActions"] = ActionMap( ["InfobarShowHideActions"] ,
59 "toggleShow": self.toggleShow,
61 }, 1) # lower prio to make it possible to override ok and cancel..
63 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
65 iPlayableService.evStart: self.serviceStarted,
68 self.__state = self.STATE_SHOWN
71 self.hideTimer = eTimer()
72 self.hideTimer.callback.append(self.doTimerHide)
73 self.hideTimer.start(5000, True)
75 self.onShow.append(self.__onShow)
76 self.onHide.append(self.__onHide)
78 def serviceStarted(self):
80 if config.usage.show_infobar_on_zap.value:
84 self.__state = self.STATE_SHOWN
87 def startHideTimer(self):
88 if self.__state == self.STATE_SHOWN and not self.__locked:
89 idx = config.usage.infobar_timeout.index
91 self.hideTimer.start(idx*1000, True)
94 self.__state = self.STATE_HIDDEN
100 def doTimerHide(self):
101 self.hideTimer.stop()
102 if self.__state == self.STATE_SHOWN:
105 def toggleShow(self):
106 if self.__state == self.STATE_SHOWN:
108 self.hideTimer.stop()
109 elif self.__state == self.STATE_HIDDEN:
113 self.__locked = self.__locked + 1
116 self.hideTimer.stop()
118 def unlockShow(self):
119 self.__locked = self.__locked - 1
121 self.startHideTimer()
123 # def startShow(self):
124 # self.instance.m_animation.startMoveAnimation(ePoint(0, 600), ePoint(0, 380), 100)
125 # self.__state = self.STATE_SHOWN
127 # def startHide(self):
128 # self.instance.m_animation.startMoveAnimation(ePoint(0, 380), ePoint(0, 600), 100)
129 # self.__state = self.STATE_HIDDEN
131 class NumberZap(Screen):
138 self.close(int(self["number"].getText()))
140 def keyNumberGlobal(self, number):
141 self.Timer.start(3000, True) #reset timer
142 self.field = self.field + str(number)
143 self["number"].setText(self.field)
144 if len(self.field) >= 4:
147 def __init__(self, session, number):
148 Screen.__init__(self, session)
149 self.field = str(number)
151 self["channel"] = Label(_("Channel:"))
153 self["number"] = Label(self.field)
155 self["actions"] = NumberActionMap( [ "SetupActions" ],
159 "1": self.keyNumberGlobal,
160 "2": self.keyNumberGlobal,
161 "3": self.keyNumberGlobal,
162 "4": self.keyNumberGlobal,
163 "5": self.keyNumberGlobal,
164 "6": self.keyNumberGlobal,
165 "7": self.keyNumberGlobal,
166 "8": self.keyNumberGlobal,
167 "9": self.keyNumberGlobal,
168 "0": self.keyNumberGlobal
171 self.Timer = eTimer()
172 self.Timer.callback.append(self.keyOK)
173 self.Timer.start(3000, True)
175 class InfoBarNumberZap:
176 """ Handles an initial number for NumberZapping """
178 self["NumberActions"] = NumberActionMap( [ "NumberActions"],
180 "1": self.keyNumberGlobal,
181 "2": self.keyNumberGlobal,
182 "3": self.keyNumberGlobal,
183 "4": self.keyNumberGlobal,
184 "5": self.keyNumberGlobal,
185 "6": self.keyNumberGlobal,
186 "7": self.keyNumberGlobal,
187 "8": self.keyNumberGlobal,
188 "9": self.keyNumberGlobal,
189 "0": self.keyNumberGlobal,
192 def keyNumberGlobal(self, number):
193 # print "You pressed number " + str(number)
195 if isinstance(self, InfoBarPiP) and self.pipHandles0Action():
196 self.pipDoHandle0Action()
198 self.servicelist.recallPrevService()
200 if self.has_key("TimeshiftActions") and not self.timeshift_enabled:
201 self.session.openWithCallback(self.numberEntered, NumberZap, number)
203 def numberEntered(self, retval):
204 # print self.servicelist
206 self.zapToNumber(retval)
208 def searchNumberHelper(self, serviceHandler, num, bouquet):
209 servicelist = serviceHandler.list(bouquet)
210 if not servicelist is None:
212 serviceIterator = servicelist.getNext()
213 if not serviceIterator.valid(): #check end of list
215 playable = not (serviceIterator.flags & (eServiceReference.isMarker|eServiceReference.isDirectory))
218 if not num: #found service with searched number ?
219 return serviceIterator, 0
222 def zapToNumber(self, number):
223 bouquet = self.servicelist.bouquet_root
225 serviceHandler = eServiceCenter.getInstance()
226 if not config.usage.multibouquet.value:
227 service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
229 bouquetlist = serviceHandler.list(bouquet)
230 if not bouquetlist is None:
232 bouquet = bouquetlist.getNext()
233 if not bouquet.valid(): #check end of list
235 if bouquet.flags & eServiceReference.isDirectory:
236 service, number = self.searchNumberHelper(serviceHandler, number, bouquet)
237 if not service is None:
238 if self.servicelist.getRoot() != bouquet: #already in correct bouquet?
239 self.servicelist.clearPath()
240 if self.servicelist.bouquet_root != bouquet:
241 self.servicelist.enterPath(self.servicelist.bouquet_root)
242 self.servicelist.enterPath(bouquet)
243 self.servicelist.setCurrentSelection(service) #select the service in servicelist
244 self.servicelist.zap()
246 config.misc.initialchannelselection = ConfigBoolean(default = True)
248 class InfoBarChannelSelection:
249 """ ChannelSelection - handles the channelSelection dialog and the initial
250 channelChange actions which open the channelSelection dialog """
253 self.servicelist = self.session.instantiateDialog(ChannelSelection)
255 if config.misc.initialchannelselection.value:
256 self.onShown.append(self.firstRun)
258 self["ChannelSelectActions"] = HelpableActionMap(self, "InfobarChannelSelection",
260 "switchChannelUp": (self.switchChannelUp, _("open servicelist(up)")),
261 "switchChannelDown": (self.switchChannelDown, _("open servicelist(down)")),
262 "zapUp": (self.zapUp, _("previous channel")),
263 "zapDown": (self.zapDown, _("next channel")),
264 "historyBack": (self.historyBack, _("previous channel in history")),
265 "historyNext": (self.historyNext, _("next channel in history")),
266 "openServiceList": (self.openServiceList, _("open servicelist")),
269 def showTvChannelList(self, zap=False):
270 self.servicelist.setModeTv()
272 self.servicelist.zap()
273 self.session.execDialog(self.servicelist)
275 def showRadioChannelList(self, zap=False):
276 self.servicelist.setModeRadio()
278 self.servicelist.zap()
279 self.session.execDialog(self.servicelist)
282 self.onShown.remove(self.firstRun)
283 config.misc.initialchannelselection.value = False
284 config.misc.initialchannelselection.save()
285 self.switchChannelDown()
287 def historyBack(self):
288 self.servicelist.historyBack()
290 def historyNext(self):
291 self.servicelist.historyNext()
293 def switchChannelUp(self):
294 self.servicelist.moveUp()
295 self.session.execDialog(self.servicelist)
297 def switchChannelDown(self):
298 self.servicelist.moveDown()
299 self.session.execDialog(self.servicelist)
301 def openServiceList(self):
302 self.session.execDialog(self.servicelist)
305 if self.servicelist.inBouquet():
306 prev = self.servicelist.getCurrentSelection()
308 prev = prev.toString()
310 if config.usage.quickzap_bouquet_change.value:
311 if self.servicelist.atBegin():
312 self.servicelist.prevBouquet()
313 self.servicelist.moveUp()
314 cur = self.servicelist.getCurrentSelection()
315 if not cur or (not (cur.flags & 64)) or cur.toString() == prev:
318 self.servicelist.moveUp()
319 self.servicelist.zap()
322 if self.servicelist.inBouquet():
323 prev = self.servicelist.getCurrentSelection()
325 prev = prev.toString()
327 if config.usage.quickzap_bouquet_change.value and self.servicelist.atEnd():
328 self.servicelist.nextBouquet()
330 self.servicelist.moveDown()
331 cur = self.servicelist.getCurrentSelection()
332 if not cur or (not (cur.flags & 64)) or cur.toString() == prev:
335 self.servicelist.moveDown()
336 self.servicelist.zap()
339 """ Handles a menu action, to open the (main) menu """
341 self["MenuActions"] = HelpableActionMap(self, "InfobarMenuActions",
343 "mainMenu": (self.mainMenu, _("Enter main menu...")),
345 self.session.infobar = None
348 print "loading mainmenu XML..."
349 menu = mdom.childNodes[0]
350 assert menu.tagName == "menu", "root element in menu must be 'menu'!"
352 self.session.infobar = self
353 # so we can access the currently active infobar from screens opened from within the mainmenu
354 # at the moment used from the SubserviceSelection
356 self.session.openWithCallback(self.mainMenuClosed, MainMenu, menu, menu.childNodes)
358 def mainMenuClosed(self, *val):
359 self.session.infobar = None
361 class InfoBarSimpleEventView:
362 """ Opens the Eventview for now/next """
364 self["EPGActions"] = HelpableActionMap(self, "InfobarEPGActions",
366 "showEventInfo": (self.openEventView, _("show event details")),
369 def openEventView(self):
371 service = self.session.nav.getCurrentService()
372 ref = self.session.nav.getCurrentlyPlayingServiceReference()
373 info = service.info()
376 self.epglist.append(ptr)
379 self.epglist.append(ptr)
380 if len(self.epglist) > 0:
381 self.session.open(EventViewSimple, self.epglist[0], ServiceReference(ref), self.eventViewCallback)
383 def eventViewCallback(self, setEvent, setService, val): #used for now/next displaying
384 if len(self.epglist) > 1:
385 tmp = self.epglist[0]
386 self.epglist[0]=self.epglist[1]
388 setEvent(self.epglist[0])
391 """ EPG - Opens an EPG list when the showEPGList action fires """
393 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
395 iPlayableService.evUpdatedEventInfo: self.__evEventInfoChanged,
398 self.is_now_next = False
400 self.bouquetSel = None
401 self.eventView = None
402 self["EPGActions"] = HelpableActionMap(self, "InfobarEPGActions",
404 "showEventInfo": (self.openEventView, _("show EPG...")),
405 "showSingleServiceEPG": (self.openSingleServiceEPG, _("show single service EPG...")),
406 "showInfobarOrEpgWhenInfobarAlreadyVisible": self.showEventInfoWhenNotVisible,
409 def showEventInfoWhenNotVisible(self):
416 def zapToService(self, service):
417 if not service is None:
418 if self.servicelist.getRoot() != self.epg_bouquet: #already in correct bouquet?
419 self.servicelist.clearPath()
420 if self.servicelist.bouquet_root != self.epg_bouquet:
421 self.servicelist.enterPath(self.servicelist.bouquet_root)
422 self.servicelist.enterPath(self.epg_bouquet)
423 self.servicelist.setCurrentSelection(service) #select the service in servicelist
424 self.servicelist.zap()
426 def getBouquetServices(self, bouquet):
428 servicelist = eServiceCenter.getInstance().list(bouquet)
429 if not servicelist is None:
431 service = servicelist.getNext()
432 if not service.valid(): #check if end of list
434 if service.flags & (eServiceReference.isDirectory | eServiceReference.isMarker): #ignore non playable services
436 services.append(ServiceReference(service))
439 def openBouquetEPG(self, bouquet, withCallback=True):
440 services = self.getBouquetServices(bouquet)
442 self.epg_bouquet = bouquet
444 self.dlg_stack.append(self.session.openWithCallback(self.closed, EPGSelection, services, self.zapToService, None, self.changeBouquetCB))
446 self.session.open(EPGSelection, services, self.zapToService, None, self.changeBouquetCB)
448 def changeBouquetCB(self, direction, epg):
451 self.bouquetSel.down()
454 bouquet = self.bouquetSel.getCurrent()
455 services = self.getBouquetServices(bouquet)
457 self.epg_bouquet = bouquet
458 epg.setServices(services)
460 def closed(self, ret=False):
461 closedScreen = self.dlg_stack.pop()
462 if self.bouquetSel and closedScreen == self.bouquetSel:
463 self.bouquetSel = None
464 elif self.eventView and closedScreen == self.eventView:
465 self.eventView = None
467 dlgs=len(self.dlg_stack)
469 self.dlg_stack[dlgs-1].close(dlgs > 1)
471 def openMultiServiceEPG(self, withCallback=True):
472 bouquets = self.servicelist.getBouquetList()
477 if cnt > 1: # show bouquet list
479 self.bouquetSel = self.session.openWithCallback(self.closed, BouquetSelector, bouquets, self.openBouquetEPG, enableWrapAround=True)
480 self.dlg_stack.append(self.bouquetSel)
482 self.bouquetSel = self.session.open(BouquetSelector, bouquets, self.openBouquetEPG, enableWrapAround=True)
484 self.openBouquetEPG(bouquets[0][1], withCallback)
486 def openSingleServiceEPG(self):
487 ref=self.session.nav.getCurrentlyPlayingServiceReference()
488 self.session.open(EPGSelection, ref)
490 def openSimilarList(self, eventid, refstr):
491 self.session.open(EPGSelection, refstr, None, eventid)
493 def getNowNext(self):
495 service = self.session.nav.getCurrentService()
496 info = service and service.info()
497 ptr = info and info.getEvent(0)
499 self.epglist.append(ptr)
500 ptr = info and info.getEvent(1)
502 self.epglist.append(ptr)
504 def __evEventInfoChanged(self):
505 if self.is_now_next and len(self.dlg_stack) == 1:
507 assert self.eventView
508 if len(self.epglist):
509 self.eventView.setEvent(self.epglist[0])
511 def openEventView(self):
512 ref = self.session.nav.getCurrentlyPlayingServiceReference()
514 if len(self.epglist) == 0:
515 self.is_now_next = False
516 epg = eEPGCache.getInstance()
517 ptr = ref and ref.valid() and epg.lookupEventTime(ref, -1)
519 self.epglist.append(ptr)
520 ptr = epg.lookupEventTime(ref, ptr.getBeginTime(), +1)
522 self.epglist.append(ptr)
524 self.is_now_next = True
525 if len(self.epglist) > 0:
526 self.eventView = self.session.openWithCallback(self.closed, EventViewEPGSelect, self.epglist[0], ServiceReference(ref), self.eventViewCallback, self.openSingleServiceEPG, self.openMultiServiceEPG, self.openSimilarList)
527 self.dlg_stack.append(self.eventView)
529 print "no epg for the service avail.. so we show multiepg instead of eventinfo"
530 self.openMultiServiceEPG(False)
532 def eventViewCallback(self, setEvent, setService, val): #used for now/next displaying
533 if len(self.epglist) > 1:
534 tmp = self.epglist[0]
535 self.epglist[0]=self.epglist[1]
537 setEvent(self.epglist[0])
539 class InfoBarRdsDecoder:
540 """provides RDS and Rass support/display"""
542 self.rds_display = self.session.instantiateDialog(RdsInfoDisplay)
543 self.rass_interactive = None
545 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
547 iPlayableService.evEnd: self.__serviceStopped,
548 iPlayableService.evUpdatedRassSlidePic: self.RassSlidePicChanged
551 self["RdsActions"] = ActionMap(["InfobarRdsActions"],
553 "startRassInteractive": self.startRassInteractive
556 self["RdsActions"].setEnabled(False)
558 self.onLayoutFinish.append(self.rds_display.show)
559 self.rds_display.onRassInteractivePossibilityChanged.append(self.RassInteractivePossibilityChanged)
561 def RassInteractivePossibilityChanged(self, state):
562 self["RdsActions"].setEnabled(state)
564 def RassSlidePicChanged(self):
565 if not self.rass_interactive:
566 service = self.session.nav.getCurrentService()
567 decoder = service and service.rdsDecoder()
569 decoder.showRassSlidePicture()
571 def __serviceStopped(self):
572 if self.rass_interactive is not None:
573 rass_interactive = self.rass_interactive
574 self.rass_interactive = None
575 rass_interactive.close()
577 def startRassInteractive(self):
578 self.rds_display.hide()
579 self.rass_interactive = self.session.openWithCallback(self.RassInteractiveClosed, RassInteractive)
581 def RassInteractiveClosed(self, *val):
582 if self.rass_interactive is not None:
583 self.rass_interactive = None
584 self.RassSlidePicChanged()
585 self.rds_display.show()
588 """handles actions like seeking, pause"""
590 SEEK_STATE_PLAY = (0, 0, 0, ">")
591 SEEK_STATE_PAUSE = (1, 0, 0, "||")
592 SEEK_STATE_EOF = (1, 0, 0, "END")
594 def __init__(self, actionmap = "InfobarSeekActions", useSeekBackHack=True):
595 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
597 iPlayableService.evSeekableStatusChanged: self.__seekableStatusChanged,
598 iPlayableService.evStart: self.__serviceStarted,
600 iPlayableService.evEOF: self.__evEOF,
601 iPlayableService.evSOF: self.__evSOF,
604 self.eofTimer = eTimer()
605 self.eofTimer.timeout.get().append(self.doEof)
606 self.eofInhibitTimer = eTimer()
607 self.eofInhibitTimer.timeout.get().append(self.inhibitEof)
609 self.minSpeedBackward = useSeekBackHack and 16 or 0
611 class InfoBarSeekActionMap(HelpableActionMap):
612 def __init__(self, screen, *args, **kwargs):
613 HelpableActionMap.__init__(self, screen, *args, **kwargs)
616 def action(self, contexts, action):
617 print "action:", action
618 if action[:5] == "seek:":
619 time = int(action[5:])
620 self.screen.doSeekRelative(time * 90000)
622 elif action[:8] == "seekdef:":
623 key = int(action[8:])
624 time = [-config.seek.selfdefined_13.value, False, config.seek.selfdefined_13.value,
625 -config.seek.selfdefined_46.value, False, config.seek.selfdefined_46.value,
626 -config.seek.selfdefined_79.value, False, config.seek.selfdefined_79.value][key-1]
627 self.screen.doSeekRelative(time * 90000)
630 return HelpableActionMap.action(self, contexts, action)
632 self["SeekActions"] = InfoBarSeekActionMap(self, actionmap,
634 "playpauseService": self.playpauseService,
635 "pauseService": (self.pauseService, _("pause")),
636 "unPauseService": (self.unPauseService, _("continue")),
638 "seekFwd": (self.seekFwd, _("skip forward")),
639 "seekFwdManual": (self.seekFwdManual, _("skip forward (enter time)")),
640 "seekBack": (self.seekBack, _("skip backward")),
641 "seekBackManual": (self.seekBackManual, _("skip backward (enter time)"))
643 # give them a little more priority to win over color buttons
645 self["SeekActions"].setEnabled(False)
647 self.seekstate = self.SEEK_STATE_PLAY
648 self.lastseekstate = self.SEEK_STATE_PLAY
650 self.onPlayStateChanged = [ ]
652 self.lockedBecauseOfSkipping = False
654 self.__seekableStatusChanged()
656 def makeStateForward(self, n):
657 minspeed = config.seek.stepwise_minspeed.value
658 repeat = int(config.seek.stepwise_repeat.value)
659 if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
660 return (0, n * repeat, repeat, ">> %dx" % n)
662 return (0, n, 0, ">> %dx" % n)
664 def makeStateBackward(self, n):
665 minspeed = config.seek.stepwise_minspeed.value
666 repeat = int(config.seek.stepwise_repeat.value)
667 if self.minSpeedBackward and n < self.minSpeedBackward:
668 r = (self.minSpeedBackward - 1)/ n + 1
669 if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
671 return (0, -n * r, r, "<< %dx" % n)
672 elif minspeed != "Never" and n >= int(minspeed) and repeat > 1:
673 return (0, -n * repeat, repeat, "<< %dx" % n)
675 return (0, -n, 0, "<< %dx" % n)
677 def makeStateSlowMotion(self, n):
678 return (0, 0, n, "/%d" % n)
680 def isStateForward(self, state):
683 def isStateBackward(self, state):
686 def isStateSlowMotion(self, state):
687 return state[1] == 0 and state[2] > 1
689 def getHigher(self, n, lst):
695 def getLower(self, n, lst):
703 def showAfterSeek(self):
704 if isinstance(self, InfoBarShowHide):
714 service = self.session.nav.getCurrentService()
718 seek = service.seek()
720 if seek is None or not seek.isCurrentlySeekable():
725 def isSeekable(self):
726 if self.getSeek() is None:
730 def __seekableStatusChanged(self):
731 # print "seekable status changed!"
732 if not self.isSeekable():
733 self["SeekActions"].setEnabled(False)
734 # print "not seekable, return to play"
735 self.setSeekState(self.SEEK_STATE_PLAY)
737 self["SeekActions"].setEnabled(True)
740 def __serviceStarted(self):
741 self.seekstate = self.SEEK_STATE_PLAY
742 self.__seekableStatusChanged()
743 if self.eofState != 0:
747 def setSeekState(self, state):
748 service = self.session.nav.getCurrentService()
753 if not self.isSeekable():
754 if state not in [self.SEEK_STATE_PLAY, self.SEEK_STATE_PAUSE]:
755 state = self.SEEK_STATE_PLAY
757 pauseable = service.pause()
759 if pauseable is None:
760 print "not pauseable."
761 state = self.SEEK_STATE_PLAY
763 oldstate = self.seekstate
764 self.seekstate = state
767 if oldstate[i] != self.seekstate[i]:
768 (self.session.nav.pause, pauseable.setFastForward, pauseable.setSlowMotion)[i](self.seekstate[i])
770 for c in self.onPlayStateChanged:
773 self.checkSkipShowHideLock()
777 def playpauseService(self):
778 if self.seekstate != self.SEEK_STATE_PLAY:
779 self.unPauseService()
783 def pauseService(self):
784 if self.seekstate == self.SEEK_STATE_PAUSE:
785 if config.seek.on_pause.value == "play":
786 self.unPauseService()
787 elif config.seek.on_pause.value == "step":
788 self.doSeekRelative(0)
789 elif config.seek.on_pause.value == "last":
790 self.setSeekState(self.lastseekstate)
791 self.lastseekstate = self.SEEK_STATE_PLAY
793 if self.seekstate != self.SEEK_STATE_EOF:
794 self.lastseekstate = self.seekstate
795 self.setSeekState(self.SEEK_STATE_PAUSE);
797 def unPauseService(self):
799 if self.seekstate == self.SEEK_STATE_PLAY:
801 self.setSeekState(self.SEEK_STATE_PLAY)
803 def doSeek(self, pts):
804 seekable = self.getSeek()
807 prevstate = self.seekstate
808 if self.eofState == 1:
811 if self.seekstate == self.SEEK_STATE_EOF:
812 if prevstate == self.SEEK_STATE_PAUSE:
813 self.setSeekState(self.SEEK_STATE_PAUSE)
815 self.setSeekState(self.SEEK_STATE_PLAY)
816 self.eofInhibitTimer.start(200, True)
819 def doSeekRelative(self, pts):
820 seekable = self.getSeek()
823 prevstate = self.seekstate
824 if self.eofState == 1:
827 if self.seekstate == self.SEEK_STATE_EOF:
828 if prevstate == self.SEEK_STATE_PAUSE:
829 self.setSeekState(self.SEEK_STATE_PAUSE)
831 self.setSeekState(self.SEEK_STATE_PLAY)
832 self.eofInhibitTimer.start(200, True)
833 seekable.seekRelative(pts<0 and -1 or 1, abs(pts))
834 if abs(pts) > 100 and config.usage.show_infobar_on_skip.value:
838 if self.seekstate == self.SEEK_STATE_PLAY:
839 self.setSeekState(self.makeStateForward(int(config.seek.enter_forward.value)))
840 elif self.seekstate == self.SEEK_STATE_PAUSE:
841 if len(config.seek.speeds_slowmotion.value):
842 self.setSeekState(self.makeStateSlowMotion(config.seek.speeds_slowmotion.value[-1]))
844 self.setSeekState(self.makeStateForward(int(config.seek.enter_forward.value)))
845 elif self.seekstate == self.SEEK_STATE_EOF:
847 elif self.isStateForward(self.seekstate):
848 speed = self.seekstate[1]
849 if self.seekstate[2]:
850 speed /= self.seekstate[2]
851 speed = self.getHigher(speed, config.seek.speeds_forward.value) or config.seek.speeds_forward.value[-1]
852 self.setSeekState(self.makeStateForward(speed))
853 elif self.isStateBackward(self.seekstate):
854 speed = -self.seekstate[1]
855 if self.seekstate[2]:
856 speed /= self.seekstate[2]
857 speed = self.getLower(speed, config.seek.speeds_backward.value)
859 self.setSeekState(self.makeStateBackward(speed))
861 self.setSeekState(self.SEEK_STATE_PLAY)
862 elif self.isStateSlowMotion(self.seekstate):
863 speed = self.getLower(self.seekstate[2], config.seek.speeds_slowmotion.value) or config.seek.speeds_slowmotion.value[0]
864 self.setSeekState(self.makeStateSlowMotion(speed))
867 if self.seekstate == self.SEEK_STATE_PLAY:
868 self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
869 elif self.seekstate == self.SEEK_STATE_EOF:
870 self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
871 self.doSeekRelative(-6)
872 elif self.seekstate == self.SEEK_STATE_PAUSE:
873 self.doSeekRelative(-3)
874 elif self.isStateForward(self.seekstate):
875 speed = self.seekstate[1]
876 if self.seekstate[2]:
877 speed /= self.seekstate[2]
878 speed = self.getLower(speed, config.seek.speeds_forward.value)
880 self.setSeekState(self.makeStateForward(speed))
882 self.setSeekState(self.SEEK_STATE_PLAY)
883 elif self.isStateBackward(self.seekstate):
884 speed = -self.seekstate[1]
885 if self.seekstate[2]:
886 speed /= self.seekstate[2]
887 speed = self.getHigher(speed, config.seek.speeds_backward.value) or config.seek.speeds_backward.value[-1]
888 self.setSeekState(self.makeStateBackward(speed))
889 elif self.isStateSlowMotion(self.seekstate):
890 speed = self.getHigher(self.seekstate[2], config.seek.speeds_slowmotion.value)
892 self.setSeekState(self.makeStateSlowMotion(speed))
894 self.setSeekState(self.SEEK_STATE_PAUSE)
896 def seekFwdManual(self):
897 self.session.openWithCallback(self.fwdSeekTo, MinuteInput)
899 def fwdSeekTo(self, minutes):
900 print "Seek", minutes, "minutes forward"
901 self.doSeekRelative(minutes * 60 * 90000)
903 def seekBackManual(self):
904 self.session.openWithCallback(self.rwdSeekTo, MinuteInput)
906 def rwdSeekTo(self, minutes):
908 self.doSeekRelative(-minutes * 60 * 90000)
910 def checkSkipShowHideLock(self):
911 wantlock = self.seekstate != self.SEEK_STATE_PLAY
913 if config.usage.show_infobar_on_skip.value:
914 if self.lockedBecauseOfSkipping and not wantlock:
916 self.lockedBecauseOfSkipping = False
918 if wantlock and not self.lockedBecauseOfSkipping:
920 self.lockedBecauseOfSkipping = True
922 def calcRemainingTime(self):
923 seekable = self.getSeek()
924 if seekable is not None:
925 len = seekable.getLength()
927 tmp = self.cueGetEndCutPosition()
932 pos = seekable.getPlayPosition()
933 speednom = self.seekstate[1] or 1
934 speedden = self.seekstate[2] or 1
935 if not len[0] and not pos[0]:
938 time = (len[1] - pos[1])*speedden/(90*speednom)
943 if self.eofState == 0 and self.seekstate != self.SEEK_STATE_EOF:
945 time = self.calcRemainingTime()
947 time = 3000 # Failed to calc, use default
949 time = 300 # Passed end, shortest wait
951 self.eofState = -2 # Too long, block eof
954 time += 1000 # Add margin
955 self.eofTimer.start(time, True)
957 def inhibitEof(self):
958 if self.eofState >= 1:
959 self.eofState = -self.eofState
964 if self.seekstate == self.SEEK_STATE_EOF:
966 if self.eofState == -2 or self.isStateBackward(self.seekstate):
970 # if we are seeking, we try to end up ~1s before the end, and pause there.
971 eofstate = self.eofState
972 seekstate = self.seekstate
974 if not self.seekstate == self.SEEK_STATE_PAUSE:
975 self.setSeekState(self.SEEK_STATE_EOF)
976 if eofstate == -1 or not seekstate in [self.SEEK_STATE_PLAY, self.SEEK_STATE_PAUSE]:
977 seekable = self.getSeek()
978 if seekable is not None:
980 if eofstate == 1 and seekstate == self.SEEK_STATE_PLAY:
981 self.doEofInternal(True)
983 self.doEofInternal(False)
985 def doEofInternal(self, playing):
986 pass # Defined in subclasses
989 self.setSeekState(self.SEEK_STATE_PLAY)
992 from Screens.PVRState import PVRState, TimeshiftState
994 class InfoBarPVRState:
995 def __init__(self, screen=PVRState):
996 self.onPlayStateChanged.append(self.__playStateChanged)
997 self.pvrStateDialog = self.session.instantiateDialog(screen)
998 self.onShow.append(self._mayShow)
999 self.onHide.append(self.pvrStateDialog.hide)
1002 if self.execing and self.seekstate != self.SEEK_STATE_PLAY:
1003 self.pvrStateDialog.show()
1005 def __playStateChanged(self, state):
1006 playstateString = state[3]
1007 self.pvrStateDialog["state"].setText(playstateString)
1010 class InfoBarTimeshiftState(InfoBarPVRState):
1012 InfoBarPVRState.__init__(self, screen=TimeshiftState)
1015 if self.execing and self.timeshift_enabled and self.seekstate != self.SEEK_STATE_PLAY:
1016 self.pvrStateDialog.show()
1018 class InfoBarShowMovies:
1020 # i don't really like this class.
1021 # it calls a not further specified "movie list" on up/down/movieList,
1022 # so this is not more than an action map
1024 self["MovieListActions"] = HelpableActionMap(self, "InfobarMovieListActions",
1026 "movieList": (self.showMovies, _("movie list")),
1027 "up": (self.showMovies, _("movie list")),
1028 "down": (self.showMovies, _("movie list"))
1031 # InfoBarTimeshift requires InfoBarSeek, instantiated BEFORE!
1035 # Timeshift works the following way:
1036 # demux0 demux1 "TimeshiftActions" "TimeshiftActivateActions" "SeekActions"
1037 # - normal playback TUNER unused PLAY enable disable disable
1038 # - user presses "yellow" button. FILE record PAUSE enable disable enable
1039 # - user presess pause again FILE record PLAY enable disable enable
1040 # - user fast forwards FILE record FF enable disable enable
1041 # - end of timeshift buffer reached TUNER record PLAY enable enable disable
1042 # - user backwards FILE record BACK # !! enable disable enable
1046 # - when a service is playing, pressing the "timeshiftStart" button ("yellow") enables recording ("enables timeshift"),
1047 # freezes the picture (to indicate timeshift), sets timeshiftMode ("activates timeshift")
1048 # now, the service becomes seekable, so "SeekActions" are enabled, "TimeshiftEnableActions" are disabled.
1049 # - the user can now PVR around
1050 # - if it hits the end, the service goes into live mode ("deactivates timeshift", it's of course still "enabled")
1051 # the service looses it's "seekable" state. It can still be paused, but just to activate timeshift right
1053 # the seek actions will be disabled, but the timeshiftActivateActions will be enabled
1054 # - if the user rewinds, or press pause, timeshift will be activated again
1056 # note that a timeshift can be enabled ("recording") and
1057 # activated (currently time-shifting).
1059 class InfoBarTimeshift:
1061 self["TimeshiftActions"] = HelpableActionMap(self, "InfobarTimeshiftActions",
1063 "timeshiftStart": (self.startTimeshift, _("start timeshift")), # the "yellow key"
1064 "timeshiftStop": (self.stopTimeshift, _("stop timeshift")) # currently undefined :), probably 'TV'
1066 self["TimeshiftActivateActions"] = ActionMap(["InfobarTimeshiftActivateActions"],
1068 "timeshiftActivateEnd": self.activateTimeshiftEnd, # something like "rewind key"
1069 "timeshiftActivateEndAndPause": self.activateTimeshiftEndAndPause # something like "pause key"
1070 }, prio=-1) # priority over record
1072 self.timeshift_enabled = 0
1073 self.timeshift_state = 0
1074 self.ts_rewind_timer = eTimer()
1075 self.ts_rewind_timer.callback.append(self.rewindService)
1077 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
1079 iPlayableService.evStart: self.__serviceStarted,
1080 iPlayableService.evSeekableStatusChanged: self.__seekableStatusChanged
1083 def getTimeshift(self):
1084 service = self.session.nav.getCurrentService()
1085 return service and service.timeshift()
1087 def startTimeshift(self):
1088 print "enable timeshift"
1089 ts = self.getTimeshift()
1091 self.session.open(MessageBox, _("Timeshift not possible!"), MessageBox.TYPE_ERROR)
1092 print "no ts interface"
1095 if self.timeshift_enabled:
1096 print "hu, timeshift already enabled?"
1098 if not ts.startTimeshift():
1099 self.timeshift_enabled = 1
1101 # we remove the "relative time" for now.
1102 #self.pvrStateDialog["timeshift"].setRelative(time.time())
1105 #self.setSeekState(self.SEEK_STATE_PAUSE)
1106 self.activateTimeshiftEnd(False)
1108 # enable the "TimeshiftEnableActions", which will override
1109 # the startTimeshift actions
1110 self.__seekableStatusChanged()
1112 print "timeshift failed"
1114 def stopTimeshift(self):
1115 if not self.timeshift_enabled:
1117 print "disable timeshift"
1118 ts = self.getTimeshift()
1121 self.session.openWithCallback(self.stopTimeshiftConfirmed, MessageBox, _("Stop Timeshift?"), MessageBox.TYPE_YESNO)
1123 def stopTimeshiftConfirmed(self, confirmed):
1127 ts = self.getTimeshift()
1132 self.timeshift_enabled = 0
1135 self.__seekableStatusChanged()
1137 # activates timeshift, and seeks to (almost) the end
1138 def activateTimeshiftEnd(self, back = True):
1139 ts = self.getTimeshift()
1140 print "activateTimeshiftEnd"
1145 if ts.isTimeshiftActive():
1146 print "!! activate timeshift called - but shouldn't this be a normal pause?"
1150 ts.activateTimeshift() # activate timeshift will automatically pause
1151 self.setSeekState(self.SEEK_STATE_PAUSE)
1154 self.doSeek(-5) # seek some gops before end
1155 self.ts_rewind_timer.start(200, 1)
1157 self.doSeek(-1) # seek 1 gop before end
1159 def rewindService(self):
1160 self.setSeekState(self.makeStateBackward(int(config.seek.enter_backward.value)))
1162 # same as activateTimeshiftEnd, but pauses afterwards.
1163 def activateTimeshiftEndAndPause(self):
1164 print "activateTimeshiftEndAndPause"
1165 #state = self.seekstate
1166 self.activateTimeshiftEnd(False)
1168 def __seekableStatusChanged(self):
1171 # print "self.isSeekable", self.isSeekable()
1172 # print "self.timeshift_enabled", self.timeshift_enabled
1174 # when this service is not seekable, but timeshift
1175 # is enabled, this means we can activate
1177 if not self.isSeekable() and self.timeshift_enabled:
1180 # print "timeshift activate:", enabled
1181 self["TimeshiftActivateActions"].setEnabled(enabled)
1183 def __serviceStarted(self):
1184 self.timeshift_enabled = False
1185 self.__seekableStatusChanged()
1187 from Screens.PiPSetup import PiPSetup
1189 class InfoBarExtensions:
1190 EXTENSION_SINGLE = 0
1196 self["InstantExtensionsActions"] = HelpableActionMap(self, "InfobarExtensions",
1198 "extensions": (self.showExtensionSelection, _("view extensions...")),
1201 def addExtension(self, extension, key = None, type = EXTENSION_SINGLE):
1202 self.list.append((type, extension, key))
1204 def updateExtension(self, extension, key = None):
1205 self.extensionsList.append(extension)
1207 if self.extensionKeys.has_key(key):
1211 for x in self.availableKeys:
1212 if not self.extensionKeys.has_key(x):
1217 self.extensionKeys[key] = len(self.extensionsList) - 1
1219 def updateExtensions(self):
1220 self.extensionsList = []
1221 self.availableKeys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ]
1222 self.extensionKeys = {}
1224 if x[0] == self.EXTENSION_SINGLE:
1225 self.updateExtension(x[1], x[2])
1228 self.updateExtension(y[0], y[1])
1231 def showExtensionSelection(self):
1232 self.updateExtensions()
1233 extensionsList = self.extensionsList[:]
1236 for x in self.availableKeys:
1237 if self.extensionKeys.has_key(x):
1238 entry = self.extensionKeys[x]
1239 extension = self.extensionsList[entry]
1241 name = str(extension[0]())
1242 list.append((extension[0](), extension))
1244 extensionsList.remove(extension)
1246 extensionsList.remove(extension)
1247 for x in extensionsList:
1248 list.append((x[0](), x))
1249 keys += [""] * len(extensionsList)
1250 self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list, keys = keys)
1252 def extensionCallback(self, answer):
1253 if answer is not None:
1256 from Tools.BoundFunction import boundFunction
1258 # depends on InfoBarExtensions
1259 from Components.PluginComponent import plugins
1261 class InfoBarPlugins:
1263 self.addExtension(extension = self.getPluginList, type = InfoBarExtensions.EXTENSION_LIST)
1265 def getPluginName(self, name):
1268 def getPluginList(self):
1270 for p in plugins.getPlugins(where = PluginDescriptor.WHERE_EXTENSIONSMENU):
1271 list.append(((boundFunction(self.getPluginName, p.name), boundFunction(self.runPlugin, p), lambda: True), None))
1274 def runPlugin(self, plugin):
1275 plugin(session = self.session, servicelist = self.servicelist)
1277 # depends on InfoBarExtensions
1278 class InfoBarSleepTimer:
1280 self.addExtension((self.getSleepTimerName, self.showSleepTimerSetup, lambda: True), "1")
1282 def getSleepTimerName(self):
1283 return _("Sleep Timer")
1285 def showSleepTimerSetup(self):
1286 self.session.open(SleepTimerEdit)
1288 # depends on InfoBarExtensions
1291 self.session.pipshown = False
1292 if SystemInfo.get("NumVideoDecoders", 1) > 1:
1293 self.addExtension((self.getShowHideName, self.showPiP, lambda: True), "blue")
1294 self.addExtension((self.getMoveName, self.movePiP, self.pipShown), "green")
1295 self.addExtension((self.getSwapName, self.swapPiP, self.pipShown), "yellow")
1298 return self.session.pipshown
1300 def pipHandles0Action(self):
1301 return self.pipShown() and config.usage.pip_zero_button.value != "standard"
1303 def getShowHideName(self):
1304 if self.session.pipshown:
1305 return _("Disable Picture in Picture")
1307 return _("Activate Picture in Picture")
1309 def getSwapName(self):
1310 return _("Swap Services")
1312 def getMoveName(self):
1313 return _("Move Picture in Picture")
1316 if self.session.pipshown:
1317 del self.session.pip
1318 self.session.pipshown = False
1320 self.session.pip = self.session.instantiateDialog(PictureInPicture)
1321 self.session.pip.show()
1322 newservice = self.session.nav.getCurrentlyPlayingServiceReference()
1323 if self.session.pip.playService(newservice):
1324 self.session.pipshown = True
1325 self.session.pip.servicePath = self.servicelist.getCurrentServicePath()
1327 self.session.pipshown = False
1328 del self.session.pip
1329 self.session.nav.playService(newservice)
1332 swapservice = self.session.nav.getCurrentlyPlayingServiceReference()
1333 if self.session.pip.servicePath:
1334 servicepath = self.servicelist.getCurrentServicePath()
1335 ref=servicepath[len(servicepath)-1]
1336 pipref=self.session.pip.getCurrentService()
1337 self.session.pip.playService(swapservice)
1338 self.servicelist.setCurrentServicePath(self.session.pip.servicePath)
1339 if pipref.toString() != ref.toString(): # is a subservice ?
1340 self.session.nav.stopService() # stop portal
1341 self.session.nav.playService(pipref) # start subservice
1342 self.session.pip.servicePath=servicepath
1345 self.session.open(PiPSetup, pip = self.session.pip)
1347 def pipDoHandle0Action(self):
1348 use = config.usage.pip_zero_button.value
1351 elif "swapstop" == use:
1357 from RecordTimer import parseEvent, RecordTimerEntry
1359 class InfoBarInstantRecord:
1360 """Instant Record - handles the instantRecord action in order to
1361 start/stop instant records"""
1363 self["InstantRecordActions"] = HelpableActionMap(self, "InfobarInstantRecord",
1365 "instantRecord": (self.instantRecord, _("Instant Record...")),
1369 def stopCurrentRecording(self, entry = -1):
1370 if entry is not None and entry != -1:
1371 self.session.nav.RecordTimer.removeEntry(self.recording[entry])
1372 self.recording.remove(self.recording[entry])
1374 def startInstantRecording(self, limitEvent = False):
1375 serviceref = self.session.nav.getCurrentlyPlayingServiceReference()
1377 # try to get event info
1380 service = self.session.nav.getCurrentService()
1381 epg = eEPGCache.getInstance()
1382 event = epg.lookupEventTime(serviceref, -1, 0)
1384 info = service.info()
1385 ev = info.getEvent(0)
1391 end = time() + 3600 * 10
1392 name = "instant record"
1396 if event is not None:
1397 curEvent = parseEvent(event)
1399 description = curEvent[3]
1400 eventid = curEvent[4]
1405 self.session.open(MessageBox, _("No event info found, recording indefinitely."), MessageBox.TYPE_INFO)
1408 if isinstance(serviceref, eServiceReference):
1409 serviceref = ServiceReference(serviceref)
1411 recording = RecordTimerEntry(serviceref, begin, end, name, description, eventid, dirname = config.movielist.last_videodir.value)
1412 recording.dontSave = True
1414 self.session.nav.RecordTimer.record(recording)
1415 self.recording.append(recording)
1417 def isInstantRecordRunning(self):
1418 print "self.recording:", self.recording
1419 if len(self.recording) > 0:
1420 for x in self.recording:
1425 def recordQuestionCallback(self, answer):
1426 print "pre:\n", self.recording
1428 if answer is None or answer[1] == "no":
1431 recording = self.recording[:]
1433 if not x in self.session.nav.RecordTimer.timer_list:
1434 self.recording.remove(x)
1435 elif x.dontSave and x.isRunning():
1436 list.append((x, False))
1438 if answer[1] == "changeduration":
1439 if len(self.recording) == 1:
1440 self.changeDuration(0)
1442 self.session.openWithCallback(self.changeDuration, TimerSelection, list)
1443 elif answer[1] == "changeendtime":
1444 if len(self.recording) == 1:
1447 self.session.openWithCallback(self.setEndtime, TimerSelection, list)
1448 elif answer[1] == "stop":
1449 if len(self.recording) == 1:
1450 self.stopCurrentRecording(0)
1452 self.session.openWithCallback(self.stopCurrentRecording, TimerSelection, list)
1453 elif answer[1] in ( "indefinitely" , "manualduration", "manualendtime", "event"):
1454 self.startInstantRecording(limitEvent = answer[1] in ("event", "manualendtime") or False)
1455 if answer[1] == "manualduration":
1456 self.changeDuration(len(self.recording)-1)
1457 elif answer[1] == "manualendtime":
1458 self.setEndtime(len(self.recording)-1)
1459 print "after:\n", self.recording
1461 def setEndtime(self, entry):
1462 if entry is not None:
1463 self.selectedEntry = entry
1464 self.endtime=ConfigClock(default = self.recording[self.selectedEntry].end)
1465 dlg = self.session.openWithCallback(self.TimeDateInputClosed, TimeDateInput, self.endtime)
1466 dlg.setTitle(_("Please change recording endtime"))
1468 def TimeDateInputClosed(self, ret):
1471 localendtime = localtime(ret[1])
1472 print "stopping recording at", strftime("%c", localendtime)
1473 self.recording[self.selectedEntry].end = ret[1]
1474 self.session.nav.RecordTimer.timeChanged(self.recording[self.selectedEntry])
1476 def changeDuration(self, entry):
1477 if entry is not None:
1478 self.selectedEntry = entry
1479 self.session.openWithCallback(self.inputCallback, InputBox, title=_("How many minutes do you want to record?"), text="5", maxSize=False, type=Input.NUMBER)
1481 def inputCallback(self, value):
1482 if value is not None:
1483 print "stopping recording after", int(value), "minutes."
1484 self.recording[self.selectedEntry].end = time() + 60 * int(value)
1485 self.session.nav.RecordTimer.timeChanged(self.recording[self.selectedEntry])
1487 def instantRecord(self):
1488 dir = config.movielist.last_videodir.value
1489 if not pathExists(dir):
1490 dir = resolveFilename(SCOPE_HDD)
1494 # XXX: this message is a little odd as we might be recording to a remote device
1495 self.session.open(MessageBox, _("No HDD found or HDD not initialized!"), MessageBox.TYPE_ERROR)
1498 if self.isInstantRecordRunning():
1499 self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
1500 title=_("A recording is currently running.\nWhat do you want to do?"), \
1501 list=[(_("stop recording"), "stop"), \
1502 (_("change recording (duration)"), "changeduration"), \
1503 (_("change recording (endtime)"), "changeendtime"), \
1504 (_("add recording (indefinitely)"), "indefinitely"), \
1505 (_("add recording (stop after current event)"), "event"), \
1506 (_("add recording (enter recording duration)"), "manualduration"), \
1507 (_("add recording (enter recording endtime)"), "manualendtime"), \
1508 (_("do nothing"), "no")])
1510 self.session.openWithCallback(self.recordQuestionCallback, ChoiceBox, \
1511 title=_("Start recording?"), \
1512 list=[(_("add recording (indefinitely)"), "indefinitely"), \
1513 (_("add recording (stop after current event)"), "event"), \
1514 (_("add recording (enter recording duration)"), "manualduration"), \
1515 (_("add recording (enter recording endtime)"), "manualendtime"), \
1516 (_("don't record"), "no")])
1518 from Tools.ISO639 import LanguageCodes
1520 class InfoBarAudioSelection:
1522 self["AudioSelectionAction"] = HelpableActionMap(self, "InfobarAudioSelectionActions",
1524 "audioSelection": (self.audioSelection, _("Audio Options...")),
1527 def audioSelection(self):
1528 service = self.session.nav.getCurrentService()
1529 self.audioTracks = audio = service and service.audioTracks()
1530 n = audio and audio.getNumberOfTracks() or 0
1533 self.audioChannel = service.audioChannel()
1536 i = audio.getTrackInfo(x)
1537 language = i.getLanguage()
1538 description = i.getDescription()
1540 if LanguageCodes.has_key(language):
1541 language = LanguageCodes[language][0]
1543 if len(description):
1544 description += " (" + language + ")"
1546 description = language
1548 tlist.append((description, x))
1550 tlist.sort(key=lambda x: x[0])
1552 selectedAudio = self.audioTracks.getCurrentTrack()
1557 if x[1] != selectedAudio:
1562 if SystemInfo["CanDownmixAC3"]:
1563 tlist = [(_("AC3 downmix") + " - " +[_("Off"), _("On")][config.av.downmix_ac3.value and 1 or 0], "CALLFUNC", self.changeAC3Downmix),
1564 ([_("Left"), _("Stereo"), _("Right")][self.audioChannel.getCurrentChannel()], "mode"),
1566 keys = [ "red", "green", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
1569 tlist = [([_("Left"), _("Stereo"), _("Right")][self.audioChannel.getCurrentChannel()], "mode"), ("--", "")] + tlist
1570 keys = [ "red", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
1572 self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = tlist, selection = selection, keys = keys)
1574 del self.audioTracks
1576 def changeAC3Downmix(self, arg):
1577 choicelist = self.session.current_dialog["list"]
1578 list = choicelist.list
1580 list[0][1]=(t[0], t[1], t[2], t[3], t[4], t[5], t[6],
1581 _("AC3 downmix") + " - " +[_("On"), _("Off")][config.av.downmix_ac3.value and 1 or 0])
1582 choicelist.setList(list)
1583 if config.av.downmix_ac3.value:
1584 config.av.downmix_ac3.value = False
1586 config.av.downmix_ac3.value = True
1587 config.av.downmix_ac3.save()
1589 def audioSelected(self, audio):
1590 if audio is not None:
1591 if isinstance(audio[1], str):
1592 if audio[1] == "mode":
1593 keys = ["red", "green", "yellow"]
1594 selection = self.audioChannel.getCurrentChannel()
1595 tlist = [(_("left"), 0), (_("stereo"), 1), (_("right"), 2)]
1596 self.session.openWithCallback(self.modeSelected, ChoiceBox, title=_("Select audio mode"), list = tlist, selection = selection, keys = keys)
1598 del self.audioChannel
1599 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > audio[1]:
1600 self.audioTracks.selectTrack(audio[1])
1602 del self.audioChannel
1603 del self.audioTracks
1605 def modeSelected(self, mode):
1606 if mode is not None:
1607 self.audioChannel.selectChannel(mode[1])
1608 del self.audioChannel
1610 class InfoBarSubserviceSelection:
1612 self["SubserviceSelectionAction"] = HelpableActionMap(self, "InfobarSubserviceSelectionActions",
1614 "subserviceSelection": (self.subserviceSelection, _("Subservice list...")),
1617 self["SubserviceQuickzapAction"] = HelpableActionMap(self, "InfobarSubserviceQuickzapActions",
1619 "nextSubservice": (self.nextSubservice, _("Switch to next subservice")),
1620 "prevSubservice": (self.prevSubservice, _("Switch to previous subservice"))
1622 self["SubserviceQuickzapAction"].setEnabled(False)
1624 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
1626 iPlayableService.evUpdatedEventInfo: self.checkSubservicesAvail
1631 def checkSubservicesAvail(self):
1632 service = self.session.nav.getCurrentService()
1633 subservices = service and service.subServices()
1634 if not subservices or subservices.getNumberOfSubservices() == 0:
1635 self["SubserviceQuickzapAction"].setEnabled(False)
1637 def nextSubservice(self):
1638 self.changeSubservice(+1)
1640 def prevSubservice(self):
1641 self.changeSubservice(-1)
1643 def changeSubservice(self, direction):
1644 service = self.session.nav.getCurrentService()
1645 subservices = service and service.subServices()
1646 n = subservices and subservices.getNumberOfSubservices()
1649 ref = self.session.nav.getCurrentlyPlayingServiceReference()
1651 if subservices.getSubservice(x).toString() == ref.toString():
1654 selection += direction
1659 newservice = subservices.getSubservice(selection)
1660 if newservice.valid():
1663 self.session.nav.playService(newservice, False)
1665 def subserviceSelection(self):
1666 service = self.session.nav.getCurrentService()
1667 subservices = service and service.subServices()
1668 self.bouquets = self.servicelist.getBouquetList()
1669 n = subservices and subservices.getNumberOfSubservices()
1672 ref = self.session.nav.getCurrentlyPlayingServiceReference()
1675 i = subservices.getSubservice(x)
1676 if i.toString() == ref.toString():
1678 tlist.append((i.getName(), i))
1680 if self.bouquets and len(self.bouquets):
1681 keys = ["red", "blue", "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * n
1682 if config.usage.multibouquet.value:
1683 tlist = [(_("Quickzap"), "quickzap", service.subServices()), (_("Add to bouquet"), "CALLFUNC", self.addSubserviceToBouquetCallback), ("--", "")] + tlist
1685 tlist = [(_("Quickzap"), "quickzap", service.subServices()), (_("Add to favourites"), "CALLFUNC", self.addSubserviceToBouquetCallback), ("--", "")] + tlist
1688 tlist = [(_("Quickzap"), "quickzap", service.subServices()), ("--", "")] + tlist
1689 keys = ["red", "", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * n
1692 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice..."), list = tlist, selection = selection, keys = keys)
1694 def subserviceSelected(self, service):
1696 if not service is None:
1697 if isinstance(service[1], str):
1698 if service[1] == "quickzap":
1699 from Screens.SubservicesQuickzap import SubservicesQuickzap
1700 self.session.open(SubservicesQuickzap, service[2])
1702 self["SubserviceQuickzapAction"].setEnabled(True)
1703 self.session.nav.playService(service[1], False)
1705 def addSubserviceToBouquetCallback(self, service):
1706 if len(service) > 1 and isinstance(service[1], eServiceReference):
1707 self.selectedSubservice = service
1708 if self.bouquets is None:
1711 cnt = len(self.bouquets)
1712 if cnt > 1: # show bouquet list
1713 self.bsel = self.session.openWithCallback(self.bouquetSelClosed, BouquetSelector, self.bouquets, self.addSubserviceToBouquet)
1714 elif cnt == 1: # add to only one existing bouquet
1715 self.addSubserviceToBouquet(self.bouquets[0][1])
1716 self.session.open(MessageBox, _("Service has been added to the favourites."), MessageBox.TYPE_INFO)
1718 def bouquetSelClosed(self, confirmed):
1720 del self.selectedSubservice
1722 self.session.open(MessageBox, _("Service has been added to the selected bouquet."), MessageBox.TYPE_INFO)
1724 def addSubserviceToBouquet(self, dest):
1725 self.servicelist.addServiceToBouquet(dest, self.selectedSubservice[1])
1727 self.bsel.close(True)
1729 del self.selectedSubservice
1731 class InfoBarAdditionalInfo:
1734 self["RecordingPossible"] = Boolean(fixed=harddiskmanager.HDDCount() > 0 and config.misc.rcused.value == 1)
1735 self["TimeshiftPossible"] = self["RecordingPossible"]
1736 self["ShowTimeshiftOnYellow"] = Boolean(fixed=(not config.misc.rcused.value == 0))
1737 self["ShowAudioOnYellow"] = Boolean(fixed=config.misc.rcused.value == 0)
1738 self["ShowRecordOnRed"] = Boolean(fixed=config.misc.rcused.value == 1)
1739 self["ExtensionsAvailable"] = Boolean(fixed=1)
1741 class InfoBarNotifications:
1743 self.onExecBegin.append(self.checkNotifications)
1744 Notifications.notificationAdded.append(self.checkNotificationsIfExecing)
1745 self.onClose.append(self.__removeNotification)
1747 def __removeNotification(self):
1748 Notifications.notificationAdded.remove(self.checkNotificationsIfExecing)
1750 def checkNotificationsIfExecing(self):
1752 self.checkNotifications()
1754 def checkNotifications(self):
1755 if len(Notifications.notifications):
1756 n = Notifications.notifications[0]
1758 Notifications.notifications = Notifications.notifications[1:]
1761 if n[3].has_key("onSessionOpenCallback"):
1762 n[3]["onSessionOpenCallback"]()
1763 del n[3]["onSessionOpenCallback"]
1766 dlg = self.session.openWithCallback(cb, n[1], *n[2], **n[3])
1768 dlg = self.session.open(n[1], *n[2], **n[3])
1770 # remember that this notification is currently active
1772 Notifications.current_notifications.append(d)
1773 dlg.onClose.append(boundFunction(self.__notificationClosed, d))
1775 def __notificationClosed(self, d):
1776 Notifications.current_notifications.remove(d)
1778 class InfoBarServiceNotifications:
1780 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
1782 iPlayableService.evEnd: self.serviceHasEnded
1785 def serviceHasEnded(self):
1786 print "service end!"
1789 self.setSeekState(self.SEEK_STATE_PLAY)
1793 class InfoBarCueSheetSupport:
1799 ENABLE_RESUME_SUPPORT = False
1801 def __init__(self, actionmap = "InfobarCueSheetActions"):
1802 self["CueSheetActions"] = HelpableActionMap(self, actionmap,
1804 "jumpPreviousMark": (self.jumpPreviousMark, _("jump to previous marked position")),
1805 "jumpNextMark": (self.jumpNextMark, _("jump to next marked position")),
1806 "toggleMark": (self.toggleMark, _("toggle a cut mark at the current position"))
1810 self.is_closing = False
1811 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
1813 iPlayableService.evStart: self.__serviceStarted,
1816 def __serviceStarted(self):
1819 print "new service started! trying to download cuts!"
1820 self.downloadCuesheet()
1822 if self.ENABLE_RESUME_SUPPORT:
1825 for (pts, what) in self.cut_list:
1826 if what == self.CUT_TYPE_LAST:
1829 if last is not None:
1830 self.resume_point = last
1831 if config.usage.on_movie_start.value == "ask":
1832 Notifications.AddNotificationWithCallback(self.playLastCB, MessageBox, _("Do you want to resume this playback?"), timeout=10)
1833 elif config.usage.on_movie_start.value == "resume":
1834 # TRANSLATORS: The string "Resuming playback" flashes for a moment
1835 # TRANSLATORS: at the start of a movie, when the user has selected
1836 # TRANSLATORS: "Resume from last position" as start behavior.
1837 # TRANSLATORS: The purpose is to notify the user that the movie starts
1838 # TRANSLATORS: in the middle somewhere and not from the beginning.
1839 # TRANSLATORS: (Some translators seem to have interpreted it as a
1840 # TRANSLATORS: question or a choice, but it is a statement.)
1841 Notifications.AddNotificationWithCallback(self.playLastCB, MessageBox, _("Resuming playback"), timeout=2, type=MessageBox.TYPE_INFO)
1843 def playLastCB(self, answer):
1845 self.doSeek(self.resume_point)
1846 self.hideAfterResume()
1848 def hideAfterResume(self):
1849 if isinstance(self, InfoBarShowHide):
1852 def __getSeekable(self):
1853 service = self.session.nav.getCurrentService()
1856 return service.seek()
1858 def cueGetCurrentPosition(self):
1859 seek = self.__getSeekable()
1862 r = seek.getPlayPosition()
1867 def cueGetEndCutPosition(self):
1870 for cp in self.cut_list:
1871 if cp[1] == self.CUT_TYPE_OUT:
1875 elif cp[1] == self.CUT_TYPE_IN:
1879 def jumpPreviousNextMark(self, cmp, start=False):
1880 current_pos = self.cueGetCurrentPosition()
1881 if current_pos is None:
1883 mark = self.getNearestCutPoint(current_pos, cmp=cmp, start=start)
1884 if mark is not None:
1892 def jumpPreviousMark(self):
1893 # we add 2 seconds, so if the play position is <2s after
1894 # the mark, the mark before will be used
1895 self.jumpPreviousNextMark(lambda x: -x-5*90000, start=True)
1897 def jumpNextMark(self):
1898 if not self.jumpPreviousNextMark(lambda x: x):
1901 def getNearestCutPoint(self, pts, cmp=abs, start=False):
1907 bestdiff = cmp(0 - pts)
1909 nearest = [0, False]
1910 for cp in self.cut_list:
1911 if beforecut and cp[1] in [self.CUT_TYPE_IN, self.CUT_TYPE_OUT]:
1913 if cp[1] == self.CUT_TYPE_IN: # Start is here, disregard previous marks
1914 diff = cmp(cp[0] - pts)
1920 if cp[1] in [self.CUT_TYPE_MARK, self.CUT_TYPE_LAST]:
1921 diff = cmp(cp[0] - pts)
1922 if diff >= 0 and (nearest is None or bestdiff > diff):
1927 def toggleMark(self, onlyremove=False, onlyadd=False, tolerance=5*90000, onlyreturn=False):
1928 current_pos = self.cueGetCurrentPosition()
1929 if current_pos is None:
1930 print "not seekable"
1933 nearest_cutpoint = self.getNearestCutPoint(current_pos)
1935 if nearest_cutpoint is not None and abs(nearest_cutpoint[0] - current_pos) < tolerance:
1937 return nearest_cutpoint
1939 self.removeMark(nearest_cutpoint)
1940 elif not onlyremove and not onlyreturn:
1941 self.addMark((current_pos, self.CUT_TYPE_MARK))
1946 def addMark(self, point):
1947 insort(self.cut_list, point)
1948 self.uploadCuesheet()
1949 self.showAfterCuesheetOperation()
1951 def removeMark(self, point):
1952 self.cut_list.remove(point)
1953 self.uploadCuesheet()
1954 self.showAfterCuesheetOperation()
1956 def showAfterCuesheetOperation(self):
1957 if isinstance(self, InfoBarShowHide):
1960 def __getCuesheet(self):
1961 service = self.session.nav.getCurrentService()
1964 return service.cueSheet()
1966 def uploadCuesheet(self):
1967 cue = self.__getCuesheet()
1970 print "upload failed, no cuesheet interface"
1972 cue.setCutList(self.cut_list)
1974 def downloadCuesheet(self):
1975 cue = self.__getCuesheet()
1978 print "download failed, no cuesheet interface"
1981 self.cut_list = cue.getCutList()
1983 class InfoBarSummary(Screen):
1985 <screen position="0,0" size="132,64">
1986 <widget source="global.CurrentTime" render="Label" position="62,46" size="82,18" font="Regular;16" >
1987 <convert type="ClockToText">WithSeconds</convert>
1989 <widget source="session.RecordState" render="FixedLabel" text=" " position="62,46" size="82,18" zPosition="1" >
1990 <convert type="ConfigEntryTest">config.usage.blinking_display_clock_during_recording,True,CheckSourceBoolean</convert>
1991 <convert type="ConditionalShowHide">Blink</convert>
1993 <widget source="session.CurrentService" render="Label" position="6,4" size="120,42" font="Regular;18" >
1994 <convert type="ServiceName">Name</convert>
1996 <widget source="session.Event_Now" render="Progress" position="6,46" size="46,18" borderWidth="1" >
1997 <convert type="EventTime">Progress</convert>
2001 # for picon: (path="piconlcd" will use LCD picons)
2002 # <widget source="session.CurrentService" render="Picon" position="6,0" size="120,64" path="piconlcd" >
2003 # <convert type="ServiceName">Reference</convert>
2006 def __init__(self, session, parent):
2007 Screen.__init__(self, session, parent = parent)
2009 class InfoBarSummarySupport:
2013 def createSummary(self):
2014 return InfoBarSummary
2016 class InfoBarMoviePlayerSummary(Screen):
2018 <screen position="0,0" size="132,64">
2019 <widget source="global.CurrentTime" render="Label" position="62,46" size="64,18" font="Regular;16" halign="right" >
2020 <convert type="ClockToText">WithSeconds</convert>
2022 <widget source="session.RecordState" render="FixedLabel" text=" " position="62,46" size="64,18" zPosition="1" >
2023 <convert type="ConfigEntryTest">config.usage.blinking_display_clock_during_recording,True,CheckSourceBoolean</convert>
2024 <convert type="ConditionalShowHide">Blink</convert>
2026 <widget source="session.CurrentService" render="Label" position="6,4" size="120,42" font="Regular;18" >
2027 <convert type="ServiceName">Name</convert>
2029 <widget source="session.CurrentService" render="Progress" position="6,46" size="56,18" borderWidth="1" >
2030 <convert type="ServicePosition">Position</convert>
2034 def __init__(self, session, parent):
2035 Screen.__init__(self, session)
2037 class InfoBarMoviePlayerSummarySupport:
2041 def createSummary(self):
2042 return InfoBarMoviePlayerSummary
2044 class InfoBarTeletextPlugin:
2046 self.teletext_plugin = None
2048 for p in plugins.getPlugins(PluginDescriptor.WHERE_TELETEXT):
2049 self.teletext_plugin = p
2051 if self.teletext_plugin is not None:
2052 self["TeletextActions"] = HelpableActionMap(self, "InfobarTeletextActions",
2054 "startTeletext": (self.startTeletext, _("View teletext..."))
2057 print "no teletext plugin found!"
2059 def startTeletext(self):
2060 self.teletext_plugin(session=self.session, service=self.session.nav.getCurrentService())
2062 class InfoBarSubtitleSupport(object):
2064 object.__init__(self)
2065 self.subtitle_window = self.session.instantiateDialog(SubtitleDisplay)
2066 self.__subtitles_enabled = False
2068 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
2070 iPlayableService.evEnd: self.__serviceStopped,
2071 iPlayableService.evUpdatedInfo: self.__updatedInfo
2073 self.cached_subtitle_checked = False
2074 self.__selected_subtitle = None
2076 def __serviceStopped(self):
2077 self.subtitle_window.hide()
2078 self.__subtitles_enabled = False
2079 self.cached_subtitle_checked = False
2081 def __updatedInfo(self):
2082 if not self.cached_subtitle_checked:
2083 subtitle = self.getCurrentServiceSubtitle()
2084 self.cached_subtitle_checked = True
2085 self.__selected_subtitle = subtitle and subtitle.getCachedSubtitle()
2086 if self.__selected_subtitle:
2087 subtitle.enableSubtitles(self.subtitle_window.instance, self.selected_subtitle)
2088 self.subtitle_window.show()
2089 self.__subtitles_enabled = True
2091 def getCurrentServiceSubtitle(self):
2092 service = self.session.nav.getCurrentService()
2093 return service and service.subtitle()
2095 def setSubtitlesEnable(self, enable=True):
2096 subtitle = self.getCurrentServiceSubtitle()
2097 if enable and self.__selected_subtitle is not None:
2098 if subtitle and not self.__subtitles_enabled:
2099 subtitle.enableSubtitles(self.subtitle_window.instance, self.selected_subtitle)
2100 self.subtitle_window.show()
2101 self.__subtitles_enabled = True
2104 subtitle.disableSubtitles(self.subtitle_window.instance)
2105 self.__subtitles_enabled = False
2106 self.subtitle_window.hide()
2108 def setSelectedSubtitle(self, subtitle):
2109 self.__selected_subtitle = subtitle
2111 subtitles_enabled = property(lambda self: self.__subtitles_enabled, setSubtitlesEnable)
2112 selected_subtitle = property(lambda self: self.__selected_subtitle, setSelectedSubtitle)
2114 class InfoBarServiceErrorPopupSupport:
2116 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
2118 iPlayableService.evTuneFailed: self.__tuneFailed,
2119 iPlayableService.evStart: self.__serviceStarted
2121 self.__serviceStarted()
2123 def __serviceStarted(self):
2124 self.last_error = None
2125 Notifications.RemovePopup(id = "ZapError")
2127 def __tuneFailed(self):
2128 service = self.session.nav.getCurrentService()
2129 info = service and service.info()
2130 error = info and info.getInfo(iServiceInformation.sDVBState)
2132 if error == self.last_error:
2135 self.last_error = error
2138 eDVBServicePMTHandler.eventNoResources: _("No free tuner!"),
2139 eDVBServicePMTHandler.eventTuneFailed: _("Tune failed!"),
2140 eDVBServicePMTHandler.eventNoPAT: _("No data on transponder!\n(Timeout reading PAT)"),
2141 eDVBServicePMTHandler.eventNoPATEntry: _("Service not found!\n(SID not found in PAT)"),
2142 eDVBServicePMTHandler.eventNoPMT: _("Service invalid!\n(Timeout reading PMT)"),
2143 eDVBServicePMTHandler.eventNewProgramInfo: None,
2144 eDVBServicePMTHandler.eventTuned: None,
2145 eDVBServicePMTHandler.eventSOF: None,
2146 eDVBServicePMTHandler.eventEOF: None,
2147 eDVBServicePMTHandler.eventMisconfiguration: _("Service unavailable!\nCheck tuner configuration!"),
2150 error = errors.get(error) #this returns None when the key not exist in the dict
2152 if error is not None:
2153 Notifications.AddPopup(text = error, type = MessageBox.TYPE_ERROR, timeout = 5, id = "ZapError")
2155 Notifications.RemovePopup(id = "ZapError")