1 from Screens.Screen import Screen
2 from Plugins.Plugin import PluginDescriptor
4 from enigma import eTimer
6 from Components.ActionMap import ActionMap
7 from Components.Label import Label
8 from Components.Pixmap import Pixmap
9 from Screens.MessageBox import MessageBox
10 from Screens.Setup import SetupSummary
11 from Components.ConfigList import ConfigListScreen
12 from Components.config import getConfigListEntry, config
13 from VideoWizard import VideoWizard
14 from Components.config import config
16 from VideoHardware import video_hw
18 class VideoSetup(Screen, ConfigListScreen):
19 def __init__(self, session, hw):
20 Screen.__init__(self, session)
21 self.skinName = "Setup"
22 self.setup_title = "Videomode Setup"
24 self.onChangedEntry = [ ]
26 # handle hotplug by re-creating setup
27 self.onShow.append(self.startHotplug)
28 self.onHide.append(self.stopHotplug)
31 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
33 self["actions"] = ActionMap(["SetupActions"],
35 "cancel": self.keyCancel,
39 self["title"] = Label(_("Video-Setup"))
41 self["oktext"] = Label(_("OK"))
42 self["canceltext"] = Label(_("Cancel"))
44 self["cancel"] = Pixmap()
47 self.grabLastGoodMode()
49 def startHotplug(self):
50 self.hw.on_hotplug.append(self.createSetup)
52 def stopHotplug(self):
53 self.hw.on_hotplug.remove(self.createSetup)
55 def createSetup(self):
57 self.list.append(getConfigListEntry(_("Output Type"), 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 self.list.append(getConfigListEntry(_("Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
65 # if config.av.videoport.value == "DVI":
66 # self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
68 self["config"].list = self.list
69 self["config"].l.setList(self.list)
72 ConfigListScreen.keyLeft(self)
76 ConfigListScreen.keyRight(self)
79 def confirm(self, confirmed):
81 self.hw.setMode(*self.last_good)
85 def grabLastGoodMode(self):
86 port = config.av.videoport.value
87 mode = config.av.videomode[port].value
88 rate = config.av.videorate[mode].value
89 self.last_good = (port, mode, rate)
92 port = config.av.videoport.value
93 mode = config.av.videomode[port].value
94 rate = config.av.videorate[mode].value
95 if (port, mode, rate) != self.last_good or True:
96 self.hw.setMode(port, mode, rate)
97 self.session.openWithCallback(self.confirm, MessageBox, "Is this videomode ok?", MessageBox.TYPE_YESNO, timeout = 20, default = False)
102 def changedEntry(self):
103 for x in self.onChangedEntry:
106 def getCurrentEntry(self):
107 return self["config"].getCurrent()[0]
109 def getCurrentValue(self):
110 return str(self["config"].getCurrent()[1].getText())
112 def createSummary(self):
115 class VideomodeHotplug:
116 def __init__(self, hw):
120 self.hw.on_hotplug.append(self.hotplug)
123 self.hw.on_hotplug.remove(self.hotplug)
125 def hotplug(self, what):
126 print "hotplug detected on port '%s'" % (what)
127 port = config.av.videoport.value
128 mode = config.av.videomode[port].value
129 rate = config.av.videorate[mode].value
131 if not self.hw.isModeAvailable(port, mode, rate):
132 print "mode %s/%s/%s went away!" % (port, mode, rate)
133 modelist = self.hw.getModeList(port)
134 if not len(modelist):
135 print "sorry, no other mode is available (unplug?). Doing nothing."
137 mode = modelist[0][0]
138 rate = modelist[0][1]
139 print "setting %s/%s/%s" % (port, mode, rate)
140 self.hw.setMode(port, mode, rate)
145 global hotplug, video_hw
146 hotplug = VideomodeHotplug(video_hw)
154 def autostart(reason, session = None, **kwargs):
155 if session is not None:
156 global my_global_session
157 my_global_session = session
165 def videoSetupMain(session, **kwargs):
166 session.open(VideoSetup, video_hw)
168 def startSetup(menuid):
169 if menuid != "system":
172 return [(_("Video Setup"), videoSetupMain, "video_setup", None)]
174 def Plugins(**kwargs):
176 # PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
177 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup)
179 if config.misc.firstrun.value:
180 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=VideoWizard))