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