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 self.list.append(getConfigListEntry(_("Display >16:9 content as"), config.av.policy_169))
82 elif config.av.aspect.value == "4_3":
83 self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169))
85 # if config.av.videoport.value == "DVI":
86 # self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
87 if config.av.videoport.value == "Scart":
88 self.list.append(getConfigListEntry(_("Color Format"), config.av.colorformat))
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))
95 self.list.append(getConfigListEntry(_("AC3 default"), config.av.defaultac3))
96 if SystemInfo["CanDownmixAC3"]:
97 self.list.append(getConfigListEntry(_("AC3 downmix"), config.av.downmix_ac3))
99 if SystemInfo["CanChangeOsdAlpha"]:
100 self.list.append(getConfigListEntry(_("OSD visibility"), config.av.osd_alpha))
102 self["config"].list = self.list
103 self["config"].l.setList(self.list)
106 ConfigListScreen.keyLeft(self)
110 ConfigListScreen.keyRight(self)
113 def confirm(self, confirmed):
115 config.av.videoport.value = self.last_good[0]
116 config.av.videomode[self.last_good[0]].value = self.last_good[1]
117 config.av.videorate[self.last_good[1]].value = self.last_good[2]
118 self.hw.setMode(*self.last_good)
122 def grabLastGoodMode(self):
123 port = config.av.videoport.value
124 mode = config.av.videomode[port].value
125 rate = config.av.videorate[mode].value
126 self.last_good = (port, mode, rate)
129 port = config.av.videoport.value
130 mode = config.av.videomode[port].value
131 rate = config.av.videorate[mode].value
132 if (port, mode, rate) != self.last_good:
133 self.hw.setMode(port, mode, rate)
134 from Screens.MessageBox import MessageBox
135 self.session.openWithCallback(self.confirm, MessageBox, "Is this videomode ok?", MessageBox.TYPE_YESNO, timeout = 20, default = False)
140 def changedEntry(self):
141 for x in self.onChangedEntry:
144 def getCurrentEntry(self):
145 return self["config"].getCurrent()[0]
147 def getCurrentValue(self):
148 return str(self["config"].getCurrent()[1].getText())
150 def createSummary(self):
151 from Screens.Setup import SetupSummary
154 class VideomodeHotplug:
155 def __init__(self, hw):
159 self.hw.on_hotplug.append(self.hotplug)
162 self.hw.on_hotplug.remove(self.hotplug)
164 def hotplug(self, what):
165 print "hotplug detected on port '%s'" % (what)
166 port = config.av.videoport.value
167 mode = config.av.videomode[port].value
168 rate = config.av.videorate[mode].value
170 if not self.hw.isModeAvailable(port, mode, rate):
171 print "mode %s/%s/%s went away!" % (port, mode, rate)
172 modelist = self.hw.getModeList(port)
173 if not len(modelist):
174 print "sorry, no other mode is available (unplug?). Doing nothing."
176 mode = modelist[0][0]
177 rate = modelist[0][1]
178 print "setting %s/%s/%s" % (port, mode, rate)
179 self.hw.setMode(port, mode, rate)
184 global hotplug, video_hw
185 hotplug = VideomodeHotplug(video_hw)
193 def autostart(reason, session = None, **kwargs):
194 if session is not None:
195 global my_global_session
196 my_global_session = session
204 def videoSetupMain(session, **kwargs):
205 session.open(VideoSetup, video_hw)
207 def startSetup(menuid):
208 if menuid != "system":
211 return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
213 def VideoWizard(*args, **kwargs):
214 from VideoWizard import VideoWizard
215 return VideoWizard(*args, **kwargs)
217 def Plugins(**kwargs):
219 # PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
220 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup)
222 if config.misc.videowizardenabled.value:
223 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))