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(_("Dolby Digital downmix"), self.settings.downmix))
75 self["key_red"].setBoolean(True)
78 self.audioChannel = service.audioChannel()
79 choicelist = [("0",_("left")), ("1",_("stereo")), ("2", _("right"))]
80 self.settings.channelmode = ConfigSelection(choices = choicelist, default = str(self.audioChannel.getCurrentChannel()))
81 self.settings.channelmode.addNotifier(self.changeMode, initial_call = False)
82 conflist.append(getConfigListEntry(_("Channel"), self.settings.channelmode))
83 self["key_green"].setBoolean(True)
84 selectedAudio = self.audioTracks.getCurrentTrack()
87 i = audio.getTrackInfo(x)
88 languages = i.getLanguage().split('/')
89 description = i.getDescription() or _("<unknown>")
93 if selectedAudio == x:
94 selected = _("Running")
98 for lang in languages:
101 if LanguageCodes.has_key(lang):
102 language += LanguageCodes[lang][0]
109 streams.append((x, "", number, description, language, selected))
113 conflist.append(('',))
114 self["key_green"].setBoolean(False)
116 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
117 self.setTitle(_("Subtitle selection"))
118 conflist.append(('',))
119 conflist.append(('',))
120 self["key_red"].setBoolean(False)
121 self["key_green"].setBoolean(False)
123 if self.subtitlesEnabled():
124 sel = self.infobar.selected_subtitle
130 subtitlelist = self.getSubtitleList()
132 if len(subtitlelist):
133 for x in subtitlelist:
136 language = _("<unknown>")
139 if sel and x[:4] == sel[:4]:
140 selected = _("Running")
144 if LanguageCodes.has_key(x[4]):
145 language = LanguageCodes[x[4]][0]
151 number = "%x" % (x[1])
155 number = "%x%02x" % (x[3],x[2])
158 types = (_("<unknown>"), "UTF-8 text", "SSA", "AAS", ".SRT file", "VOB", "PGS (unsupported)")
159 description = types[x[2]]
161 streams.append((x, "", number, description, language, selected))
167 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
169 from Components.PluginComponent import plugins
170 from Plugins.Plugin import PluginDescriptor
172 if hasattr(self.infobar, "runPlugin"):
174 def __init__(self, fnc, *args):
177 def __call__(self, *args, **kwargs):
180 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
183 self["key_blue"].setBoolean(True)
184 conflist.append(getConfigListEntry(Plugins[0][0], ConfigNothing()))
185 self.plugincallfunc = Plugins[0][1]
187 print "plugin(s) installed but not displayed in the dialog box:", Plugins[1:]
189 self["config"].list = conflist
190 self["config"].l.setList(conflist)
192 self["streams"].list = streams
193 self["streams"].setIndex(selectedidx)
195 def __updatedInfo(self):
198 def getSubtitleList(self):
199 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
200 l = s and s.getSubtitleList() or [ ]
203 def subtitlesEnabled(self):
204 return self.infobar.subtitles_enabled
206 def enableSubtitle(self, subtitles):
207 if self.infobar.selected_subtitle != subtitles:
208 self.infobar.subtitles_enabled = False
209 self.infobar.selected_subtitle = subtitles
211 self.infobar.subtitles_enabled = True
213 def changeAC3Downmix(self, downmix):
214 if downmix.getValue() == True:
215 config.av.downmix_ac3.value = True
217 config.av.downmix_ac3.value = False
218 config.av.downmix_ac3.save()
220 def changeMode(self, mode):
222 self.audioChannel.selectChannel(int(mode.getValue()))
224 def changeAudio(self, audio):
226 if isinstance(track, int):
227 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
228 self.audioTracks.selectTrack(track)
231 if self.focus == FOCUS_CONFIG:
232 ConfigListScreen.keyLeft(self)
233 elif self.focus == FOCUS_STREAMS:
234 self["streams"].setIndex(0)
236 def keyRight(self, config = False):
237 if config or self.focus == FOCUS_CONFIG:
238 if self["config"].getCurrentIndex() < 3:
239 ConfigListScreen.keyRight(self)
240 elif hasattr(self, "plugincallfunc"):
241 self.plugincallfunc()
242 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
243 self["streams"].setIndex(self["streams"].count()-1)
246 if self["key_red"].getBoolean():
250 if self["key_green"].getBoolean():
254 if self["key_yellow"].getBoolean():
258 if self["key_blue"].getBoolean():
261 def colorkey(self, idx):
262 self["config"].setCurrentIndex(idx)
266 if self.focus == FOCUS_CONFIG:
267 self["config"].instance.moveSelection(self["config"].instance.moveUp)
268 elif self.focus == FOCUS_STREAMS:
269 if self["streams"].getIndex() == 0:
270 self["config"].instance.setSelectionEnable(True)
271 self["streams"].style = "notselected"
272 self["config"].setCurrentIndex(len(self["config"].getList())-1)
273 self.focus = FOCUS_CONFIG
275 self["streams"].selectPrevious()
278 if self.focus == FOCUS_CONFIG:
279 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
280 self["config"].instance.moveSelection(self["config"].instance.moveDown)
282 self["config"].instance.setSelectionEnable(False)
283 self["streams"].style = "default"
284 self.focus = FOCUS_STREAMS
285 elif self.focus == FOCUS_STREAMS:
286 self["streams"].selectNext()
289 if self.focus == FOCUS_STREAMS and self["streams"].list:
290 cur = self["streams"].getCurrent()
291 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
292 self.changeAudio(cur[2])
294 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
295 if self.infobar.selected_subtitle == cur[0]:
296 self.enableSubtitle(None)
297 selectedidx = self["streams"].getIndex()
299 self["streams"].setIndex(selectedidx)
301 self.enableSubtitle(cur[0])
304 elif self.focus == FOCUS_CONFIG:
310 class SubtitleSelection(AudioSelection):
311 def __init__(self, session, infobar=None):
312 AudioSelection.__init__(self, session, infobar, page=PAGE_SUBTITLES)
313 self.skinName = ["AudioSelection"]