enigma2: update to 4.3.1r12
[enigma2.git] / usr / lib / enigma2 / python / Plugins / SystemPlugins / Videomode / plugin.py
1 from Screens.Screen import Screen
2 from Plugins.Plugin import PluginDescriptor
3 from Components.SystemInfo import SystemInfo
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import getConfigListEntry, config, ConfigBoolean, ConfigNothing
6 from Components.Sources.StaticText import StaticText
7
8 import VideoHardware
9
10 config.misc.videowizardenabled = ConfigBoolean(default = True)
11
12 class VideoSetup(Screen, ConfigListScreen):
13
14         def __init__(self, session, hw):
15                 Screen.__init__(self, session)
16                 # for the skin: first try VideoSetup, then Setup, this allows individual skinning
17                 self.skinName = ["VideoSetup", "Setup" ]
18                 self.setup_title = _("A/V Settings")
19                 self.hw = hw
20                 self.onChangedEntry = [ ]
21
22                 # handle hotplug by re-creating setup
23                 self.onShow.append(self.startHotplug)
24                 self.onHide.append(self.stopHotplug)
25
26                 self.list = [ ]
27                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
28
29                 from Components.ActionMap import ActionMap
30                 self["actions"] = ActionMap(["SetupActions"], 
31                         {
32                                 "cancel": self.keyCancel,
33                                 "save": self.apply,
34                         }, -2)
35
36                 self["key_red"] = StaticText(_("Cancel"))
37                 self["key_green"] = StaticText(_("OK"))
38
39                 self.createSetup()
40                 self.grabLastGoodMode()
41                 self.onLayoutFinish.append(self.layoutFinished)
42
43         def layoutFinished(self):
44                 self.setTitle(self.setup_title)
45
46         def startHotplug(self):
47                 self.hw.on_hotplug.append(self.createSetup)
48
49         def stopHotplug(self):
50                 self.hw.on_hotplug.remove(self.createSetup)
51
52         def createSetup(self):
53                 level = config.usage.setup_level.index
54
55                 self.list = [
56                         getConfigListEntry(_("Video")),
57                         getConfigListEntry(_("Video Output"), config.av.videoport)
58                 ]
59
60                 (port, mode, rate) = self._getPortModeRate()
61
62                 # if we have modes for this port:
63                 if mode and rate:
64                         # add mode- and rate-selection:
65                         self.list.append(getConfigListEntry(_("Mode"), mode))
66                         if mode.value == 'PC':
67                                 self.list.append(getConfigListEntry(_("Resolution"), rate))
68                         else:
69                                 self.list.append(getConfigListEntry(_("Refresh Rate"), rate))
70
71                 # some modes (720p, 1080i) are always widescreen. Don't let the user select something here, "auto" is not what he wants.
72                 force_wide = self.hw.isWidescreenMode(port, mode and mode.value or None)
73
74                 if not force_wide:
75                         self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspect))
76
77                 if force_wide or config.av.aspect.value in ("16_9", "16_10"):
78                         self.list.extend((
79                                 getConfigListEntry(_("Display 4:3 content as"), config.av.policy_43),
80                                 getConfigListEntry(_("Display >16:9 content as"), config.av.policy_169)
81                         ))
82                 elif config.av.aspect.value == "4_3":
83                         self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169))
84
85 #               if port == "DVI":
86 #                       self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
87                 if port and port.value and port.value == "Scart":
88                         self.list.append(getConfigListEntry(_("Color Format"), config.av.colorformat))
89                         if level >= 1:
90                                 self.list.append(getConfigListEntry(_("WSS on 4:3"), config.av.wss))
91                                 if SystemInfo["ScartSwitch"]:
92                                         self.list.append(getConfigListEntry(_("Auto scart switching"), config.av.vcrswitch))
93
94                 if SystemInfo["CanChangeOsdAlpha"]:
95                         self.list.append(getConfigListEntry(_("OSD visibility"), config.av.osd_alpha))
96
97                 if not isinstance(config.av.scaler_sharpness, ConfigNothing):
98                         self.list.append(getConfigListEntry(_("Scaler sharpness"), config.av.scaler_sharpness))
99
100                 if level >= 1:
101                         if SystemInfo["HDRSupport"]:
102                                 self.list.append(getConfigListEntry(_("HLG Support"), config.av.hlg_support))
103                                 self.list.append(getConfigListEntry(_("HDR10 Support"), config.av.hdr10_support))
104                                 self.list.append(getConfigListEntry(_("Allow 12bit"), config.av.allow_12bit))
105                                 self.list.append(getConfigListEntry(_("Allow 10bit"), config.av.allow_10bit))
106                         self.list.append(getConfigListEntry(_("Audio")))
107                         self.list.append(getConfigListEntry(_("AC3 default"), config.av.defaultac3))
108                         if SystemInfo["CanDownmixAC3"]:
109                                 self.list.append(getConfigListEntry(_("AC3 downmix"), config.av.downmix_ac3))
110                         self.list.extend((
111                                 getConfigListEntry(_("General AC3 Delay"), config.av.generalAC3delay),
112                                 getConfigListEntry(_("General PCM Delay"), config.av.generalPCMdelay)
113                         ))
114                         if SystemInfo["SupportsAC3PlusTranscode"]:
115                                 self.list.append(getConfigListEntry(_("Convert AC3+ to AC3"), config.av.convert_ac3plus))
116
117                 self["config"].list = self.list
118                 self["config"].l.setList(self.list)
119
120         def keyLeft(self):
121                 ConfigListScreen.keyLeft(self)
122                 self.createSetup()
123
124         def keyRight(self):
125                 ConfigListScreen.keyRight(self)
126                 self.createSetup()
127
128         def confirm(self, confirmed):
129                 if not confirmed:
130                         config.av.videoport.value = self.last_good[0]
131                         config.av.videomode[self.last_good[0]].value = self.last_good[1]
132                         config.av.videorate[self.last_good[1]].value = self.last_good[2]
133                         self.hw.setMode(*self.last_good)
134                         self.createSetup()
135                 else:
136                         self.keySave()
137
138         def _getPortModeRate(self):
139                 mode = None
140                 rate = None
141                 port = config.av.videoport
142                 if config.av.videomode.has_key(port.value):
143                         mode = config.av.videomode[port.value]
144                         if config.av.videorate.has_key(mode.value):
145                                 rate = config.av.videorate[mode.value]
146                 return (port, mode, rate)
147
148         def _getPortModeRateValues(self):
149                 mode = None
150                 rate = None
151                 port = config.av.videoport.value
152                 if config.av.videomode.has_key(port):
153                         mode = config.av.videomode[port].value
154                         if config.av.videorate.has_key(mode):
155                                 rate = config.av.videorate[mode].value
156                 return (port, mode, rate)
157
158         def grabLastGoodMode(self):
159                 self.last_good = self._getPortModeRateValues()
160
161         def apply(self):
162                 (port, mode, rate) = self._getPortModeRateValues()
163                 if (port, mode, rate) != self.last_good:
164                         self.hw.setMode(port, mode, rate)
165                         from Screens.MessageBox import MessageBox
166                         self.session.openWithCallback(self.confirm, MessageBox, _("Is this videomode ok?"), MessageBox.TYPE_YESNO, timeout = 20, default = False)
167                 else:
168                         self.keySave()
169
170         # for summary:
171         def changedEntry(self):
172                 for x in self.onChangedEntry:
173                         x()
174
175         def getCurrentEntry(self):
176                 return self["config"].getCurrent()[0]
177
178         def getCurrentValue(self):
179                 return str(self["config"].getCurrent()[1].getText())
180
181         def createSummary(self):
182                 from Screens.Setup import SetupSummary
183                 return SetupSummary
184
185
186 def createInstance(reason, session = None, **kwargs):
187         if reason == 0:
188                 video_hw = VideoHardware.video_hw
189
190 def videoSetupMain(session, **kwargs):
191         session.open(VideoSetup, VideoHardware.video_hw)
192
193 def startSetup(menuid):
194         if menuid != "osd_video_audio":
195                 return [ ]
196
197         return [(_("A/V Settings"), videoSetupMain, "av_setup", 20)]
198
199 def VideoWizard(*args, **kwargs):
200         from VideoWizard import VideoWizard
201         return VideoWizard(*args, **kwargs)
202
203 def Plugins(**kwargs):
204         list = [
205                 PluginDescriptor(where = [PluginDescriptor.WHERE_AUTOSTART], fnc = createInstance),
206                 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, needsRestart = False, fnc=startSetup) 
207         ]
208         return list