add InfoBarSubtitleSupport
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
index d08a050b343850a4fbf5f135cb616281bc428618..2f7b36c3e3855163c3b70374240c7757cb6b68a3 100644 (file)
@@ -13,7 +13,7 @@ from Components.PluginComponent import plugins
 from Components.ProgressBar import *
 from Components.ServiceEventTracker import ServiceEventTracker
 from Components.ServiceName import ServiceName
-from Components.config import config, configElement, ConfigSubsection, configSequence, configElementBoolean
+from Components.config import config, configElement, ConfigSubsection, configSequence, configElementBoolean, configSelection, configElement_nonSave, getConfigListEntry
 from Components.config import configfile, configsequencearg
 from Components.TimerList import TimerEntryComponent
 from Components.TunerInfo import TunerInfo
@@ -30,6 +30,7 @@ from Screens.MessageBox import MessageBox
 from Screens.MinuteInput import MinuteInput
 from Screens.TimerSelection import TimerSelection
 from Screens.PictureInPicture import PictureInPicture
+from Screens.SubtitleDisplay import SubtitleDisplay
 from ServiceReference import ServiceReference
 
 from Tools import Notifications
@@ -448,7 +449,8 @@ class InfoBarEPG:
                if self.is_now_next and len(self.dlg_stack) == 1:
                        self.getNowNext()
                        assert self.eventView
-                       self.eventView.setEvent(self.epglist[0])
+                       if len(self.epglist):
+                               self.eventView.setEvent(self.epglist[0])
 
        def openEventView(self):
                ref = self.session.nav.getCurrentlyPlayingServiceReference()
@@ -1019,6 +1021,7 @@ class InfoBarExtensions:
        PIPON = 0
        PIPOFF = 1
        MOVEPIP = 2
+       PIPSWAP = 3
 
        def extensions(self):
                list = []
@@ -1027,29 +1030,30 @@ class InfoBarExtensions:
                elif self.pipshown == True:
                        list.append((_("Disable Picture in Picture"), self.PIPOFF))
                        list.append((_("Move Picture in Picture"), self.MOVEPIP))
+                       list.append((_("Swap services"), self.PIPSWAP))
                self.session.openWithCallback(self.extensionCallback, ChoiceBox, title=_("Please choose an extension..."), list = list)
 
        def extensionCallback(self, answer):
                if answer is not None:
                        if answer[1] == self.PIPON:
-#                              self.session.nav.stopService()
                                self.pip = self.session.instantiateDialog(PictureInPicture)
-                               #self.pip.show()
                                
                                newservice = self.session.nav.getCurrentlyPlayingServiceReference()
-                               self.pipservice = eServiceCenter.getInstance().play(newservice)
-                               if self.pipservice and not self.pipservice.setTarget(1):
-                                       self.pipservice.start()
+                               
+                               if self.pip.playService(newservice):
                                        self.pipshown = True
                                else:
-                                       self.pipservice = None
+                                       self.pipshown = False
                                        del self.pip
                                self.session.nav.playService(newservice)
                        elif answer[1] == self.PIPOFF:
-                               #self.pip.hide()
-                               self.pipservice = None
                                del self.pip
                                self.pipshown = False
+                       elif answer[1] == self.PIPSWAP:
+                               swapservice = self.pip.getCurrentService()
+                               self.pip.playService(self.session.nav.getCurrentlyPlayingServiceReference())
+                               self.session.nav.playService(swapservice)
+                               
                        elif answer[1] == self.MOVEPIP:
                                self.session.open(PiPSetup, pip = self.pip)
 
@@ -1191,9 +1195,11 @@ class InfoBarAudioSelection:
        def audioSelection(self):
                service = self.session.nav.getCurrentService()
                audio = service.audioTracks()
-               self.audio = audio
+               self.audioTracks = audio
                n = audio.getNumberOfTracks()
                if n > 0:
+#                      self.audioChannel = service.audioChannel()
+#                      config.audio.audiochannel = configElement_nonSave("config.audio.audiochannel", configSelection, self.audioChannel.getCurrentChannel(), (("left", _("Left  >")), ("stereo", _("<  Stereo  >")), ("right", _("<  Right"))))
                        tlist = []
                        for x in range(n):
                                i = audio.getTrackInfo(x)
@@ -1213,6 +1219,9 @@ class InfoBarAudioSelection:
                        
                        selectedAudio = tlist[0][1]
                        tlist.sort(lambda x,y : cmp(x[0], y[0]))
+
+#                      tlist.insert(0, getConfigListEntry(_("Audio Channel"), config.audio.audiochannel))
+
                        selection = 0
                        for x in tlist:
                                if x[1] != selectedAudio:
@@ -1221,11 +1230,15 @@ class InfoBarAudioSelection:
                                        break
                        
                        self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = tlist, selection = selection)
+               else:
+                       del self.audioTracks
 
        def audioSelected(self, audio):
                if audio is not None:
-                       self.audio.selectTrack(audio[1])
-               del self.audio
+                       self.audioTracks.selectTrack(audio[1])
+               del self.audioTracks
+#              del self.audioChannel
+#              del config.audio.audiochannel
 
 class InfoBarSubserviceSelection:
        def __init__(self):
@@ -1398,6 +1411,10 @@ class InfoBarNotifications:
        def __init__(self):
                self.onExecBegin.append(self.checkNotifications)
                Notifications.notificationAdded.append(self.checkNotificationsIfExecing)
+               self.onClose.append(self.__removeNotification)
+       
+       def __removeNotification(self):
+               Notifications.notificationAdded.remove(self.checkNotificationsIfExecing)
        
        def checkNotificationsIfExecing(self):
                if self.execing:
@@ -1407,7 +1424,6 @@ class InfoBarNotifications:
                if len(Notifications.notifications):
                        n = Notifications.notifications[0]
                        Notifications.notifications = Notifications.notifications[1:]
-                       print "open",n
                        cb = n[0]
                        if cb is not None:
                                self.session.openWithCallback(cb, n[1], *n[2], **n[3])
@@ -1585,3 +1601,40 @@ class InfoBarTeletextPlugin:
 
        def startTeletext(self):
                self.teletext_plugin(session=self.session, service=self.session.nav.getCurrentService())
+
+class InfoBarSubtitleSupport(object):
+       def __init__(self):
+               object.__init__(self)
+               self.subtitle_window = self.session.instantiateDialog(SubtitleDisplay)
+               self.__subtitles_enabled = False
+
+               self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
+                       {
+                               iPlayableService.evStart: self.__serviceStarted,
+                       })
+
+       def __serviceStarted(self):
+               # reenable if it was enabled
+               r = self.__subtitles_enabled
+               self.__subtitles_enabled = False
+               self.setSubtitlesEnable(r)
+
+       def getCurrentServiceSubtitle(self):
+               service = self.session.nav.getCurrentService()
+               return service and service.subtitle()
+       
+       def setSubtitlesEnable(self, enable=True):
+               subtitle = self.getCurrentServiceSubtitle()
+               if enable:
+                       if subtitle and not self.__subtitles_enabled:
+                               subtitle.enableSubtitles(self.subtitle_window.instance, 0)
+                               self.subtitle_window.show()
+                               self.__subtitles_enabled = True
+               else:
+                       if subtitle:
+                               subtitle.disableSubtitles(self.subtitle_window.instance)
+
+                       self.subtitle_window.hide()
+                       self.__subtitles_enabled = False
+               
+       subtitlesEnabled = property(lambda self: self.__subtitlesEnabled, setSubtitlesEnable)