[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / 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 from Screens.InfoBar import InfoBar
11
12 class Subtitles(Screen, ConfigListScreen):
13         def __init__(self, session, infobar=None):
14                 Screen.__init__(self, session)
15         
16                 self["actions"] = ActionMap(["SetupActions"],
17                 {
18                         "ok": self.ok,
19                         "cancel": self.cancel,
20                 }, -2)
21
22                 self.list = []
23                 ConfigListScreen.__init__(self, self.list)
24                 if self.session.infobar is None:        
25                         if InfoBar.instance:
26                                 self.infobar = InfoBar.instance
27                 else:
28                         self.infobar = self.session.infobar
29
30                 self.fillList()
31
32                 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
33                         {
34                                 iPlayableService.evUpdatedInfo: self.__updatedInfo
35                         })
36                 self.cached_subtitle_checked = False
37                 self.__selected_subtitle = None
38
39         def fillList(self):
40                 list = self.list
41                 del list[:]
42                 print "self.list", list
43                 if self.subtitlesEnabled():
44                         list.append(getConfigListEntry(_("Disable Subtitles"), ConfigNothing(), None))
45                         sel = self.infobar.selected_subtitle
46                 else:
47                         sel = None
48                 for x in self.getSubtitleList():
49                         if sel and sel[:4] == x[:4]: #ignore Language code in compare
50                                 text = _("Running")
51                         else:
52                                 text = _("Enable")
53                         if x[0] == 0:
54                                 if LanguageCodes.has_key(x[4]):
55                                         list.append(getConfigListEntry(text+" DVB "+LanguageCodes[x[4]][0], ConfigNothing(), x))
56                                 else:
57                                         list.append(getConfigListEntry(text+" DVB "+x[4], ConfigNothing(), x))
58                         elif x[0] == 1:
59                                 if x[4] == 'und': #undefined
60                                         list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2]), ConfigNothing(), x))
61                                 else:
62                                         if LanguageCodes.has_key(x[4]):
63                                                 list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+LanguageCodes[x[4]][0], ConfigNothing(), x))
64                                         else:
65                                                 list.append(getConfigListEntry(text+" TTX "+_("Page")+" %x%02x"%(x[3],x[2])+" "+x[4], ConfigNothing(), x))
66                         elif x[0] == 2:
67                                 types = (" UTF-8 text "," SSA / AAS "," .SRT file ")
68                                 if x[4] == 'und': #undefined
69                                         list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles")+" %d" % x[1], ConfigNothing(), x))
70                                 else:
71                                         if LanguageCodes.has_key(x[4]):
72                                                 list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles") + ' ' + LanguageCodes[x[4]][0], ConfigNothing(), x))
73                                         else:
74                                                 list.append(getConfigListEntry(text+types[x[2]]+_("Subtitles")+" %d " % x[1] +x[4], ConfigNothing(), x))
75 #               return _("Disable subtitles")
76                 self["config"].list = list
77                 self["config"].l.setList(list)
78
79         def __updatedInfo(self):
80                 self.fillList()
81
82         def getSubtitleList(self):
83                 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
84                 l = s and s.getSubtitleList() or [ ]
85                 return l
86
87         def subtitlesEnabled(self):
88                 return self.infobar.subtitles_enabled
89
90         def enableSubtitle(self, subtitles):
91                 if self.infobar.selected_subtitle != subtitles:
92                         self.infobar.subtitles_enabled = False
93                         self.infobar.selected_subtitle = subtitles
94                         if subtitles:
95                                 self.infobar.subtitles_enabled = True
96
97         def keyLeft(self):
98                 ConfigListScreen.keyLeft(self)
99
100         def keyRight(self):
101                 ConfigListScreen.keyRight(self)
102
103         def ok(self):
104                 if self.list:
105                         cur = self["config"].getCurrent()
106                         self.enableSubtitle(cur[2])
107                 self.close(1)
108
109         def cancel(self):
110                 self.close()