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.ChoiceList import ChoiceList, ChoiceEntryComponent
6 from Components.config import config, ConfigSubsection, getConfigListEntry, ConfigNothing, ConfigSelection, ConfigOnOff
7 from Components.MultiContent import MultiContentEntryText
8 from Components.Sources.List import List
9 from Components.Sources.Boolean import Boolean
10 from Components.SystemInfo import SystemInfo
12 from enigma import iPlayableService
14 from Tools.ISO639 import LanguageCodes
15 from Tools.BoundFunction import boundFunction
16 FOCUS_CONFIG, FOCUS_STREAMS = range(2)
17 [PAGE_AUDIO, PAGE_SUBTITLES] = ["audio", "subtitles"]
19 class AudioSelection(Screen, ConfigListScreen):
20 def __init__(self, session, infobar=None, page=PAGE_AUDIO):
21 Screen.__init__(self, session)
23 self["streams"] = List([])
24 self["key_red"] = Boolean(False)
25 self["key_green"] = Boolean(False)
26 self["key_yellow"] = Boolean(True)
27 self["key_blue"] = Boolean(False)
29 ConfigListScreen.__init__(self, [])
30 self.infobar = infobar or self.session.infobar
32 self.__event_tracker = ServiceEventTracker(screen=self, eventmap=
34 iPlayableService.evUpdatedInfo: self.__updatedInfo
36 self.cached_subtitle_checked = False
37 self.__selected_subtitle = None
39 self["actions"] = ActionMap(["ColorActions", "SetupActions", "DirectionActions"],
42 "green": self.keyGreen,
43 "yellow": self.keyYellow,
46 "cancel": self.cancel,
51 self.settings = ConfigSubsection()
52 choicelist = [(PAGE_AUDIO,_("audio tracks")), (PAGE_SUBTITLES,_("Subtitles"))]
53 self.settings.menupage = ConfigSelection(choices = choicelist, default=page)
54 self.settings.menupage.addNotifier(self.fillList)
55 self.onLayoutFinish.append(self.__layoutFinished)
57 def __layoutFinished(self):
58 self["config"].instance.setSelectionEnable(False)
59 self.focus = FOCUS_STREAMS
61 def fillList(self, arg=None):
66 service = self.session.nav.getCurrentService()
67 self.audioTracks = audio = service and service.audioTracks()
68 n = audio and audio.getNumberOfTracks() or 0
70 if self.settings.menupage.getValue() == PAGE_AUDIO:
71 self.setTitle(_("Select audio track"))
72 if SystemInfo["CanDownmixAC3"]:
73 self.settings.downmix = ConfigOnOff(default=config.av.downmix_ac3.value)
74 self.settings.downmix.addNotifier(self.changeAC3Downmix, initial_call = False)
75 conflist.append(getConfigListEntry(_("AC3 downmix"), self.settings.downmix))
76 self["key_red"].setBoolean(True)
79 self.audioChannel = service.audioChannel()
80 choicelist = [("0",_("left")), ("1",_("stereo")), ("2", _("right"))]
81 self.settings.channelmode = ConfigSelection(choices = choicelist, default = str(self.audioChannel.getCurrentChannel()))
82 self.settings.channelmode.addNotifier(self.changeMode, initial_call = False)
83 conflist.append(getConfigListEntry(_("Channel"), self.settings.channelmode))
84 self["key_green"].setBoolean(True)
85 selectedAudio = self.audioTracks.getCurrentTrack()
88 i = audio.getTrackInfo(x)
89 languages = i.getLanguage().split('/')
90 description = i.getDescription() or _("<unknown>")
94 if selectedAudio == x:
95 selected = _("Running")
99 for lang in languages:
102 if LanguageCodes.has_key(lang):
103 language += LanguageCodes[lang][0]
110 streams.append((x, "", number, description, language, selected))
113 conflist.append(getConfigListEntry("", self.settings.dummy))
114 self["key_green"].setBoolean(False)
116 conflist.append(('',))
117 self["key_green"].setBoolean(False)
119 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
120 self.setTitle(_("Subtitle selection"))
121 conflist.append(('',))
122 conflist.append(('',))
123 self["key_red"].setBoolean(False)
124 self["key_green"].setBoolean(False)
126 if self.subtitlesEnabled():
127 sel = self.infobar.selected_subtitle
133 subtitlelist = self.getSubtitleList()
135 if len(subtitlelist):
136 for x in subtitlelist:
139 language = _("<unknown>")
142 if sel and x[:4] == sel[:4]:
143 selected = _("Running")
147 if LanguageCodes.has_key(x[4]):
148 language = LanguageCodes[x[4]][0]
154 number = "%x" % (x[1])
158 number = "%x%02x" % (x[3],x[2])
161 types = (_("<unknown>"), "UTF-8 text", "SSA", "AAS", ".SRT file", "VOB")
162 description = types[x[2]]
164 streams.append((x, "", number, description, language, selected))
170 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
172 from Components.PluginComponent import plugins
173 from Plugins.Plugin import PluginDescriptor
175 if hasattr(self.infobar, "runPlugin"):
177 def __init__(self, fnc, *args):
180 def __call__(self, *args, **kwargs):
183 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
186 self["key_blue"].setBoolean(True)
187 conflist.append(getConfigListEntry(Plugins[0][0], ConfigNothing()))
188 self.plugincallfunc = Plugins[0][1]
190 print "these plugins are installed but not displayed in the dialog box:", Plugins[1:]
192 self["config"].list = conflist
193 self["config"].l.setList(conflist)
195 self["streams"].list = streams
196 self["streams"].setIndex(selectedidx)
198 def __updatedInfo(self):
201 def getSubtitleList(self):
202 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
203 l = s and s.getSubtitleList() or [ ]
206 def subtitlesEnabled(self):
207 return self.infobar.subtitles_enabled
209 def enableSubtitle(self, subtitles):
210 if self.infobar.selected_subtitle != subtitles:
211 self.infobar.subtitles_enabled = False
212 self.infobar.selected_subtitle = subtitles
214 self.infobar.subtitles_enabled = True
216 def changeAC3Downmix(self, downmix):
217 if downmix.getValue() == True:
218 config.av.downmix_ac3.value = True
220 config.av.downmix_ac3.value = False
221 config.av.downmix_ac3.save()
223 def changeMode(self, mode):
225 self.audioChannel.selectChannel(int(mode.getValue()))
227 def changeAudio(self, audio):
229 if isinstance(track, int):
230 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
231 self.audioTracks.selectTrack(track)
234 if self.focus == FOCUS_CONFIG:
235 ConfigListScreen.keyLeft(self)
236 elif self.focus == FOCUS_STREAMS:
237 self["streams"].setIndex(0)
239 def keyRight(self, config = False):
240 if config or self.focus == FOCUS_CONFIG:
241 if self["config"].getCurrentIndex() < 3:
242 ConfigListScreen.keyRight(self)
243 elif hasattr(self, "plugincallfunc"):
244 self.plugincallfunc()
245 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
246 self["streams"].setIndex(self["streams"].count()-1)
249 if self["key_red"].getBoolean():
253 if self["key_green"].getBoolean():
257 if self["key_yellow"].getBoolean():
261 if self["key_blue"].getBoolean():
264 def colorkey(self, idx):
265 self["config"].setCurrentIndex(idx)
269 if self.focus == FOCUS_CONFIG:
270 self["config"].instance.moveSelection(self["config"].instance.moveUp)
271 elif self.focus == FOCUS_STREAMS:
272 if self["streams"].getIndex() == 0:
273 self["config"].instance.setSelectionEnable(True)
274 self["streams"].style = "notselected"
275 self["config"].setCurrentIndex(len(self["config"].getList())-1)
276 self.focus = FOCUS_CONFIG
278 self["streams"].selectPrevious()
281 if self.focus == FOCUS_CONFIG:
282 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
283 self["config"].instance.moveSelection(self["config"].instance.moveDown)
285 self["config"].instance.setSelectionEnable(False)
286 self["streams"].style = "default"
287 self.focus = FOCUS_STREAMS
288 elif self.focus == FOCUS_STREAMS:
289 self["streams"].selectNext()
292 if self.focus == FOCUS_STREAMS and self["streams"].list:
293 cur = self["streams"].getCurrent()
294 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
295 self.changeAudio(cur[2])
297 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
298 if self.infobar.selected_subtitle == cur[0]:
299 self.enableSubtitle(None)
300 selectedidx = self["streams"].getIndex()
302 self["streams"].setIndex(selectedidx)
304 self.enableSubtitle(cur[0])
307 elif self.focus == FOCUS_CONFIG:
313 class SubtitleSelection(AudioSelection):
314 def __init__(self, session, infobar=None):
315 AudioSelection.__init__(self, session, infobar, PAGE_SUBTITLES)