b36dc4a282706e78c67100a081daf45a733b5748
[vuplus_dvbapp] / lib / python / Components / AVSwitch.py
1 from config import *
2 import os
3 from enigma import *
4
5 class AVSwitch:
6         INPUT = { "ENCODER": 0, "SCART": 1, "AUX": 2 }
7         def __init__(self):
8                 pass
9
10         def setColorFormat(self, value):
11                 eAVSwitch.getInstance().setColorFormat(value)
12                 
13         def setAspectRatio(self, value):
14                 eAVSwitch.getInstance().setAspectRatio(value)
15                 self.checkWSS()
16
17         def setSystem(self, value):
18                 eAVSwitch.getInstance().setVideomode(value)
19                 
20         def checkWSS(self):
21                 if currentConfigSelectionElement(config.av.aspectratio) == "4_3_letterbox" or currentConfigSelectionElement(config.av.aspectratio) == "4_3_panscan":
22                         writevalue = "4:3_full_format"
23                 elif currentConfigSelectionElement(config.av.aspectratio) == "16_9":
24                         if currentConfigSelectionElement(config.av.wss) == "off":
25                                 writevalue = "auto(4:3_off)"
26                         else:
27                                 writevalue = "auto"
28                 elif currentConfigSelectionElement(config.av.aspectratio) == "16_9_always":
29                         writevalue = "16:9_full_format"
30                 try:
31                         file = open("/proc/stb/denc/0/wss", "w")
32                         file.write(writevalue)
33                         file.close()
34                 except:
35                         print "[AVSwitch.py] Error writing to /proc/stb/denc/0/wss"
36
37         def setWSS(self, value = None):
38                 self.checkWSS()
39         
40         def setInput(self, input):
41                 eAVSwitch.getInstance().setInput(self.INPUT[input])
42                 # FIXME why do we have to reset the colorformat? bug in avs-driver?
43                 eAVSwitch.getInstance().setColorFormat(config.av.colorformat.value)
44
45 def InitAVSwitch():
46         config.av = ConfigSubsection();
47         config.av.colorformat = configElement("config.av.colorformat", configSelection, 1, (("cvbs", _("CVBS")), ("rgb", _("RGB")), ("svideo", _("S-Video")) ))
48         config.av.aspectratio = configElement("config.av.aspectratio", configSelection, 0, (("4_3_letterbox", _("4:3 Letterbox")), ("4_3_panscan", _("4:3 PanScan")), ("16_9", _("16:9")), ("16_9_always", _("16:9 always"))) )
49         #config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, ("PAL", "PAL + PAL60", "Multi", "NTSC") )
50         config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, (("pal", _("PAL")), ("ntsc", _("NTSC"))) )
51         config.av.wss = configElement("config.av.wss", configSelection, 0, (("off", _("Off")), ("on", _("On"))) )
52         config.av.defaultac3 = configElement("config.av.defaultac3", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
53         config.av.vcrswitch = configElement("config.av.vcrswitch", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
54
55         iAVSwitch = AVSwitch()
56
57         def setColorFormat(configElement):
58                 iAVSwitch.setColorFormat(configElement.value)
59         def setAspectRatio(configElement):
60                 iAVSwitch.setAspectRatio(configElement.value)
61         def setSystem(configElement):
62                 iAVSwitch.setSystem(configElement.value)
63         def setWSS(configElement):
64                 iAVSwitch.setWSS(configElement.value)
65
66         # this will call the "setup-val" initial
67         config.av.colorformat.addNotifier(setColorFormat)
68         config.av.aspectratio.addNotifier(setAspectRatio)
69         config.av.tvsystem.addNotifier(setSystem)
70         config.av.wss.addNotifier(setWSS)
71         
72         iAVSwitch.setInput("ENCODER") # init on startup