fix wrong return at "state"
[enigma2-plugins.git] / webinterface / src / WebComponents / Sources / Volume.py
1 from enigma import eDVBVolumecontrol #this is not nice
2
3 from Components.config import config
4 from Components.Sources.Source import Source
5
6 from GlobalActions import globalActionMap
7
8 from mytest import VolumeControl
9
10 class Volume(Source):
11         
12     def __init__(self,session,command_default="state"):
13         self.cmd = command_default
14         Source.__init__(self)
15         global globalActionMap # hackalert :)       
16         self.actionmap = globalActionMap
17         self.volctrl = eDVBVolumecontrol.getInstance() # this is not nice
18         #self.volcontrol = VolumeControl(session)
19     def handleCommand(self, cmd):
20         self.cmd = cmd
21         
22     def do_func(self):
23         list = []
24         if self.cmd == "state":
25             list.append(True)
26             list.append("state")
27         elif self.cmd == "up":
28             self.actionmap.actions["volumeUp"]()
29             list.append(True)
30             list.append("volume changed")
31         elif self.cmd == "down":
32             self.actionmap.actions["volumeDown"]()
33             list.append(True)
34             list.append("volume changed")
35         elif self.cmd == "mute":
36             self.actionmap.actions["volumeMute"]()
37             list.append(True)
38             list.append("mute toggled")
39         elif self.cmd.startswith("set"):
40             try:
41                 targetvol = int(self.cmd[3:])
42                 if targetvol>100:
43                     targetvol = 100
44                 if targetvol<0:
45                     targetvol = 0
46                 # because we can not set a fix volume in mytest.VolumeControl, we have to do in manualy here
47                 self.volctrl.setVolume(targetvol,targetvol) 
48                 #self.volcontrol.volumeDialog.setValue(targetvol)
49                 #self.volcontrol.volumeDialog.show()
50                 #self.volcontrol.hideVolTimer.start(3000, True)
51                 #self.volcontrol.volSave()
52                 list.append(True)
53                 list.append("volume set to %i" % targetvol)
54             except ValueError: # if cmd was set12NotInt
55                 list.append(False)
56                 list.append("wrong parameter format 'set=%s'. Use set=set15 "%self.cmd)
57         else:
58             list.append(False)
59             list.append("unknown Volume command %s" %self.cmd)
60         list.append(self.volctrl.getVolume())
61         list.append(self.volctrl.isMuted())
62         print "returning",[list]
63         return [list]
64     
65     list = property(do_func)
66     lut = {"Result": 0
67            ,"ResultText": 1
68            ,"Volume": 2
69            ,"isMuted": 3
70            }
71
72