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 print "config.av.downmix_ac3.value=", config.av.downmix_ac3.value
74 self.settings.downmix = ConfigOnOff(default=config.av.downmix_ac3.value)
75 self.settings.downmix.addNotifier(self.changeAC3Downmix, initial_call = False)
76 conflist.append(getConfigListEntry(_("AC3 downmix"), self.settings.downmix))
77 self["key_red"].setBoolean(True)
80 self.audioChannel = service.audioChannel()
81 print "self.audioChannel.getCurrentChannel()", self.audioChannel.getCurrentChannel()
82 choicelist = [("0",_("left")), ("1",_("stereo")), ("2", _("right"))]
83 self.settings.channelmode = ConfigSelection(choices = choicelist, default = str(self.audioChannel.getCurrentChannel()))
84 self.settings.channelmode.addNotifier(self.changeMode, initial_call = False)
85 conflist.append(getConfigListEntry(_("Channel"), self.settings.channelmode))
86 self["key_green"].setBoolean(True)
88 selectedAudio = self.audioTracks.getCurrentTrack()
89 print "selectedAudio:", selectedAudio
93 i = audio.getTrackInfo(x)
94 languages = i.getLanguage().split('/')
95 description = i.getDescription() or _("<unknown>")
99 if selectedAudio == x:
100 selected = _("Running")
104 for lang in languages:
107 if LanguageCodes.has_key(lang):
108 language += LanguageCodes[lang][0]
115 streams.append((x, "", number, description, language, selected))
119 self.settings.dummy = ConfigNothing()
120 conflist.append(getConfigListEntry("", self.settings.dummy))
121 self["key_green"].setBoolean(False)
123 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
124 self.setTitle(_("Subtitle selection"))
126 self.settings.dummy = ConfigNothing()
127 conflist.append(getConfigListEntry("", self.settings.dummy))
128 self["key_red"].setBoolean(False)
129 conflist.append(getConfigListEntry("", self.settings.dummy))
130 self["key_green"].setBoolean(False)
132 if self.subtitlesEnabled():
133 sel = self.infobar.selected_subtitle
139 subtitlelist = self.getSubtitleList()
141 if len(subtitlelist):
142 for x in subtitlelist:
145 language = _("<unknown>")
148 if sel and x[:4] == sel[:4]:
149 selected = _("Running")
153 if LanguageCodes.has_key(x[4]):
154 language = LanguageCodes[x[4]][0]
160 number = "%x" % (x[1])
164 number = "%x%02x" % (x[3],x[2])
167 types = ("UTF-8 text","SSA / AAS",".SRT file")
168 description = types[x[2]]
170 streams.append((x, "", number, description, language, selected))
176 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
178 from Components.PluginComponent import plugins
179 from Plugins.Plugin import PluginDescriptor
181 if hasattr(self.infobar, "runPlugin"):
183 def __init__(self, fnc, *args):
186 def __call__(self, *args, **kwargs):
189 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
191 print "Plugins", Plugins
193 self.settings.dummy = ConfigNothing()
195 self["key_blue"].setBoolean(True)
196 conflist.append(getConfigListEntry(Plugins[0][0], self.settings.dummy))
197 self.plugincallfunc = Plugins[0][1]
199 self["config"].list = conflist
200 self["config"].l.setList(conflist)
202 print "setting self[streams].list:", streams
203 self["streams"].list = streams
204 print "setting self[streams].setIndex:", selectedidx
205 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 print "[enableSubtitle]", subtitles
221 if self.infobar.selected_subtitle != subtitles:
222 self.infobar.subtitles_enabled = False
223 self.infobar.selected_subtitle = subtitles
225 self.infobar.subtitles_enabled = True
227 def changeAC3Downmix(self, downmix):
228 print "changeAC3Downmix config.av.downmix_ac3.value=", config.av.downmix_ac3.value, downmix.getValue()
229 if downmix.getValue() == True:
230 config.av.downmix_ac3.value = True
232 config.av.downmix_ac3.value = False
233 config.av.downmix_ac3.save()
235 def changeMode(self, mode):
236 print "changeMode", mode, mode.getValue()
238 self.audioChannel.selectChannel(int(mode.getValue()))
240 def changeAudio(self, audio):
241 print "changeAudio", audio, "self.session.nav.getCurrentService().audioTracks().getNumberOfTracks():", self.session.nav.getCurrentService().audioTracks().getNumberOfTracks()
243 if isinstance(track, int):
244 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
245 self.audioTracks.selectTrack(track)
248 if self.focus == FOCUS_CONFIG:
249 ConfigListScreen.keyLeft(self)
250 elif self.focus == FOCUS_STREAMS:
251 self["streams"].setIndex(0)
253 def keyRight(self, config = False):
254 if config or self.focus == FOCUS_CONFIG:
255 if self["config"].getCurrentIndex() < 3:
256 ConfigListScreen.keyRight(self)
257 elif hasattr(self, "plugincallfunc"):
258 self.plugincallfunc()
259 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
260 self["streams"].setIndex(self["streams"].count()-1)
263 if self["key_red"].getBoolean():
267 if self["key_green"].getBoolean():
271 if self["key_yellow"].getBoolean():
275 if self["key_blue"].getBoolean():
279 def colorkey(self, idx):
280 self["config"].setCurrentIndex(idx)
284 print "[keyUp]", self["streams"].getIndex()
285 if self.focus == FOCUS_CONFIG:
286 self["config"].instance.moveSelection(self["config"].instance.moveUp)
287 elif self.focus == FOCUS_STREAMS:
288 if self["streams"].getIndex() == 0:
289 self["config"].instance.setSelectionEnable(True)
290 self["streams"].style = "notselected"
291 self["config"].setCurrentIndex(len(self["config"].getList())-1)
292 self.focus = FOCUS_CONFIG
294 self["streams"].selectPrevious()
297 print "[keyDown]", self["config"].getCurrentIndex(), len(self["config"].getList())-1
298 if self.focus == FOCUS_CONFIG:
299 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
300 self["config"].instance.moveSelection(self["config"].instance.moveDown)
302 self["config"].instance.setSelectionEnable(False)
303 self["streams"].style = "default"
304 self.focus = FOCUS_STREAMS
305 elif self.focus == FOCUS_STREAMS:
306 self["streams"].selectNext()
309 print "[keyok]", self["streams"].list, self["streams"].getCurrent()
310 if self.focus == FOCUS_STREAMS and self["streams"].list:
311 cur = self["streams"].getCurrent()
312 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
313 self.changeAudio(cur[2])
315 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
316 if self.infobar.selected_subtitle == cur[0]:
317 self.enableSubtitle(None)
318 selectedidx = self["streams"].getIndex()
320 self["streams"].setIndex(selectedidx)
322 self.enableSubtitle(cur[0])
325 elif self.focus == FOCUS_CONFIG:
331 class SubtitleSelection(AudioSelection):
332 def __init__(self, session, infobar=None):
333 AudioSelection.__init__(self, session, infobar, page=PAGE_SUBTITLES)
334 self.skinName = ["AudioSelection"]