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
10 profile("VolumeControl")
11 #TODO .. move this to a own .py file
13 """Volume control, handles volUp, volDown, volMute actions and display
14 a corresponding dialog"""
15 def __init__(self, session):
16 global globalActionMap
18 globalActionMap.actions["volumeUp"]=self.volUp
19 globalActionMap.actions["volumeDown"]=self.volDown
20 globalActionMap.actions["volumeMute"]=self.volMute
22 assert not instance, "only one VolumeControl instance is allowed!"
25 config.audio = ConfigSubsection()
26 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
28 self.volumeDialog = session.instantiateDialog(Volume)
29 self.muteDialog = session.instantiateDialog(Mute)
31 self.hideVolTimer = eTimer()
32 self.hideVolTimer.callback.append(self.volHide)
34 vol = config.audio.volume.value
35 self.volumeDialog.setValue(vol)
36 self.volctrl = eDVBVolumecontrol.getInstance()
37 self.volctrl.setVolume(vol, vol)
40 if self.volctrl.isMuted():
41 config.audio.volume.value = 0
43 config.audio.volume.value = self.volctrl.getVolume()
44 config.audio.volume.save()
52 def setVolume(self, direction):
53 oldvol = self.volctrl.getVolume()
55 self.volctrl.volumeUp()
57 self.volctrl.volumeDown()
58 is_muted = self.volctrl.isMuted()
59 vol = self.volctrl.getVolume()
60 self.volumeDialog.show()
62 self.volMute() # unmute
64 self.volMute(False, True) # mute but dont show mute symbol
65 if self.volctrl.isMuted():
66 self.volumeDialog.setValue(0)
68 self.volumeDialog.setValue(self.volctrl.getVolume())
70 self.hideVolTimer.start(3000, True)
73 self.volumeDialog.hide()
75 def volMute(self, showMuteSymbol=True, force=False):
76 vol = self.volctrl.getVolume()
78 self.volctrl.volumeToggleMute()
79 if self.volctrl.isMuted():
81 self.muteDialog.show()
82 self.volumeDialog.setValue(0)
84 self.muteDialog.hide()
85 self.volumeDialog.setValue(vol)