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()
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)
85 selectedAudio = self.audioTracks.getCurrentTrack()
88 i = audio.getTrackInfo(x)
89 languages = i.getLanguage().split('/')
90 description = i.getDescription() or _("<unknown>")
94 if selectedAudio == x:
95 selected = _("Running")
99 for lang in languages:
102 if LanguageCodes.has_key(lang):
103 language += LanguageCodes[lang][0]
110 streams.append((x, "", number, description, language, selected))
114 conflist.append(('',))
115 self["key_green"].setBoolean(False)
117 elif self.settings.menupage.getValue() == PAGE_SUBTITLES:
118 self.setTitle(_("Subtitle selection"))
119 conflist.append(('',))
120 conflist.append(('',))
121 self["key_red"].setBoolean(False)
122 self["key_green"].setBoolean(False)
124 if self.subtitlesEnabled():
125 sel = self.infobar.selected_subtitle
131 subtitlelist = self.getSubtitleList()
133 if len(subtitlelist):
134 for x in subtitlelist:
137 language = _("<unknown>")
140 if sel and x[:4] == sel[:4]:
141 selected = _("Running")
145 if LanguageCodes.has_key(x[4]):
146 language = LanguageCodes[x[4]][0]
152 number = "%x" % (x[1])
156 number = "%x%02x" % (x[3],x[2])
159 types = ("UTF-8 text","SSA / AAS",".SRT file")
160 description = types[x[2]]
162 streams.append((x, "", number, description, language, selected))
168 conflist.append(getConfigListEntry(_("Menu"), self.settings.menupage))
170 from Components.PluginComponent import plugins
171 from Plugins.Plugin import PluginDescriptor
173 if hasattr(self.infobar, "runPlugin"):
175 def __init__(self, fnc, *args):
178 def __call__(self, *args, **kwargs):
181 Plugins = [ (p.name, PluginCaller(self.infobar.runPlugin, p)) for p in plugins.getPlugins(where = PluginDescriptor.WHERE_AUDIOMENU) ]
184 self["key_blue"].setBoolean(True)
185 conflist.append(getConfigListEntry(Plugins[0][0], ConfigNothing()))
186 self.plugincallfunc = Plugins[0][1]
188 print "these plugins are installed but not displayed in the dialog box:", Plugins[1:]
190 self["config"].list = conflist
191 self["config"].l.setList(conflist)
193 self["streams"].list = streams
194 self["streams"].setIndex(selectedidx)
196 def __updatedInfo(self):
199 def getSubtitleList(self):
200 s = self.infobar and self.infobar.getCurrentServiceSubtitle()
201 l = s and s.getSubtitleList() or [ ]
204 def subtitlesEnabled(self):
205 return self.infobar.subtitles_enabled
207 def enableSubtitle(self, subtitles):
208 if self.infobar.selected_subtitle != subtitles:
209 self.infobar.subtitles_enabled = False
210 self.infobar.selected_subtitle = subtitles
212 self.infobar.subtitles_enabled = True
214 def changeAC3Downmix(self, downmix):
215 if downmix.getValue() == True:
216 config.av.downmix_ac3.value = True
218 config.av.downmix_ac3.value = False
219 config.av.downmix_ac3.save()
221 def changeMode(self, mode):
223 self.audioChannel.selectChannel(int(mode.getValue()))
225 def changeAudio(self, audio):
227 if isinstance(track, int):
228 if self.session.nav.getCurrentService().audioTracks().getNumberOfTracks() > track:
229 self.audioTracks.selectTrack(track)
232 if self.focus == FOCUS_CONFIG:
233 ConfigListScreen.keyLeft(self)
234 elif self.focus == FOCUS_STREAMS:
235 self["streams"].setIndex(0)
237 def keyRight(self, config = False):
238 if config or self.focus == FOCUS_CONFIG:
239 if self["config"].getCurrentIndex() < 3:
240 ConfigListScreen.keyRight(self)
241 elif hasattr(self, "plugincallfunc"):
242 self.plugincallfunc()
243 if self.focus == FOCUS_STREAMS and self["streams"].count() and config == False:
244 self["streams"].setIndex(self["streams"].count()-1)
247 if self["key_red"].getBoolean():
251 if self["key_green"].getBoolean():
255 if self["key_yellow"].getBoolean():
259 if self["key_blue"].getBoolean():
262 def colorkey(self, idx):
263 self["config"].setCurrentIndex(idx)
267 if self.focus == FOCUS_CONFIG:
268 self["config"].instance.moveSelection(self["config"].instance.moveUp)
269 elif self.focus == FOCUS_STREAMS:
270 if self["streams"].getIndex() == 0:
271 self["config"].instance.setSelectionEnable(True)
272 self["streams"].style = "notselected"
273 self["config"].setCurrentIndex(len(self["config"].getList())-1)
274 self.focus = FOCUS_CONFIG
276 self["streams"].selectPrevious()
279 if self.focus == FOCUS_CONFIG:
280 if self["config"].getCurrentIndex() < len(self["config"].getList())-1:
281 self["config"].instance.moveSelection(self["config"].instance.moveDown)
283 self["config"].instance.setSelectionEnable(False)
284 self["streams"].style = "default"
285 self.focus = FOCUS_STREAMS
286 elif self.focus == FOCUS_STREAMS:
287 self["streams"].selectNext()
290 if self.focus == FOCUS_STREAMS and self["streams"].list:
291 cur = self["streams"].getCurrent()
292 if self.settings.menupage.getValue() == PAGE_AUDIO and cur[0] is not None:
293 self.changeAudio(cur[2])
295 if self.settings.menupage.getValue() == PAGE_SUBTITLES and cur[0] is not None:
296 if self.infobar.selected_subtitle == cur[0]:
297 self.enableSubtitle(None)
298 selectedidx = self["streams"].getIndex()
300 self["streams"].setIndex(selectedidx)
302 self.enableSubtitle(cur[0])
305 elif self.focus == FOCUS_CONFIG:
311 class SubtitleSelection(AudioSelection):
312 def __init__(self, session, infobar=None):
313 AudioSelection.__init__(self, session, infobar, page=PAGE_SUBTITLES)
314 self.skinName = ["AudioSelection"]