1 # -*- coding: utf-8 -*-
3 # AutomaticVolumeAdjustment E2
7 # Coded by Dr.Best (c) 2009
8 # Support: www.dreambox-tools.info
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
21 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
23 from Screens.Screen import Screen
24 from Screens.MessageBox import MessageBox
25 from Components.MenuList import MenuList
26 from Components.Sources.StaticText import StaticText
27 from Components.ActionMap import ActionMap
28 from Components.ConfigList import ConfigList, ConfigListScreen
29 from Components.config import ConfigSubsection, ConfigText, \
30 getConfigListEntry, config, ConfigInteger, Config, ConfigSubList, ConfigDirectory, NoSave, ConfigYesNo
31 from os import path as os_path, open as os_open, close as os_close, O_RDWR as os_O_RDWR, O_CREAT as os_O_CREAT
32 from Screens.ChannelSelection import SimpleChannelSelection
33 from enigma import eServiceReference
34 from ServiceReference import ServiceReference
36 import plugin as AutomaticVolumeAdjustmentPlugin # import to submit config-values
38 class AutomaticVolumeAdjustmentConfig():
40 self.CONFIG_FILE = '/usr/lib/enigma2/python/Plugins/SystemPlugins/AutomaticVolumeAdjustment/config'
44 # load config file and initialize
45 def loadConfigFile(self):
46 print "[AutomaticVolumeAdjustmentConfig] Loading config file..."
47 self.config = Config()
48 if not os_path.exists(self.CONFIG_FILE):
49 fd = os_open( self.CONFIG_FILE, os_O_RDWR|os_O_CREAT)
51 self.config.loadFromFile(self.CONFIG_FILE)
52 self.config.entriescount = ConfigInteger(0)
53 self.config.Entries = ConfigSubList()
54 self.config.enable = ConfigYesNo(default = False)
55 self.config.adustvalue = ConfigInteger(default=25, limits=(0,50))
59 count = self.config.entriescount.value
63 self.initEntryConfig()
65 print "[AutomaticVolumeAdjustmentConfig] Loaded %s entries from config file..." % count
67 def initEntryConfig(self):
68 self.config.Entries.append(ConfigSubsection())
69 i = len(self.config.Entries) - 1
70 self.config.Entries[i].servicereference = ConfigText(default = "")
71 self.config.Entries[i].name = NoSave(ConfigDirectory(default = _("Press OK to select a service")))
72 self.config.Entries[i].adjustvalue = ConfigInteger(default=25, limits=(5,50))
73 return self.config.Entries[i]
75 def remove(self, configItem):
76 self.config.entriescount.value = self.config.entriescount.value - 1
77 self.config.entriescount.save()
78 self.config.Entries.remove(configItem)
79 self.config.Entries.save()
83 print "[AutomaticVolumeAdjustmentConfig] saving config file..."
84 self.config.saveToFile(self.CONFIG_FILE)
86 class AutomaticVolumeAdjustmentConfigScreen(ConfigListScreen, Screen):
88 <screen name="AutomaticVolumeAdjustmentConfigScreen" position="center,center" size="550,400">
89 <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
90 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
91 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
92 <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
93 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
95 <widget source="key_red" render="Label" position="0,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
96 <widget source="key_green" render="Label" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
97 <widget render="Label" source="key_blue" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
100 def __init__(self, session):
101 Screen.__init__(self, session)
102 self.title = _("Automatic Volume Adjustment - Config")
103 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
105 "green": self.keySave,
106 "red": self.keyCancel,
108 "cancel": self.keyCancel,
110 self["key_red"] = StaticText(_("Cancel"))
111 self["key_green"] = StaticText(_("OK"))
112 self["key_blue"] = StaticText(_("Services"))
113 self.configVA = AutomaticVolumeAdjustmentConfig()
115 self.list.append(getConfigListEntry(_("Enable"), self.configVA.config.enable))
116 self.list.append(getConfigListEntry(_("Default volume adjustment value for AC3/DTS"), self.configVA.config.adustvalue))
117 ConfigListScreen.__init__(self, self.list, session)
120 self.session.open(AutomaticVolumeAdjustmentEntriesListConfigScreen, self.configVA)
123 for x in self["config"].list:
126 if AutomaticVolumeAdjustmentPlugin.automaticvolumeadjustment is not None:
127 AutomaticVolumeAdjustmentPlugin.automaticvolumeadjustment.initializeConfigValues(self.configVA, True) # submit config values
131 ConfigListScreen.cancelConfirm(self, True)
134 class AutomaticVolumeAdjustmentEntriesListConfigScreen(Screen):
136 <screen position="center,center" size="550,400">
137 <widget render="Label" source="name" position="5,0" size="350,50" font="Regular;20" halign="left"/>
138 <widget render="Label" source="adjustvalue" position="355,0" size="200,50" font="Regular;20" halign="left"/>
139 <widget name="entrylist" position="0,50" size="550,300" scrollbarMode="showOnDemand"/>
140 <widget render="Label" source="key_red" position="0,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
141 <widget source="key_green" render="Label" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
142 <widget render="Label" source="key_yellow" position="280,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="yellow" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
143 <widget render="Label" source="key_blue" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
144 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
145 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
146 <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
147 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
150 def __init__(self, session, configVA):
151 Screen.__init__(self, session)
152 self.title = _("Automatic Volume Adjustment - Service Config")
153 self["name"] = StaticText(_("Servicename"))
154 self["adjustvalue"] = StaticText(_("Adjustment value"))
155 self["key_red"] = StaticText(_("Add"))
156 self["key_green"] = StaticText(_("OK"))
157 self["key_yellow"] = StaticText(_("Edit"))
158 self["key_blue"] = StaticText(_("Delete"))
159 self["entrylist"] = AutomaticVolumeAdjustmentEntryList([])
160 self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
163 "back" : self.keyClose,
165 "green": self.keyClose,
166 "yellow": self.keyYellow,
167 "blue": self.keyDelete,
169 self["entrylist"].setConfig(configVA)
172 def updateList(self):
173 self["entrylist"].buildList()
179 self.session.openWithCallback(self.updateList,AutomaticVolumeAdjustmentEntryConfigScreen,None, self["entrylist"].configVA)
182 try:sel = self["entrylist"].l.getCurrentSelection()[0]
184 self.close(self["entrylist"].getCurrentIndex(), sel)
187 try:sel = self["entrylist"].l.getCurrentSelection()[0]
191 self.session.openWithCallback(self.updateList,AutomaticVolumeAdjustmentEntryConfigScreen,sel, self["entrylist"].configVA)
194 try:sel = self["entrylist"].l.getCurrentSelection()[0]
198 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Do you really want to delete this entry?"))
200 def deleteConfirm(self, result):
203 sel = self["entrylist"].l.getCurrentSelection()[0]
204 self["entrylist"].configVA.remove(sel)
205 if AutomaticVolumeAdjustmentPlugin.automaticvolumeadjustment is not None:
206 AutomaticVolumeAdjustmentPlugin.automaticvolumeadjustment.initializeConfigValues(self["entrylist"].configVA, True) # submit config values
209 class AutomaticVolumeAdjustmentEntryList(MenuList):
210 def __init__(self, list, enableWrapAround = True):
211 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
212 self.l.setFont(0, gFont("Regular", 20))
213 self.l.setFont(1, gFont("Regular", 18))
216 def postWidgetCreate(self, instance):
217 MenuList.postWidgetCreate(self, instance)
218 instance.setItemHeight(20)
220 def getCurrentIndex(self):
221 return self.instance.getCurrentIndex()
223 def setConfig(self, configVA):
224 self.configVA = configVA
228 for c in self.configVA.config.Entries:
229 c.name.value = ServiceReference(eServiceReference(c.servicereference.value)).getServiceName()
232 (eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 350, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, c.name.value),
233 (eListboxPythonMultiContent.TYPE_TEXT, 355, 0,200, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.adjustvalue.value)),
240 class AutomaticVolumeAdjustmentEntryConfigScreen(ConfigListScreen, Screen):
242 <screen name="AutomaticVolumeAdjustmentEntryConfigScreen" position="center,center" size="550,400">
243 <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
244 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
245 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
246 <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
247 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
249 <widget source="key_red" render="Label" position="0,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
250 <widget source="key_green" render="Label" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
253 def __init__(self, session, entry, configVA):
254 Screen.__init__(self, session)
255 self.title = _("Automatic Volume Adjustment - Entry Config")
256 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
258 "green": self.keySave,
259 "red": self.keyCancel,
260 "cancel": self.keyCancel,
261 "ok": self.keySelect,
263 self["key_red"] = StaticText(_("Cancel"))
264 self["key_green"] = StaticText(_("OK"))
265 self.configVA = configVA
268 self.current = self.configVA.initEntryConfig()
273 self.service = getConfigListEntry(_("Servicename"), self.current.name)
274 self.list.append(self.service)
275 self.list.append(getConfigListEntry(_("Adjustment value"), self.current.adjustvalue))
276 ConfigListScreen.__init__(self, self.list, session)
279 cur = self["config"].getCurrent()
280 if cur == self.service:
281 self.session.openWithCallback(self.channelSelected, ConfigChannelSelection)
283 def channelSelected(self, ref = None):
285 self.current.name.value = ServiceReference(ref).getServiceName()
286 self.current.servicereference.value = ref.toString()
290 if self.current.servicereference.value:
291 if self.newmode == 1:
292 self.configVA.config.entriescount.value = self.configVA.config.entriescount.value + 1
293 self.configVA.config.entriescount.save()
294 for x in self["config"].list:
297 if AutomaticVolumeAdjustmentPlugin.automaticvolumeadjustment is not None:
298 AutomaticVolumeAdjustmentPlugin.automaticvolumeadjustment.initializeConfigValues(self.configVA, True) # submit config values
301 self.session.open(MessageBox, _("You must select a valid service!"), type = MessageBox.TYPE_INFO)
304 if self.newmode == 1:
305 self.configVA.remove(self.current)
306 ConfigListScreen.cancelConfirm(self, True)
308 class ConfigChannelSelection(SimpleChannelSelection):
309 def __init__(self, session):
310 SimpleChannelSelection.__init__(self, session, _("Channel Selection"))
311 self.skinName = ["SimpleChannelSelection"]
312 self["ChannelSelectEPGActions"] = ActionMap(["ChannelSelectEPGActions"],
314 "showEPGList": self.channelSelected
317 def channelSelected(self):
318 ref = self.getCurrentSelection()
319 if (ref.flags & 7) == 7:
321 elif not (ref.flags & eServiceReference.isMarker):