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 getConfigListEntry(_("Video Output"), config.av.videoport)
59 # if we have modes for this port:
60 if config.av.videoport.value in config.av.videomode:
61 # add mode- and rate-selection:
62 self.list.append(getConfigListEntry(_("Mode"), config.av.videomode[config.av.videoport.value]))
63 if config.av.videomode[config.av.videoport.value].value == 'PC':
64 self.list.append(getConfigListEntry(_("Resolution"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
66 self.list.append(getConfigListEntry(_("Refresh Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
68 port = config.av.videoport.value
69 if port not in config.av.videomode:
72 mode = config.av.videomode[port].value
74 # some modes (720p, 1080i) are always widescreen. Don't let the user select something here, "auto" is not what he wants.
75 force_wide = self.hw.isWidescreenMode(port, mode)
78 self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspect))
80 if force_wide or config.av.aspect.value in ("16_9", "16_10"):
82 getConfigListEntry(_("Display 4:3 content as"), config.av.policy_43),
83 getConfigListEntry(_("Display >16:9 content as"), config.av.policy_169)
85 elif config.av.aspect.value == "4_3":
86 self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169))
88 # if config.av.videoport.value == "DVI":
89 # self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
90 if config.av.videoport.value == "Scart":
91 self.list.append(getConfigListEntry(_("Color Format"), config.av.colorformat))
93 self.list.append(getConfigListEntry(_("WSS on 4:3"), config.av.wss))
94 if SystemInfo["ScartSwitch"]:
95 self.list.append(getConfigListEntry(_("Auto scart switching"), config.av.vcrswitch))
98 self.list.append(getConfigListEntry(_("AC3 default"), config.av.defaultac3))
99 if SystemInfo["CanDownmixAC3"]:
100 self.list.append(getConfigListEntry(_("AC3 downmix"), config.av.downmix_ac3))
102 getConfigListEntry(_("General AC3 Delay"), config.av.generalAC3delay),
103 getConfigListEntry(_("General PCM Delay"), config.av.generalPCMdelay)
106 if SystemInfo["CanChangeOsdAlpha"]:
107 self.list.append(getConfigListEntry(_("OSD visibility"), config.av.osd_alpha))
109 self["config"].list = self.list
110 self["config"].l.setList(self.list)
113 ConfigListScreen.keyLeft(self)
117 ConfigListScreen.keyRight(self)
120 def confirm(self, confirmed):
122 config.av.videoport.value = self.last_good[0]
123 config.av.videomode[self.last_good[0]].value = self.last_good[1]
124 config.av.videorate[self.last_good[1]].value = self.last_good[2]
125 self.hw.setMode(*self.last_good)
129 def grabLastGoodMode(self):
130 port = config.av.videoport.value
131 mode = config.av.videomode[port].value
132 rate = config.av.videorate[mode].value
133 self.last_good = (port, mode, rate)
136 port = config.av.videoport.value
137 mode = config.av.videomode[port].value
138 rate = config.av.videorate[mode].value
139 if (port, mode, rate) != self.last_good:
140 self.hw.setMode(port, mode, rate)
141 from Screens.MessageBox import MessageBox
142 self.session.openWithCallback(self.confirm, MessageBox, "Is this videomode ok?", MessageBox.TYPE_YESNO, timeout = 20, default = False)
147 def changedEntry(self):
148 for x in self.onChangedEntry:
151 def getCurrentEntry(self):
152 return self["config"].getCurrent()[0]
154 def getCurrentValue(self):
155 return str(self["config"].getCurrent()[1].getText())
157 def createSummary(self):
158 from Screens.Setup import SetupSummary
161 class VideomodeHotplug:
162 def __init__(self, hw):
166 self.hw.on_hotplug.append(self.hotplug)
169 self.hw.on_hotplug.remove(self.hotplug)
171 def hotplug(self, what):
172 print "hotplug detected on port '%s'" % (what)
173 port = config.av.videoport.value
174 mode = config.av.videomode[port].value
175 rate = config.av.videorate[mode].value
177 if not self.hw.isModeAvailable(port, mode, rate):
178 print "mode %s/%s/%s went away!" % (port, mode, rate)
179 modelist = self.hw.getModeList(port)
180 if not len(modelist):
181 print "sorry, no other mode is available (unplug?). Doing nothing."
183 mode = modelist[0][0]
184 rate = modelist[0][1]
185 print "setting %s/%s/%s" % (port, mode, rate)
186 self.hw.setMode(port, mode, rate)
191 global hotplug, video_hw
192 hotplug = VideomodeHotplug(video_hw)
200 def autostart(reason, session = None, **kwargs):
201 if session is not None:
202 global my_global_session
203 my_global_session = session
211 def videoSetupMain(session, **kwargs):
212 session.open(VideoSetup, video_hw)
214 def startSetup(menuid):
215 if menuid != "system":
218 return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
220 def VideoWizard(*args, **kwargs):
221 from VideoWizard import VideoWizard
222 return VideoWizard(*args, **kwargs)
224 def Plugins(**kwargs):
226 # PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
227 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup)
229 if config.misc.videowizardenabled.value:
230 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))