d98f411fc54f4f44aa5f034b36665908b0b2c74d
[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, 1), "SCART": (1, 0), "AUX": (2, 1) }
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][0])
42                 eAVSwitch.getInstance().setSlowblank(self.INPUT[input][1])
43                 # FIXME why do we have to reset the colorformat? bug in avs-driver?
44                 eAVSwitch.getInstance().setColorFormat(config.av.colorformat.value)
45
46 def InitAVSwitch():
47         config.av = ConfigSubsection();
48         config.av.colorformat = configElement("config.av.colorformat", configSelection, 1, (("cvbs", _("CVBS")), ("rgb", _("RGB")), ("svideo", _("S-Video")) ))
49         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"))) )
50         #config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, ("PAL", "PAL + PAL60", "Multi", "NTSC") )
51         config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, (("pal", _("PAL")), ("ntsc", _("NTSC"))) )
52         config.av.wss = configElement("config.av.wss", configSelection, 0, (("off", _("Off")), ("on", _("On"))) )
53         config.av.defaultac3 = configElement("config.av.defaultac3", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
54         config.av.vcrswitch = configElement("config.av.vcrswitch", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
55
56         iAVSwitch = AVSwitch()
57
58         def setColorFormat(configElement):
59                 iAVSwitch.setColorFormat(configElement.value)
60         def setAspectRatio(configElement):
61                 iAVSwitch.setAspectRatio(configElement.value)
62         def setSystem(configElement):
63                 iAVSwitch.setSystem(configElement.value)
64         def setWSS(configElement):
65                 iAVSwitch.setWSS(configElement.value)
66
67         # this will call the "setup-val" initial
68         config.av.colorformat.addNotifier(setColorFormat)
69         config.av.aspectratio.addNotifier(setAspectRatio)
70         config.av.tvsystem.addNotifier(setSystem)
71         config.av.wss.addNotifier(setWSS)
72         
73         iAVSwitch.setInput("ENCODER") # init on startup