allow access to gfbdc from python to set resolution
[enigma2.git] / lib / python / Components / AVSwitch.py
1 from config import config, ConfigSelection, ConfigYesNo, ConfigEnableDisable, ConfigSubsection, ConfigBoolean
2 from enigma import eAVSwitch
3
4 class AVSwitch:
5         INPUT = { "ENCODER": (0, 4), "SCART": (1, 3), "AUX": (2, 4) }
6
7         def setInput(self, input):
8                 eAVSwitch.getInstance().setInput(self.INPUT[input][0])
9                 if self.INPUT[input][1] == 4:
10                         aspect = self.getAspectRatioSetting()
11                         self.setAspectWSS(aspect)
12                         self.setAspectSlowBlank(aspect)
13                 else:
14                         eAVSwitch.getInstance().setSlowblank(self.INPUT[input][1])
15                 # FIXME why do we have to reset the colorformat? bug in avs-driver?
16                 map = {"cvbs": 0, "rgb": 1, "svideo": 2, "yuv": 3}
17                 eAVSwitch.getInstance().setColorFormat(map[config.av.colorformat.value])
18
19         def setColorFormat(self, value):
20                 eAVSwitch.getInstance().setColorFormat(value)
21
22         def setAspectRatio(self, value):
23                 eAVSwitch.getInstance().setAspectRatio(value)
24                 self.setAspectWSS(value)
25                 self.setAspectSlowBlank(value)
26
27         def setSystem(self, value):
28                 eAVSwitch.getInstance().setVideomode(value)
29
30         def getAspectRatioSetting(self):
31                 valstr = config.av.aspectratio.value
32                 if valstr == "4_3_letterbox":
33                         val = 0
34                 elif valstr == "4_3_panscan":
35                         val = 1
36                 elif valstr == "16_9":
37                         val = 2
38                 elif valstr == "16_9_always":
39                         val = 3
40                 elif valstr == "16_10_letterbox":
41                         val = 4
42                 elif valstr == "16_10_panscan":
43                         val = 5
44                 elif valstr == "16_9_letterbox":
45                         val = 6
46                 return val
47
48         def setAspectWSS(self, aspect=None):
49                 if aspect is None:
50                         aspect = self.getAspectRatioSetting()
51                 if aspect == 0 or aspect == 1: # letterbox or panscan
52                         value = 3 # 4:3_full_format
53                 elif aspect == 2: # 16:9
54                         if not config.av.wss.value:
55                                 value = 2 # auto(4:3_off)
56                         else:
57                                 value = 1 # auto
58                 elif aspect == 3 or aspect == 6: # always 16:9
59                         value = 4 # 16:9_full_format
60                 elif aspect == 4 or aspect == 5: # 16:10
61                         value = 10 # 14:9_full_format
62                 eAVSwitch.getInstance().setWSS(value)
63
64         def setAspectSlowBlank(self, aspect=None):
65                 if aspect is None:
66                         aspect = self.getAspectRatioSetting()
67                 if aspect == 0 or aspect == 1: # letterbox or panscan
68                         value = 2 # 12 V
69                 elif aspect == 2: # 16:9
70                         value = 4 # auto
71                 elif aspect == 3 or aspect == 4 or aspect == 5 or aspect == 6: # always 16:9
72                         value = 1 # 6V
73                 eAVSwitch.getInstance().setSlowblank(value)
74
75 def InitAVSwitch():
76         config.av = ConfigSubsection()
77         config.av.yuvenabled = ConfigBoolean(default=False)
78         colorformat_choices = {"cvbs": _("CVBS"), "rgb": _("RGB"), "svideo": _("S-Video")}
79         
80         # when YUV is not enabled, don't let the user select it
81         if config.av.yuvenabled.value:
82                 colorformat_choices["yuv"] = _("YPbPr")
83
84         config.av.colorformat = ConfigSelection(choices=colorformat_choices, default="rgb")
85         config.av.aspectratio = ConfigSelection(choices={
86                         "4_3_letterbox": _("4:3 Letterbox"),
87                         "4_3_panscan": _("4:3 PanScan"), 
88                         "16_9": _("16:9"), 
89                         "16_9_always": _("16:9 always"),
90                         "16_10_letterbox": _("16:10 Letterbox"),
91                         "16_10_panscan": _("16:10 PanScan"), 
92                         "16_9_letterbox": _("16:9 Letterbox")}, 
93                         default = "4_3_letterbox")
94         config.av.tvsystem = ConfigSelection(choices = {"pal": _("PAL"), "ntsc": _("NTSC"), "multinorm": _("multinorm")}, default="pal")
95         config.av.wss = ConfigEnableDisable(default = True)
96         config.av.defaultac3 = ConfigYesNo(default = False)
97         config.av.vcrswitch = ConfigEnableDisable(default = False)
98
99         iAVSwitch = AVSwitch()
100
101         def setColorFormat(configElement):
102                 map = {"cvbs": 0, "rgb": 1, "svideo": 2, "yuv": 3}
103                 iAVSwitch.setColorFormat(map[configElement.value])
104
105         def setAspectRatio(configElement):
106                 map = {"4_3_letterbox": 0, "4_3_panscan": 1, "16_9": 2, "16_9_always": 3, "16_10_letterbox": 4, "16_10_panscan": 5, "16_9_letterbox" : 6}
107                 iAVSwitch.setAspectRatio(map[configElement.value])
108
109         def setSystem(configElement):
110                 map = {"pal": 0, "ntsc": 1, "multinorm" : 2}
111                 iAVSwitch.setSystem(map[configElement.value])
112
113         def setWSS(configElement):
114                 iAVSwitch.setAspectWSS()
115
116         # this will call the "setup-val" initial
117         config.av.colorformat.addNotifier(setColorFormat)
118         config.av.aspectratio.addNotifier(setAspectRatio)
119         config.av.tvsystem.addNotifier(setSystem)
120         config.av.wss.addNotifier(setWSS)
121
122         iAVSwitch.setInput("ENCODER") # init on startup