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, ConfigSlider
6 from Components.Sources.StaticText import StaticText
8 from VideoHardware import video_hw
10 config.misc.videowizardenabled = ConfigBoolean(default = True)
12 class VideoSetup(Screen, ConfigListScreen):
14 def __init__(self, session, hw):
15 Screen.__init__(self, session)
16 self.setup_title = _("A/V Settings")
18 self.onChangedEntry = [ ]
20 # handle hotplug by re-creating setup
21 self.onShow.append(self.startHotplug)
22 self.onHide.append(self.stopHotplug)
25 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
27 from Components.ActionMap import ActionMap
28 self["actions"] = ActionMap(["SetupActions"],
30 "cancel": self.keyCancel,
34 self["key_red"] = StaticText(_("Cancel"))
35 self["key_green"] = StaticText(_("OK"))
38 self.grabLastGoodMode()
39 self.onLayoutFinish.append(self.layoutFinished)
41 def layoutFinished(self):
42 self.setTitle(self.setup_title)
44 def startHotplug(self):
45 self.hw.on_hotplug.append(self.createSetup)
47 def stopHotplug(self):
48 self.hw.on_hotplug.remove(self.createSetup)
50 def createSetup(self):
51 level = config.usage.setup_level.index
54 getConfigListEntry(_("Video Output"), config.av.videoport)
57 # if we have modes for this port:
58 if config.av.videoport.value in config.av.videomode:
59 # add mode- and rate-selection:
60 self.list.append(getConfigListEntry(_("Mode"), config.av.videomode[config.av.videoport.value]))
61 if config.av.videomode[config.av.videoport.value].value == 'PC':
62 self.list.append(getConfigListEntry(_("Resolution"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
64 self.list.append(getConfigListEntry(_("Refresh Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
66 port = config.av.videoport.value
67 if port not in config.av.videomode:
70 mode = config.av.videomode[port].value
72 # some modes (720p, 1080i) are always widescreen. Don't let the user select something here, "auto" is not what he wants.
73 force_wide = self.hw.isWidescreenMode(port, mode)
76 self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspect))
78 if force_wide or config.av.aspect.value in ("16_9", "16_10"):
80 getConfigListEntry(_("Display 4:3 content as"), config.av.policy_43),
81 getConfigListEntry(_("Display >16:9 content as"), config.av.policy_169)
83 elif config.av.aspect.value == "4_3":
84 self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169))
86 # if config.av.videoport.value == "DVI":
87 # self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
88 if config.av.videoport.value == "Scart":
89 self.list.append(getConfigListEntry(_("Color Format"), config.av.colorformat))
91 self.list.append(getConfigListEntry(_("WSS on 4:3"), config.av.wss))
92 if SystemInfo["ScartSwitch"]:
93 self.list.append(getConfigListEntry(_("Auto scart switching"), config.av.vcrswitch))
96 self.list.append(getConfigListEntry(_("AC3 default"), config.av.defaultac3))
97 if SystemInfo["CanDownmixAC3"]:
98 self.list.append(getConfigListEntry(_("AC3 downmix"), config.av.downmix_ac3))
100 getConfigListEntry(_("General AC3 Delay"), config.av.generalAC3delay),
101 getConfigListEntry(_("General PCM Delay"), config.av.generalPCMdelay)
104 if SystemInfo["CanChangeOsdAlpha"]:
105 self.list.append(getConfigListEntry(_("OSD visibility"), config.av.osd_alpha))
107 if not isinstance(config.av.scaler_sharpness, ConfigNothing):
108 self.list.append(getConfigListEntry(_("Scaler sharpness"), config.av.scaler_sharpness))
110 self["config"].list = self.list
111 self["config"].l.setList(self.list)
114 ConfigListScreen.keyLeft(self)
118 ConfigListScreen.keyRight(self)
121 def confirm(self, confirmed):
123 config.av.videoport.value = self.last_good[0]
124 config.av.videomode[self.last_good[0]].value = self.last_good[1]
125 config.av.videorate[self.last_good[1]].value = self.last_good[2]
126 self.hw.setMode(*self.last_good)
130 def grabLastGoodMode(self):
131 port = config.av.videoport.value
132 mode = config.av.videomode[port].value
133 rate = config.av.videorate[mode].value
134 self.last_good = (port, mode, rate)
137 port = config.av.videoport.value
138 mode = config.av.videomode[port].value
139 rate = config.av.videorate[mode].value
140 if (port, mode, rate) != self.last_good:
141 self.hw.setMode(port, mode, rate)
142 from Screens.MessageBox import MessageBox
143 self.session.openWithCallback(self.confirm, MessageBox, _("Is this videomode ok?"), MessageBox.TYPE_YESNO, timeout = 20, default = False)
148 def changedEntry(self):
149 for x in self.onChangedEntry:
152 def getCurrentEntry(self):
153 return self["config"].getCurrent()[0]
155 def getCurrentValue(self):
156 return str(self["config"].getCurrent()[1].getText())
158 def createSummary(self):
159 from Screens.Setup import SetupSummary
162 class VideomodeHotplug:
163 def __init__(self, hw):
167 self.hw.on_hotplug.append(self.hotplug)
170 self.hw.on_hotplug.remove(self.hotplug)
172 def hotplug(self, what):
173 print "hotplug detected on port '%s'" % (what)
174 port = config.av.videoport.value
175 mode = config.av.videomode[port].value
176 rate = config.av.videorate[mode].value
178 if not self.hw.isModeAvailable(port, mode, rate):
179 print "mode %s/%s/%s went away!" % (port, mode, rate)
180 modelist = self.hw.getModeList(port)
181 if not len(modelist):
182 print "sorry, no other mode is available (unplug?). Doing nothing."
184 mode = modelist[0][0]
185 rate = modelist[0][1]
186 print "setting %s/%s/%s" % (port, mode, rate)
187 self.hw.setMode(port, mode, rate)
192 global hotplug, video_hw
193 hotplug = VideomodeHotplug(video_hw)
201 def autostart(reason, session = None, **kwargs):
202 if session is not None:
203 global my_global_session
204 my_global_session = session
212 def videoSetupMain(session, **kwargs):
213 session.open(VideoSetup, video_hw)
215 def startSetup(menuid):
216 if menuid != "system":
219 return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
221 def VideoWizard(*args, **kwargs):
222 from VideoWizard import VideoWizard
223 return VideoWizard(*args, **kwargs)
225 def Plugins(**kwargs):
227 # PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
228 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup)
230 if config.misc.videowizardenabled.value:
231 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))