1 from Screen import Screen
2 from Components.ServiceEventTracker import ServiceEventTracker
3 from Components.ActionMap import NumberActionMap
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"] = NumberActionMap(["ColorActions", "SetupActions", "DirectionActions"],
42 "green": self.keyGreen,
43 "yellow": self.keyYellow,
46 "cancel": self.cancel,
49 "1": self.keyNumberGlobal,
50 "2": self.keyNumberGlobal,
51 "3": self.keyNumberGlobal,
52 "4": self.keyNumberGlobal,
53 "5": self.keyNumberGlobal,
54 "6": self.keyNumberGlobal,
55 "7": self.keyNumberGlobal,
56 "8": self.keyNumberGlobal,
57 "9": self.keyNumberGlobal,
60 self.settings = ConfigSubsection()
61 choicelist = [(PAGE_AUDIO,_("audio tracks")), (PAGE_SUBTITLES,_("Subtitles"))]
62 self.settings.menupage = ConfigSelection(choices = choicelist, default=page)
63 self.onLayoutFinish.append(self.__layoutFinished)
65 def __layoutFinished(self):
66 self["config"].instance.setSelectionEnable(False)
67 self.focus = FOCUS_STREAMS
68 self.settings.menupage.addNotifier(self.fillList)
70 def fillList(self, arg=None):
75 if self.settings.menupage.getValue() == PAGE_AUDIO:
76 self.setTitle(_("Select audio track"))
77 service = self.session.nav.getCurrentService()
78 self.audioTracks = audio = service and service.audioTracks()
79 n = audio and audio.getNumberOfTracks() or 0
80 if SystemInfo["CanDownmixAC3"]:
81 self.settings.downmix = ConfigOnOff(default=config.av.downmix_ac3.value)
82 self.settings.downmix.addNotifier(self.changeAC3Downmix, initial_call = False)
83 conflist.append(getConfigListEntry(_("Dolby Digital downmix"), self.settings.downmix))
84 self["key_red"].setBoolean(True)
87 self.audioChannel = service.audioChannel()
89 choicelist = [("0",_("left")), ("1",_("stereo")), ("2", _("right"))]
90 self.settings.channelmode = ConfigSelection(choices = choicelist, default = str(self.audioChannel.getCurrentChannel()))
91 self.settings.channelmode.addNotifier(self.changeMode, initial_call = False)
92 conflist.append(getConfigListEntry(_("Channel"), self.settings.channelmode))
93 self["key_green"].setBoolean(True)
95 conflist.append(('',))
96 self["key_green"].setBoolean(False)
97 selectedAudio = self.audioTracks.getCurrentTrack()
100 i = audio.getTrackInfo(x)
101 languages = i.getLanguage().split('/')
102 description = i.getDescription() or _("<unknown>")
106 if selectedAudio == x:
107 selected = _("Running")
111 for lang in languages:
114 if LanguageCodes.has_key(lang):
115 language += LanguageCodes[lang][0]
122 streams.append((x, "", number, description, language, selected))
126 conflist.append(('',))
127 self["key_green"].setBoolean(False)
129 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
130 self.setTitle(_("Subtitle selection"))
131 conflist.append(('',))
132 conflist.append(('',))
133 self["key_red"].setBoolean(False)
134 self["key_green"].setBoolean(False)
136 if self.subtitlesEnabled():
137 sel = self.infobar.selected_subtitle
143 subtitlelist = self.getSubtitleList()
145 if len(subtitlelist):
146 for x in subtitlelist:
149 language = _("<unknown>")
153 selected = _("Running")
157 if LanguageCodes.has_key(x[4]):
158 language = LanguageCodes[x[4]][0]
164 number = "%x" % (x[1])
168 number = "%x%02x" % (x[3],x[2])
171 types = (_("<unknown>"), "UTF-8 text", "SSA", "AAS", ".SRT file", "VOB", "PGS (unsupported)")
172 description = types[x[2]]
174 streams.append((x, "", number, description, language, selected))
180 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
182 from Components.PluginComponent import plugins
183 from Plugins.Plugin import PluginDescriptor
185 if hasattr(self.infobar, "runPlugin"):
187 def __init__(self, fnc, *args):
190 def __call__(self, *args, **kwargs):
193 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
196 self["key_blue"].setBoolean(True)
197 conflist.append(getConfigListEntry(Plugins[0][0], ConfigNothing()))
198 self.plugincallfunc = Plugins[0][1]
200 print "plugin(s) installed but not displayed in the dialog box:", Plugins[1:]
202 self["config"].list = conflist
203 self["config"].l.setList(conflist)
205 self["streams"].list = streams
206 self["streams"].setIndex(selectedidx)
208 def __updatedInfo(self):
211 def getSubtitleList(self):
212 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
213 l = s and s.getSubtitleList() or [ ]
216 def subtitlesEnabled(self):
217 return self.infobar.subtitles_enabled
219 def enableSubtitle(self, subtitles):
220 if self.infobar.selected_subtitle != subtitles:
221 self.infobar.subtitles_enabled = False
222 self.infobar.selected_subtitle = subtitles
224 self.infobar.subtitles_enabled = True
226 def changeAC3Downmix(self, downmix):
227 if downmix.getValue() == True:
228 config.av.downmix_ac3.value = True
230 config.av.downmix_ac3.value = False
231 config.av.downmix_ac3.save()
233 def changeMode(self, mode):
234 if mode is not None and self.audioChannel:
235 self.audioChannel.selectChannel(int(mode.getValue()))
237 def changeAudio(self, audio):
239 if isinstance(track, int):
240 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
241 self.audioTracks.selectTrack(track)
244 if self.focus == FOCUS_CONFIG:
245 ConfigListScreen.keyLeft(self)
246 elif self.focus == FOCUS_STREAMS:
247 self["streams"].setIndex(0)
249 def keyRight(self, config = False):
250 if config or self.focus == FOCUS_CONFIG:
251 if self["config"].getCurrentIndex() < 3:
252 ConfigListScreen.keyRight(self)
253 elif hasattr(self, "plugincallfunc"):
254 self.plugincallfunc()
255 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
256 self["streams"].setIndex(self["streams"].count()-1)
259 if self["key_red"].getBoolean():
263 if self["key_green"].getBoolean():
267 if self["key_yellow"].getBoolean():
271 if self["key_blue"].getBoolean():
274 def colorkey(self, idx):
275 self["config"].setCurrentIndex(idx)
279 if self.focus == FOCUS_CONFIG:
280 self["config"].instance.moveSelection(self["config"].instance.moveUp)
281 elif self.focus == FOCUS_STREAMS:
282 if self["streams"].getIndex() == 0:
283 self["config"].instance.setSelectionEnable(True)
284 self["streams"].style = "notselected"
285 self["config"].setCurrentIndex(len(self["config"].getList())-1)
286 self.focus = FOCUS_CONFIG
288 self["streams"].selectPrevious()
291 if self.focus == FOCUS_CONFIG:
292 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
293 self["config"].instance.moveSelection(self["config"].instance.moveDown)
295 self["config"].instance.setSelectionEnable(False)
296 self["streams"].style = "default"
297 self.focus = FOCUS_STREAMS
298 elif self.focus == FOCUS_STREAMS:
299 self["streams"].selectNext()
301 def keyNumberGlobal(self, number):
302 if number <= len(self["streams"].list):
303 self["streams"].setIndex(number-1)
307 if self.focus == FOCUS_STREAMS and self["streams"].list:
308 cur = self["streams"].getCurrent()
309 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
310 self.changeAudio(cur[0])
312 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
313 if self.infobar.selected_subtitle == cur[0]:
314 self.enableSubtitle(None)
315 selectedidx = self["streams"].getIndex()
317 self["streams"].setIndex(selectedidx)
319 self.enableSubtitle(cur[0])
322 elif self.focus == FOCUS_CONFIG:
328 class SubtitleSelection(AudioSelection):
329 def __init__(self, session, infobar=None):
330 AudioSelection.__init__(self, session, infobar, page=PAGE_SUBTITLES)
331 self.skinName = ["AudioSelection"]