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 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()
81 choicelist = [("0",_("left")), ("1",_("stereo")), ("2", _("right"))]
82 self.settings.channelmode = ConfigSelection(choices = choicelist, default = str(self.audioChannel.getCurrentChannel()))
83 self.settings.channelmode.addNotifier(self.changeMode, initial_call = False)
84 conflist.append(getConfigListEntry(_("Channel"), self.settings.channelmode))
85 self["key_green"].setBoolean(True)
87 conflist.append(('',))
88 self["key_green"].setBoolean(False)
89 selectedAudio = self.audioTracks.getCurrentTrack()
92 i = audio.getTrackInfo(x)
93 languages = i.getLanguage().split('/')
94 description = i.getDescription() or _("<unknown>")
98 if selectedAudio == x:
99 selected = _("Running")
103 for lang in languages:
106 if LanguageCodes.has_key(lang):
107 language += LanguageCodes[lang][0]
114 streams.append((x, "", number, description, language, selected))
118 conflist.append(('',))
119 self["key_green"].setBoolean(False)
121 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
122 self.setTitle(_("Subtitle selection"))
123 conflist.append(('',))
124 conflist.append(('',))
125 self["key_red"].setBoolean(False)
126 self["key_green"].setBoolean(False)
128 if self.subtitlesEnabled():
129 sel = self.infobar.selected_subtitle
135 subtitlelist = self.getSubtitleList()
137 if len(subtitlelist):
138 for x in subtitlelist:
141 language = _("<unknown>")
145 selected = _("Running")
149 if LanguageCodes.has_key(x[4]):
150 language = LanguageCodes[x[4]][0]
156 number = "%x" % (x[1])
160 number = "%x%02x" % (x[3],x[2])
163 types = ("UTF-8 text","SSA / AAS",".SRT file","VOB")
164 description = types[x[2]]
166 streams.append((x, "", number, description, language, selected))
172 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
174 from Components.PluginComponent import plugins
175 from Plugins.Plugin import PluginDescriptor
177 if hasattr(self.infobar, "runPlugin"):
179 def __init__(self, fnc, *args):
182 def __call__(self, *args, **kwargs):
185 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
188 self["key_blue"].setBoolean(True)
189 conflist.append(getConfigListEntry(Plugins[0][0], ConfigNothing()))
190 self.plugincallfunc = Plugins[0][1]
192 print "these plugins are installed but not displayed in the dialog box:", Plugins[1:]
194 self["config"].list = conflist
195 self["config"].l.setList(conflist)
197 self["streams"].list = streams
198 self["streams"].setIndex(selectedidx)
200 def __updatedInfo(self):
203 def getSubtitleList(self):
204 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
205 l = s and s.getSubtitleList() or [ ]
208 def subtitlesEnabled(self):
209 return self.infobar.subtitles_enabled
211 def enableSubtitle(self, subtitles):
212 if self.infobar.selected_subtitle != subtitles:
213 self.infobar.subtitles_enabled = False
214 self.infobar.selected_subtitle = subtitles
216 self.infobar.subtitles_enabled = True
218 def changeAC3Downmix(self, downmix):
219 if downmix.getValue() == True:
220 config.av.downmix_ac3.value = True
222 config.av.downmix_ac3.value = False
223 config.av.downmix_ac3.save()
225 def changeMode(self, mode):
226 if mode is not None and self.audioChannel:
227 self.audioChannel.selectChannel(int(mode.getValue()))
229 def changeAudio(self, audio):
231 if isinstance(track, int):
232 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
233 self.audioTracks.selectTrack(track)
236 if self.focus == FOCUS_CONFIG:
237 ConfigListScreen.keyLeft(self)
238 elif self.focus == FOCUS_STREAMS:
239 self["streams"].setIndex(0)
241 def keyRight(self, config = False):
242 if config or self.focus == FOCUS_CONFIG:
243 if self["config"].getCurrentIndex() < 3:
244 ConfigListScreen.keyRight(self)
245 elif hasattr(self, "plugincallfunc"):
246 self.plugincallfunc()
247 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
248 self["streams"].setIndex(self["streams"].count()-1)
251 if self["key_red"].getBoolean():
255 if self["key_green"].getBoolean():
259 if self["key_yellow"].getBoolean():
263 if self["key_blue"].getBoolean():
266 def colorkey(self, idx):
267 self["config"].setCurrentIndex(idx)
271 if self.focus == FOCUS_CONFIG:
272 self["config"].instance.moveSelection(self["config"].instance.moveUp)
273 elif self.focus == FOCUS_STREAMS:
274 if self["streams"].getIndex() == 0:
275 self["config"].instance.setSelectionEnable(True)
276 self["streams"].style = "notselected"
277 self["config"].setCurrentIndex(len(self["config"].getList())-1)
278 self.focus = FOCUS_CONFIG
280 self["streams"].selectPrevious()
283 if self.focus == FOCUS_CONFIG:
284 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
285 self["config"].instance.moveSelection(self["config"].instance.moveDown)
287 self["config"].instance.setSelectionEnable(False)
288 self["streams"].style = "default"
289 self.focus = FOCUS_STREAMS
290 elif self.focus == FOCUS_STREAMS:
291 self["streams"].selectNext()
294 if self.focus == FOCUS_STREAMS and self["streams"].list:
295 cur = self["streams"].getCurrent()
296 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
297 self.changeAudio(cur[2])
299 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
300 if self.infobar.selected_subtitle == cur[0]:
301 self.enableSubtitle(None)
302 selectedidx = self["streams"].getIndex()
304 self["streams"].setIndex(selectedidx)
306 self.enableSubtitle(cur[0])
309 elif self.focus == FOCUS_CONFIG:
315 class SubtitleSelection(AudioSelection):
316 def __init__(self, session, infobar=None):
317 AudioSelection.__init__(self, session, infobar, page=PAGE_SUBTITLES)
318 self.skinName = ["AudioSelection"]