PicturePlayer/plugin.py: - center screens where needed.
[enigma2.git] / lib / python / Screens / Subtitles.py
index e3cdd71a4f58c79e3de56674488b52fea07d8776..9ba7e0a56e0e1acedaed0cc384163add73f126b0 100644 (file)
@@ -1,12 +1,14 @@
 from Screen import Screen
+from Components.ServiceEventTracker import ServiceEventTracker
 from Components.ActionMap import ActionMap
 from Components.ConfigList import ConfigListScreen
 from Components.config import config, getConfigListEntry, ConfigNothing
+from enigma import iPlayableService
 
 from Tools.ISO639 import LanguageCodes
 
 class Subtitles(Screen, ConfigListScreen):
-       def __init__(self, session):
+       def __init__(self, session, infobar=None):
                Screen.__init__(self, session)
         
                self["actions"] = ActionMap(["SetupActions"],
@@ -17,9 +19,22 @@ class Subtitles(Screen, ConfigListScreen):
 
                self.list = []
                ConfigListScreen.__init__(self, self.list)
-               self.infobar = self.session.infobar
+               self.infobar = infobar or self.session.infobar
+               self.fillList()
+
+               self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
+                       {
+                               iPlayableService.evUpdatedInfo: self.__updatedInfo
+                       })
+               self.cached_subtitle_checked = False
+               self.__selected_subtitle = None
+
+       def fillList(self):
+               list = self.list
+               del list[:]
+               print "self.list", list
                if self.subtitlesEnabled():
-                       self.list.append(getConfigListEntry(_("Disable Subtitles"), ConfigNothing(), None))
+                       list.append(getConfigListEntry(_("Disable Subtitles"), ConfigNothing(), None))
                        sel = self.infobar.selected_subtitle
                else:
                        sel = None
@@ -30,20 +45,32 @@ class Subtitles(Screen, ConfigListScreen):
                                text = _("Enable")
                        if x[0] == 0:
                                if LanguageCodes.has_key(x[4]):
-                                       self.list.append(getConfigListEntry(text+" DVB "+LanguageCodes[x[4]][0], ConfigNothing(), x))
+                                       list.append(getConfigListEntry(text+" DVB "+LanguageCodes[x[4]][0], ConfigNothing(), x))
                                else:
-                                       self.list.append(getConfigListEntry(text+" DVB "+x[4], ConfigNothing(), x))
+                                       list.append(getConfigListEntry(text+" DVB "+x[4], ConfigNothing(), x))
                        elif x[0] == 1:
                                if x[4] == 'und': #undefined
-                                       self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2]), ConfigNothing(), x))
+                                       list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2]), ConfigNothing(), x))
+                               else:
+                                       if LanguageCodes.has_key(x[4]):
+                                               list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+LanguageCodes[x[4]][0], ConfigNothing(), x))
+                                       else:
+                                               list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+x[4], ConfigNothing(), x))
+                       elif x[0] == 2:
+                               types = (" UTF-8 text "," SSA / AAS "," .SRT file ")
+                               if x[4] == 'und': #undefined
+                                       list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles")+" %d" % x[1], ConfigNothing(), x))
                                else:
                                        if LanguageCodes.has_key(x[4]):
-                                               self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+LanguageCodes[x[4]][0], ConfigNothing(), x))
+                                               list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles") + ' ' + LanguageCodes[x[4]][0], ConfigNothing(), x))
                                        else:
-                                               self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+x[4], ConfigNothing(), x))
+                                               list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles")+" %d " % x[1] +x[4], ConfigNothing(), x))
 #              return _("Disable subtitles")
-               self["config"].list = self.list
-               self["config"].l.setList(self.list)
+               self["config"].list = list
+               self["config"].l.setList(list)
+
+       def __updatedInfo(self):
+               self.fillList()
 
        def getSubtitleList(self):
                s = self.infobar and self.infobar.getCurrentServiceSubtitle()
@@ -57,10 +84,8 @@ class Subtitles(Screen, ConfigListScreen):
                if self.infobar.selected_subtitle != subtitles:
                        self.infobar.subtitles_enabled = False
                        self.infobar.selected_subtitle = subtitles
-                       self.infobar.subtitles_enabled = True
-
-       def disableSubtitles(self):
-               self.infobar.subtitles_enabled = False
+                       if subtitles:
+                               self.infobar.subtitles_enabled = True
 
        def keyLeft(self):
                ConfigListScreen.keyLeft(self)
@@ -69,7 +94,7 @@ class Subtitles(Screen, ConfigListScreen):
                ConfigListScreen.keyRight(self)
 
        def ok(self):
-               if len(self.list):
+               if self.list:
                        cur = self["config"].getCurrent()
                        self.enableSubtitle(cur[2])
                self.close(1)