small fixes
[enigma2.git] / lib / python / Screens / Subtitles.py
1 from Screen import Screen
2 from Components.ServiceEventTracker import ServiceEventTracker
3 from Components.ActionMap import ActionMap
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import config, getConfigListEntry, ConfigNothing
6 from enigma import iPlayableService
7
8 from Tools.ISO639 import LanguageCodes
9
10 class Subtitles(Screen, ConfigListScreen):
11         def __init__(self, session):
12                 Screen.__init__(self, session)
13         
14                 self["actions"] = ActionMap(["SetupActions"],
15                 {
16                         "ok": self.ok,
17                         "cancel": self.cancel,
18                 }, -2)
19
20                 self.list = []
21                 ConfigListScreen.__init__(self, self.list)
22                 self.infobar = self.session.infobar
23                 self.fillList()
24
25                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
26                         {
27                                 iPlayableService.evUpdatedInfo: self.__updatedInfo
28                         })
29                 self.cached_subtitle_checked = False
30                 self.__selected_subtitle = None
31
32         def fillList(self):
33                 del self.list[:]
34                 print "self.list", self.list
35                 if self.subtitlesEnabled():
36                         self.list.append(getConfigListEntry(_("Disable Subtitles"), ConfigNothing(), None))
37                         sel = self.infobar.selected_subtitle
38                 else:
39                         sel = None
40                 for x in self.getSubtitleList():
41                         if sel and sel[:4] == x[:4]: #ignore Language code in compare
42                                 text = _("Running")
43                         else:
44                                 text = _("Enable")
45                         if x[0] == 0:
46                                 if LanguageCodes.has_key(x[4]):
47                                         self.list.append(getConfigListEntry(text+" DVB "+LanguageCodes[x[4]][0], ConfigNothing(), x))
48                                 else:
49                                         self.list.append(getConfigListEntry(text+" DVB "+x[4], ConfigNothing(), x))
50                         elif x[0] == 1:
51                                 if x[4] == 'und': #undefined
52                                         self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2]), ConfigNothing(), x))
53                                 else:
54                                         if LanguageCodes.has_key(x[4]):
55                                                 self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+LanguageCodes[x[4]][0], ConfigNothing(), x))
56                                         else:
57                                                 self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+x[4], ConfigNothing(), x))
58 #               return _("Disable subtitles")
59                 self["config"].list = self.list
60                 self["config"].l.setList(self.list)
61
62         def __updatedInfo(self):
63                 self.fillList()
64
65         def getSubtitleList(self):
66                 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
67                 l = s and s.getSubtitleList() or [ ]
68                 return l
69
70         def subtitlesEnabled(self):
71                 return self.infobar.subtitles_enabled
72
73         def enableSubtitle(self, subtitles):
74                 if self.infobar.selected_subtitle != subtitles:
75                         self.infobar.subtitles_enabled = False
76                         self.infobar.selected_subtitle = subtitles
77                         self.infobar.subtitles_enabled = True
78
79         def disableSubtitles(self):
80                 self.infobar.subtitles_enabled = False
81
82         def keyLeft(self):
83                 ConfigListScreen.keyLeft(self)
84
85         def keyRight(self):
86                 ConfigListScreen.keyRight(self)
87
88         def ok(self):
89                 if len(self.list):
90                         cur = self["config"].getCurrent()
91                         self.enableSubtitle(cur[2])
92                 self.close(1)
93
94         def cancel(self):
95                 self.close()