1 # -*- coding: utf-8 -*-
3 # AutomaticVolumeAdjustment E2
7 # Coded by Dr.Best (c) 2010
8 # Support: www.dreambox-tools.info
10 # This plugin is licensed under the Creative Commons
11 # Attribution-NonCommercial-ShareAlike 3.0 Unported
12 # License. To view a copy of this license, visit
13 # http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
14 # Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
16 # Alternatively, this plugin may be distributed and executed on hardware which
17 # is licensed by Dream Multimedia GmbH.
19 # This plugin is NOT free software. It is open source, you are allowed to
20 # modify it (if you keep the license), but it may not be commercially
21 # distributed other than under the conditions noted above.
23 from Components.config import ConfigSubsection, ConfigText, \
24 config, ConfigInteger, Config, ConfigSubList, ConfigDirectory, NoSave, ConfigYesNo, ConfigSelectionNumber, ConfigSelection
25 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
26 from pickle import load as pickle_load, dump as pickle_dump
28 CONFIG_FILE_VOLUME = '/usr/lib/enigma2/python/Plugins/SystemPlugins/AutomaticVolumeAdjustment/config_volume'
31 if os_path.exists(CONFIG_FILE_VOLUME):
32 pkl_file = open(CONFIG_FILE_VOLUME, 'rb')
34 volumedict = pickle_load(pkl_file)
39 def saveVolumeDict(dict):
40 pkl_file = open(CONFIG_FILE_VOLUME, 'wb')
42 pickle_dump(dict, pkl_file)
45 class AutomaticVolumeAdjustmentConfig():
47 self.CONFIG_FILE = '/usr/lib/enigma2/python/Plugins/SystemPlugins/AutomaticVolumeAdjustment/config'
51 # load config file and initialize
52 def loadConfigFile(self):
53 print "[AutomaticVolumeAdjustmentConfig] Loading config file..."
54 self.config = Config()
55 if not os_path.exists(self.CONFIG_FILE):
56 fd = os_open( self.CONFIG_FILE, os_O_RDWR|os_O_CREAT)
58 self.config.loadFromFile(self.CONFIG_FILE)
59 self.config.entriescount = ConfigInteger(0)
60 self.config.Entries = ConfigSubList()
61 self.config.enable = ConfigYesNo(default = False)
62 self.config.modus = ConfigSelection(choices = [("0", _("Automatic volume adjust")), ("1", _("Remember service volume value"))], default = "0")
63 self.config.adustvalue = ConfigSelectionNumber(-50, 50, 5, default = 25)
64 self.config.mpeg_max_volume = ConfigSelectionNumber(10, 100, 5, default = 100)
65 self.config.show_volumebar = ConfigYesNo(default = False)
69 count = self.config.entriescount.value
73 self.initEntryConfig()
75 print "[AutomaticVolumeAdjustmentConfig] Loaded %s entries from config file..." % count
77 def initEntryConfig(self):
78 self.config.Entries.append(ConfigSubsection())
79 i = len(self.config.Entries) - 1
80 self.config.Entries[i].servicereference = ConfigText(default = "")
81 self.config.Entries[i].name = NoSave(ConfigDirectory(default = _("Press OK to select a service")))
82 self.config.Entries[i].adjustvalue = ConfigSelectionNumber(-50, 50, 5, default = 25)
83 return self.config.Entries[i]
85 def remove(self, configItem):
86 self.config.entriescount.value = self.config.entriescount.value - 1
87 self.config.entriescount.save()
88 self.config.Entries.remove(configItem)
89 self.config.Entries.save()
93 print "[AutomaticVolumeAdjustmentConfig] saving config file..."
94 self.config.saveToFile(self.CONFIG_FILE)