use uncode for textinput component
[enigma2.git] / lib / python / Components / AVSwitch.py
1 from config import *
2 import os
3 from enigma import *
4
5 class AVSwitch:
6         INPUT = { "ENCODER": (0, 4), "SCART": (1, 3), "AUX": (2, 4) }
7
8         def setInput(self, input):
9                 eAVSwitch.getInstance().setInput(self.INPUT[input][0])
10                 if self.INPUT[input][1] == 4:
11                         aspect = self.getAspectRatioSetting()
12                         self.setAspectWSS(aspect)
13                         self.setAspectSlowBlank(aspect)
14                 else:
15                         eAVSwitch.getInstance().setSlowblank(self.INPUT[input][1])
16                 # FIXME why do we have to reset the colorformat? bug in avs-driver?
17                 eAVSwitch.getInstance().setColorFormat(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 = currentConfigSelectionElement(config.av.aspectratio)
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                 return val
45
46         def setAspectWSS(self, aspect=None):
47                 if aspect is None:
48                         aspect = self.getAspectRatioSetting()
49                 if aspect == 0 or aspect == 1: # letterbox or panscan
50                         value = 3 # 4:3_full_format
51                 elif aspect == 2: # 16:9
52                         if currentConfigSelectionElement(config.av.wss) == "off":
53                                 value = 2 # auto(4:3_off)
54                         else:
55                                 value = 1 # auto
56                 elif aspect == 3: # always 16:9
57                         value = 4 # 16:9_full_format
58                 elif aspect == 4 or aspect == 5: # 16:10
59                         value = 10 # 14:9_full_format
60                 eAVSwitch.getInstance().setWSS(value)
61
62         def setAspectSlowBlank(self, aspect=None):
63                 if aspect is None:
64                         aspect = self.getAspectRatioSetting()
65                 if aspect == 0 or aspect == 1: # letterbox or panscan
66                         value = 2 # 12 V
67                 elif aspect == 2: # 16:9
68                         value = 4 # auto
69                 elif aspect == 3 or aspect == 4 or aspect == 5: # always 16:9
70                         value = 1 # 6V
71                 eAVSwitch.getInstance().setSlowblank(value)
72
73 def InitAVSwitch():
74         config.av = ConfigSubsection();
75         config.av.yuvenabled = configElementBoolean("config.av.yuvenabled", 0)
76         colorformat_choices = ( ("cvbs", _("CVBS")), ("rgb", _("RGB")), ("svideo", _("S-Video")), ("yuv", _("YPbPr")) )
77         
78         # when YUV is not enabled, don't let the user select it
79         if not config.av.yuvenabled.value:
80                 colorformat_choices = colorformat_choices[:3]
81
82         config.av.colorformat = configElement("config.av.colorformat", configSelection, 1, colorformat_choices)
83         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")), ("16_10_letterbox", _("16:10 Letterbox")), ("16_10_panscan", _("16:10 PanScan"))) )
84         #config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, ("PAL", "PAL + PAL60", "Multi", "NTSC") )
85         config.av.tvsystem = configElement("config.av.tvsystem", configSelection, 0, (("pal", _("PAL")), ("ntsc", _("NTSC"))) )
86         config.av.wss = configElement("config.av.wss", configSelection, 0, (("off", _("Off")), ("on", _("On"))) )
87         config.av.defaultac3 = configElement("config.av.defaultac3", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
88         config.av.vcrswitch = configElement("config.av.vcrswitch", configSelection, 1, (("enable", _("Enable")), ("disable", _("Disable"))))
89
90         iAVSwitch = AVSwitch()
91
92         def setColorFormat(configElement):
93                 iAVSwitch.setColorFormat(configElement.value)
94
95         def setAspectRatio(configElement):
96                 iAVSwitch.setAspectRatio(configElement.value)
97
98         def setSystem(configElement):
99                 iAVSwitch.setSystem(configElement.value)
100
101         def setWSS(configElement):
102                 iAVSwitch.setAspectWSS()
103
104         # this will call the "setup-val" initial
105         config.av.colorformat.addNotifier(setColorFormat)
106         config.av.aspectratio.addNotifier(setAspectRatio)
107         config.av.tvsystem.addNotifier(setSystem)
108         config.av.wss.addNotifier(setWSS)
109
110         iAVSwitch.setInput("ENCODER") # init on startup