swap key and value
[enigma2.git] / lib / python / Screens / InfoBarGenerics.py
index eef0f56923825233576dc699250d3412f55396ac..6ece278425f30c32dd6f52844fd34f7414dc716a 100644 (file)
@@ -593,7 +593,7 @@ class InfoBarSeek:
        SEEK_STATE_PAUSE = (1, 0, 0, "||")
        SEEK_STATE_EOF = (1, 0, 0, "END")
 
-       def __init__(self, actionmap = "InfobarSeekActions"):
+       def __init__(self, actionmap = "InfobarSeekActions", useSeekBackHack=True):
                self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
                        {
                                iPlayableService.evSeekableStatusChanged: self.__seekableStatusChanged,
@@ -608,7 +608,7 @@ class InfoBarSeek:
                self.eofInhibitTimer = eTimer()
                self.eofInhibitTimer.timeout.get().append(self.inhibitEof)
 
-#              self.minSpeedBackward = 16
+               self.minSpeedBackward = useSeekBackHack and 16 or 0
 
                class InfoBarSeekActionMap(HelpableActionMap):
                        def __init__(self, screen, *args, **kwargs):
@@ -666,13 +666,12 @@ class InfoBarSeek:
        def makeStateBackward(self, n):
                minspeed = config.seek.stepwise_minspeed.value
                repeat = int(config.seek.stepwise_repeat.value)
-#              if n < self.minSpeedBackward:
-#                      r = (self.minSpeedBackward - 1)/ n + 1
-#                      if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
-#                              r = max(r, repeat)
-#                      return (0, -n * r, r, "<< %dx" % n)
-#              el
-               if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
+               if self.minSpeedBackward and n < self.minSpeedBackward:
+                       r = (self.minSpeedBackward - 1)/ n + 1
+                       if minspeed != "Never" and n >= int(minspeed) and repeat > 1:
+                               r = max(r, repeat)
+                       return (0, -n * r, r, "<< %dx" % n)
+               elif minspeed != "Never" and n >= int(minspeed) and repeat > 1:
                        return (0, -n * repeat, repeat, "<< %dx" % n)
                else:
                        return (0, -n, 0, "<< %dx" % n)
@@ -1280,10 +1279,7 @@ class InfoBarPlugins:
 # depends on InfoBarExtensions
 class InfoBarSleepTimer:
        def __init__(self):
-               self.addExtension((self.getSleepTimerName, self.showSleepTimerSetup, self.available), "1")
-
-       def available(self):
-               return True
+               self.addExtension((self.getSleepTimerName, self.showSleepTimerSetup, lambda: True), "1")
 
        def getSleepTimerName(self):
                return _("Sleep Timer")
@@ -1296,13 +1292,10 @@ class InfoBarPiP:
        def __init__(self):
                self.session.pipshown = False
                if SystemInfo.get("NumVideoDecoders", 1) > 1:
-                       self.addExtension((self.getShowHideName, self.showPiP, self.available), "blue")
+                       self.addExtension((self.getShowHideName, self.showPiP, lambda: True), "blue")
                        self.addExtension((self.getMoveName, self.movePiP, self.pipShown), "green")
                        self.addExtension((self.getSwapName, self.swapPiP, self.pipShown), "yellow")
 
-       def available(self):
-               return SystemInfo.get("NumVideoDecoders", 1) > 1
-
        def pipShown(self):
                return self.session.pipshown
 
@@ -1419,10 +1412,6 @@ class InfoBarInstantRecord:
                recording.dontSave = True
                self.recording.append(recording)
 
-#### DEPRECATED CODE ####
-               self["BlinkingPoint"].setConnect(lambda: self.recording.isRunning())
-#########################
-
        def isInstantRecordRunning(self):
                print "self.recording:", self.recording
                if len(self.recording) > 0:
@@ -1531,10 +1520,8 @@ class InfoBarAudioSelection:
 
        def audioSelection(self):
                service = self.session.nav.getCurrentService()
-               audio = service and service.audioTracks()
-               self.audioTracks = audio
+               self.audioTracks = audio = service and service.audioTracks()
                n = audio and audio.getNumberOfTracks() or 0
-               keys = [ "red", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
                tlist = []
                if n > 0:
                        self.audioChannel = service.audioChannel()
@@ -1554,21 +1541,45 @@ class InfoBarAudioSelection:
 
                                tlist.append((description, x))
 
-                       selectedAudio = audio.getCurrentTrack()
                        tlist.sort(key=lambda x: x[0])
 
-                       selection = 2
+                       selectedAudio = self.audioTracks.getCurrentTrack()
+
+                       selection = 0
+
                        for x in tlist:
                                if x[1] != selectedAudio:
                                        selection += 1
                                else:
                                        break
 
-                       tlist = [([_("Left"), _("Stereo"), _("Right")][self.audioChannel.getCurrentChannel()], "mode"), ("--", "")] + tlist
+                       if SystemInfo["CanDownmixAC3"]:
+                               tlist = [(_("AC3 downmix") + " - " +[_("Off"), _("On")][config.av.downmix_ac3.value and 1 or 0], "CALLFUNC", self.changeAC3Downmix),
+                                       ([_("Left"), _("Stereo"), _("Right")][self.audioChannel.getCurrentChannel()], "mode"),
+                                       ("--", "")] + tlist
+                               keys = [ "red", "green", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
+                               selection += 3
+                       else:
+                               tlist = [([_("Left"), _("Stereo"), _("Right")][self.audioChannel.getCurrentChannel()], "mode"), ("--", "")] + tlist
+                               keys = [ "red", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] + [""]*n
+                               selection += 2
                        self.session.openWithCallback(self.audioSelected, ChoiceBox, title=_("Select audio track"), list = tlist, selection = selection, keys = keys)
                else:
                        del self.audioTracks
 
+       def changeAC3Downmix(self, arg):
+               choicelist = self.session.current_dialog["list"]
+               list = choicelist.list
+               t = list[0][1]
+               list[0][1]=(t[0], t[1], t[2], t[3], t[4], t[5], t[6],
+                       _("AC3 downmix") + " - " +[_("On"), _("Off")][config.av.downmix_ac3.value and 1 or 0])
+               choicelist.setList(list)
+               if config.av.downmix_ac3.value:
+                       config.av.downmix_ac3.value = False
+               else:
+                       config.av.downmix_ac3.value = True
+               config.av.downmix_ac3.save()
+
        def audioSelected(self, audio):
                if audio is not None:
                        if isinstance(audio[1], str):
@@ -1641,7 +1652,7 @@ class InfoBarSubserviceSelection:
                                if newservice.valid():
                                        del subservices
                                        del service
-                                       self.session.nav.playService(newservice)
+                                       self.session.nav.playService(newservice, False)
 
        def subserviceSelection(self):
                service = self.session.nav.getCurrentService()
@@ -1659,7 +1670,7 @@ class InfoBarSubserviceSelection:
                                tlist.append((i.getName(), i))
 
                        if self.bouquets and len(self.bouquets):
-                               keys = ["red", "green", "",  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * n
+                               keys = ["red", "blue", "",  "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + [""] * n
                                if config.usage.multibouquet.value:
                                        tlist = [(_("Quickzap"), "quickzap", service.subServices()), (_("Add to bouquet"), "CALLFUNC", self.addSubserviceToBouquetCallback), ("--", "")] + tlist
                                else:
@@ -1681,7 +1692,7 @@ class InfoBarSubserviceSelection:
                                        self.session.open(SubservicesQuickzap, service[2])
                        else:
                                self["SubserviceQuickzapAction"].setEnabled(True)
-                               self.session.nav.playService(service[1])
+                               self.session.nav.playService(service[1], False)
 
        def addSubserviceToBouquetCallback(self, service):
                if len(service) > 1 and isinstance(service[1], eServiceReference):