add missing file
[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 == x:
29                                 text = _("Running")
30                         else:
31                                 text = _("Enable")
32                         if x[0] == 0:
33                                 self.list.append(getConfigListEntry(text+" DVB "+LanguageCodes[x[4]][0], ConfigNothing(), x))
34                         elif x[0] == 1:
35                                 if x[4] == 'und': #undefined
36                                         self.list.append(getConfigListEntry(text+" TTX "+_("Page")+" "+str(x[2])+"/"+str(x[3]), ConfigNothing(), x))
37                                 else:
38                                         self.list.append(getConfigListEntry(text+" TTX "+LanguageCodes[x[4]][0], ConfigNothing(), x))
39 #               return _("Disable subtitles")
40                 self["config"].list = self.list
41                 self["config"].l.setList(self.list)
42
43         def getSubtitleList(self):
44                 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
45                 l = s and s.getSubtitleList() or [ ]
46                 return l
47
48         def subtitlesEnabled(self):
49                 return self.infobar.subtitles_enabled
50
51         def enableSubtitle(self, subtitles):
52                 if self.infobar.selected_subtitle != subtitles:
53                         print "enable subtitles", subtitles
54                         self.infobar.subtitles_enabled = False
55                         self.infobar.selected_subtitle = subtitles
56                         self.infobar.subtitles_enabled = True
57
58         def disableSubtitles(self):
59                 self.infobar.subtitles_enabled = False
60
61         def keyLeft(self):
62                 ConfigListScreen.keyLeft(self)
63
64         def keyRight(self):
65                 ConfigListScreen.keyRight(self)
66
67         def ok(self):
68                 if len(self.list):
69                         cur = self["config"].getCurrent()
70                         self.enableSubtitle(cur[2])
71                 self.close(1)
72
73         def cancel(self):
74                 self.close()