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
11 """Volume control, handles volUp, volDown, volMute actions and display
12 a corresponding dialog"""
13 def __init__(self, session):
14 global globalActionMap
15 globalActionMap.actions["volumeUp"]=self.volUp
16 globalActionMap.actions["volumeDown"]=self.volDown
17 globalActionMap.actions["volumeMute"]=self.volMute
19 config.audio = ConfigSubsection()
20 config.audio.volume = ConfigInteger(default = 100, limits = (0, 100))
22 self.volumeDialog = session.instantiateDialog(Volume)
23 self.muteDialog = session.instantiateDialog(Mute)
25 self.hideVolTimer = eTimer()
26 self.hideVolTimer.callback.append(self.volHide)
28 vol = config.audio.volume.value
29 self.volumeDialog.setValue(vol)
30 self.volctrl = eDVBVolumecontrol.getInstance()
31 self.volctrl.setVolume(vol, vol)
34 if self.volctrl.isMuted():
35 config.audio.volume.value = 0
37 config.audio.volume.value = self.volctrl.getVolume()
38 config.audio.volume.save()
46 def setVolume(self, direction):
47 oldvol = self.volctrl.getVolume()
49 self.volctrl.volumeUp()
51 self.volctrl.volumeDown()
52 is_muted = self.volctrl.isMuted()
53 vol = self.volctrl.getVolume()
54 self.volumeDialog.show()
56 self.volMute() # unmute
58 self.volMute(False, True) # mute but dont show mute symbol
59 if self.volctrl.isMuted():
60 self.volumeDialog.setValue(0)
62 self.volumeDialog.setValue(self.volctrl.getVolume())
64 self.hideVolTimer.start(3000, True)
67 self.volumeDialog.hide()
69 def volMute(self, showMuteSymbol=True, force=False):
70 vol = self.volctrl.getVolume()
72 self.volctrl.volumeToggleMute()
73 if self.volctrl.isMuted():
75 self.muteDialog.show()
76 self.volumeDialog.setValue(0)
78 self.muteDialog.hide()
79 self.volumeDialog.setValue(vol)