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.onLayoutFinish.append(self.__layoutFinished)
56 def __layoutFinished(self):
57 self["config"].instance.setSelectionEnable(False)
58 self.focus = FOCUS_STREAMS
59 self.settings.menupage.addNotifier(self.fillList)
61 def fillList(self, arg=None):
66 if self.settings.menupage.getValue() == PAGE_AUDIO:
67 self.setTitle(_("Select audio track"))
68 service = self.session.nav.getCurrentService()
69 self.audioTracks = audio = service and service.audioTracks()
70 n = audio and audio.getNumberOfTracks() or 0
71 if SystemInfo["CanDownmixAC3"]:
72 self.settings.downmix = ConfigOnOff(default=config.av.downmix_ac3.value)
73 self.settings.downmix.addNotifier(self.changeAC3Downmix, initial_call = False)
74 conflist.append(getConfigListEntry(_("AC3 downmix"), self.settings.downmix))
75 self["key_red"].setBoolean(True)
78 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)
86 conflist.append(('',))
87 self["key_green"].setBoolean(False)
88 selectedAudio = self.audioTracks.getCurrentTrack()
91 i = audio.getTrackInfo(x)
92 languages = i.getLanguage().split('/')
93 description = i.getDescription() or _("<unknown>")
97 if selectedAudio == x:
98 selected = _("Running")
102 for lang in languages:
105 if LanguageCodes.has_key(lang):
106 language += LanguageCodes[lang][0]
113 streams.append((x, "", number, description, language, selected))
117 conflist.append(('',))
118 self["key_green"].setBoolean(False)
120 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
121 self.setTitle(_("Subtitle selection"))
122 conflist.append(('',))
123 conflist.append(('',))
124 self["key_red"].setBoolean(False)
125 self["key_green"].setBoolean(False)
127 if self.subtitlesEnabled():
128 sel = self.infobar.selected_subtitle
134 subtitlelist = self.getSubtitleList()
136 if len(subtitlelist):
137 for x in subtitlelist:
140 language = _("<unknown>")
144 selected = _("Running")
148 if LanguageCodes.has_key(x[4]):
149 language = LanguageCodes[x[4]][0]
155 number = "%x" % (x[1])
159 number = "%x%02x" % (x[3],x[2])
162 types = (_("<unknown>"), "UTF-8 text", "SSA", "AAS", ".SRT file", "VOB", "PGS (unsupported)")
163 description = types[x[2]]
165 streams.append((x, "", number, description, language, selected))
171 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
173 from Components.PluginComponent import plugins
174 from Plugins.Plugin import PluginDescriptor
176 if hasattr(self.infobar, "runPlugin"):
178 def __init__(self, fnc, *args):
181 def __call__(self, *args, **kwargs):
184 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
187 self["key_blue"].setBoolean(True)
188 conflist.append(getConfigListEntry(Plugins[0][0], ConfigNothing()))
189 self.plugincallfunc = Plugins[0][1]
191 print "plugin(s) installed but not displayed in the dialog box:", Plugins[1:]
193 self["config"].list = conflist
194 self["config"].l.setList(conflist)
196 self["streams"].list = streams
197 self["streams"].setIndex(selectedidx)
199 def __updatedInfo(self):
202 def getSubtitleList(self):
203 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
204 l = s and s.getSubtitleList() or [ ]
207 def subtitlesEnabled(self):
208 return self.infobar.subtitles_enabled
210 def enableSubtitle(self, subtitles):
211 if self.infobar.selected_subtitle != subtitles:
212 self.infobar.subtitles_enabled = False
213 self.infobar.selected_subtitle = subtitles
215 self.infobar.subtitles_enabled = True
217 def changeAC3Downmix(self, downmix):
218 if downmix.getValue() == True:
219 config.av.downmix_ac3.value = True
221 config.av.downmix_ac3.value = False
222 config.av.downmix_ac3.save()
224 def changeMode(self, mode):
225 if mode is not None and self.audioChannel:
226 self.audioChannel.selectChannel(int(mode.getValue()))
228 def changeAudio(self, audio):
230 if isinstance(track, int):
231 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
232 self.audioTracks.selectTrack(track)
235 if self.focus == FOCUS_CONFIG:
236 ConfigListScreen.keyLeft(self)
237 elif self.focus == FOCUS_STREAMS:
238 self["streams"].setIndex(0)
240 def keyRight(self, config = False):
241 if config or self.focus == FOCUS_CONFIG:
242 if self["config"].getCurrentIndex() < 3:
243 ConfigListScreen.keyRight(self)
244 elif hasattr(self, "plugincallfunc"):
245 self.plugincallfunc()
246 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
247 self["streams"].setIndex(self["streams"].count()-1)
250 if self["key_red"].getBoolean():
254 if self["key_green"].getBoolean():
258 if self["key_yellow"].getBoolean():
262 if self["key_blue"].getBoolean():
265 def colorkey(self, idx):
266 self["config"].setCurrentIndex(idx)
270 if self.focus == FOCUS_CONFIG:
271 self["config"].instance.moveSelection(self["config"].instance.moveUp)
272 elif self.focus == FOCUS_STREAMS:
273 if self["streams"].getIndex() == 0:
274 self["config"].instance.setSelectionEnable(True)
275 self["streams"].style = "notselected"
276 self["config"].setCurrentIndex(len(self["config"].getList())-1)
277 self.focus = FOCUS_CONFIG
279 self["streams"].selectPrevious()
282 if self.focus == FOCUS_CONFIG:
283 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
284 self["config"].instance.moveSelection(self["config"].instance.moveDown)
286 self["config"].instance.setSelectionEnable(False)
287 self["streams"].style = "default"
288 self.focus = FOCUS_STREAMS
289 elif self.focus == FOCUS_STREAMS:
290 self["streams"].selectNext()
293 if self.focus == FOCUS_STREAMS and self["streams"].list:
294 cur = self["streams"].getCurrent()
295 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
296 self.changeAudio(cur[2])
298 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
299 if self.infobar.selected_subtitle == cur[0]:
300 self.enableSubtitle(None)
301 selectedidx = self["streams"].getIndex()
303 self["streams"].setIndex(selectedidx)
305 self.enableSubtitle(cur[0])
308 elif self.focus == FOCUS_CONFIG:
314 class SubtitleSelection(AudioSelection):
315 def __init__(self, session, infobar=None):
316 AudioSelection.__init__(self, session, infobar, page=PAGE_SUBTITLES)
317 self.skinName = ["AudioSelection"]