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
7 from VideoHardware import video_hw
9 config.misc.videowizardenabled = ConfigBoolean(default = True)
11 class VideoSetup(Screen, ConfigListScreen):
12 def __init__(self, session, hw):
13 Screen.__init__(self, session)
14 self.skinName = "Setup"
15 self.setup_title = "Videomode Setup"
17 self.onChangedEntry = [ ]
19 # handle hotplug by re-creating setup
20 self.onShow.append(self.startHotplug)
21 self.onHide.append(self.stopHotplug)
24 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
26 from Components.ActionMap import ActionMap
27 self["actions"] = ActionMap(["SetupActions"],
29 "cancel": self.keyCancel,
33 from Components.Label import Label
34 self["title"] = Label(_("A/V Settings"))
36 self["oktext"] = Label(_("OK"))
37 self["canceltext"] = Label(_("Cancel"))
39 from Components.Pixmap import Pixmap
41 self["cancel"] = Pixmap()
44 self.grabLastGoodMode()
46 def startHotplug(self):
47 self.hw.on_hotplug.append(self.createSetup)
49 def stopHotplug(self):
50 self.hw.on_hotplug.remove(self.createSetup)
52 def createSetup(self):
53 level = config.usage.setup_level.index
56 self.list.append(getConfigListEntry(_("Video Output"), config.av.videoport))
58 # if we have modes for this port:
59 if config.av.videoport.value in config.av.videomode:
60 # add mode- and rate-selection:
61 self.list.append(getConfigListEntry(_("Mode"), config.av.videomode[config.av.videoport.value]))
62 if config.av.videomode[config.av.videoport.value].value == 'PC':
63 self.list.append(getConfigListEntry(_("Resolution"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
65 self.list.append(getConfigListEntry(_("Refresh Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
67 port = config.av.videoport.value
68 if port not in config.av.videomode:
71 mode = config.av.videomode[port].value
73 # some modes (720p, 1080i) are always widescreen. Don't let the user select something here, "auto" is not what he wants.
74 force_wide = self.hw.isWidescreenMode(port, mode)
77 self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspect))
79 if force_wide or config.av.aspect.value in ["16_9", "16_10"]:
80 self.list.append(getConfigListEntry(_("Display 4:3 content as"), config.av.policy_43))
81 elif config.av.aspect.value == "4_3":
82 self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169))
84 # if config.av.videoport.value == "DVI":
85 # self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
86 if config.av.videoport.value == "Scart":
87 self.list.append(getConfigListEntry(_("Color Format"), config.av.colorformat))
89 self.list.append(getConfigListEntry(_("WSS on 4:3"), config.av.wss))
90 if SystemInfo["ScartSwitch"]:
91 self.list.append(getConfigListEntry(_("Auto scart switching"), config.av.vcrswitch))
94 self.list.append(getConfigListEntry(_("AC3 default"), config.av.defaultac3))
95 if SystemInfo["CanDownmixAC3"]:
96 self.list.append(getConfigListEntry(_("AC3 downmix"), config.av.downmix_ac3))
98 if SystemInfo["CanChangeOsdAlpha"]:
99 self.list.append(getConfigListEntry(_("OSD visibility"), config.av.osd_alpha))
101 self["config"].list = self.list
102 self["config"].l.setList(self.list)
105 ConfigListScreen.keyLeft(self)
109 ConfigListScreen.keyRight(self)
112 def confirm(self, confirmed):
114 config.av.videoport.value = self.last_good[0]
115 config.av.videomode[self.last_good[0]].value = self.last_good[1]
116 config.av.videorate[self.last_good[1]].value = self.last_good[2]
117 self.hw.setMode(*self.last_good)
121 def grabLastGoodMode(self):
122 port = config.av.videoport.value
123 mode = config.av.videomode[port].value
124 rate = config.av.videorate[mode].value
125 self.last_good = (port, mode, rate)
128 port = config.av.videoport.value
129 mode = config.av.videomode[port].value
130 rate = config.av.videorate[mode].value
131 if (port, mode, rate) != self.last_good:
132 self.hw.setMode(port, mode, rate)
133 from Screens.MessageBox import MessageBox
134 self.session.openWithCallback(self.confirm, MessageBox, "Is this videomode ok?", MessageBox.TYPE_YESNO, timeout = 20, default = False)
139 def changedEntry(self):
140 for x in self.onChangedEntry:
143 def getCurrentEntry(self):
144 return self["config"].getCurrent()[0]
146 def getCurrentValue(self):
147 return str(self["config"].getCurrent()[1].getText())
149 def createSummary(self):
150 from Screens.Setup import SetupSummary
153 class VideomodeHotplug:
154 def __init__(self, hw):
158 self.hw.on_hotplug.append(self.hotplug)
161 self.hw.on_hotplug.remove(self.hotplug)
163 def hotplug(self, what):
164 print "hotplug detected on port '%s'" % (what)
165 port = config.av.videoport.value
166 mode = config.av.videomode[port].value
167 rate = config.av.videorate[mode].value
169 if not self.hw.isModeAvailable(port, mode, rate):
170 print "mode %s/%s/%s went away!" % (port, mode, rate)
171 modelist = self.hw.getModeList(port)
172 if not len(modelist):
173 print "sorry, no other mode is available (unplug?). Doing nothing."
175 mode = modelist[0][0]
176 rate = modelist[0][1]
177 print "setting %s/%s/%s" % (port, mode, rate)
178 self.hw.setMode(port, mode, rate)
183 global hotplug, video_hw
184 hotplug = VideomodeHotplug(video_hw)
192 def autostart(reason, session = None, **kwargs):
193 if session is not None:
194 global my_global_session
195 my_global_session = session
203 def videoSetupMain(session, **kwargs):
204 session.open(VideoSetup, video_hw)
206 def startSetup(menuid):
207 if menuid != "system":
210 return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
212 def VideoWizard(*args, **kwargs):
213 from VideoWizard import VideoWizard
214 return VideoWizard(*args, **kwargs)
216 def Plugins(**kwargs):
218 # PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
219 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup)
221 if config.misc.videowizardenabled.value:
222 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))