1 from enigma import eDVBVolumecontrol, eTimer
2 from Tools.Profile import profile
3 from Screens.Volume import Volume
4 from Screens.Mute import Mute
5 from GlobalActions import globalActionMap
6 from config import config, ConfigSubsection, ConfigInteger
8 profile("VolumeControl")
9 #TODO .. move this to a own .py file
12 """Volume control, handles volUp, volDown, volMute actions and display
13 a corresponding dialog"""
14 def __init__(self, session):
15 global globalActionMap
16 globalActionMap.actions["volumeUp"]=self.volUp
17 globalActionMap.actions["volumeDown"]=self.volDown
18 globalActionMap.actions["volumeMute"]=self.volMute
20 assert not VolumeControl.instance, "only one VolumeControl instance is allowed!"
21 VolumeControl.instance = self
23 config.audio = ConfigSubsection()
24 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
26 self.volumeDialog = session.instantiateDialog(Volume)
27 self.muteDialog = session.instantiateDialog(Mute)
29 self.hideVolTimer = eTimer()
30 self.hideVolTimer.callback.append(self.volHide)
32 vol = config.audio.volume.value
33 self.volumeDialog.setValue(vol)
34 self.volctrl = eDVBVolumecontrol.getInstance()
35 self.volctrl.setVolume(vol, vol)
38 if self.volctrl.isMuted():
39 config.audio.volume.value = 0
41 config.audio.volume.value = self.volctrl.getVolume()
42 config.audio.volume.save()
50 def setVolume(self, direction):
51 oldvol = self.volctrl.getVolume()
53 self.volctrl.volumeUp()
55 self.volctrl.volumeDown()
56 is_muted = self.volctrl.isMuted()
57 vol = self.volctrl.getVolume()
58 self.volumeDialog.show()
60 self.volMute() # unmute
62 self.volMute(False, True) # mute but dont show mute symbol
63 if self.volctrl.isMuted():
64 self.volumeDialog.setValue(0)
66 self.volumeDialog.setValue(self.volctrl.getVolume())
68 self.hideVolTimer.start(3000, True)
71 self.volumeDialog.hide()
73 def volMute(self, showMuteSymbol=True, force=False):
74 vol = self.volctrl.getVolume()
76 self.volctrl.volumeToggleMute()
77 if self.volctrl.isMuted():
79 self.muteDialog.show()
80 self.volumeDialog.setValue(0)
82 self.muteDialog.hide()
83 self.volumeDialog.setValue(vol)