b51cc08d83372f22aeeb8896e2cd9826fd9eabe9
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Videomode / plugin.py
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
6
7 from VideoHardware import video_hw
8
9 config.misc.videowizardenabled = ConfigBoolean(default = True)
10
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"
16                 self.hw = hw
17                 self.onChangedEntry = [ ]
18
19                 # handle hotplug by re-creating setup
20                 self.onShow.append(self.startHotplug)
21                 self.onHide.append(self.stopHotplug)
22
23                 self.list = [ ]
24                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
25
26                 from Components.ActionMap import ActionMap
27                 self["actions"] = ActionMap(["SetupActions"], 
28                         {
29                                 "cancel": self.keyCancel,
30                                 "save": self.apply,
31                         }, -2)
32
33                 from Components.Label import Label
34                 self["title"] = Label(_("A/V Settings"))
35
36                 self["oktext"] = Label(_("OK"))
37                 self["canceltext"] = Label(_("Cancel"))
38
39                 from Components.Pixmap import Pixmap
40                 self["ok"] = Pixmap()
41                 self["cancel"] = Pixmap()
42
43                 self.createSetup()
44                 self.grabLastGoodMode()
45
46         def startHotplug(self):
47                 self.hw.on_hotplug.append(self.createSetup)
48
49         def stopHotplug(self):
50                 self.hw.on_hotplug.remove(self.createSetup)
51
52         def createSetup(self):
53                 level = config.usage.setup_level.index
54
55                 self.list = [ ]
56                 self.list.append(getConfigListEntry(_("Video Output"), config.av.videoport))
57
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]))
64                         else:
65                                 self.list.append(getConfigListEntry(_("Refresh Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
66
67                 port = config.av.videoport.value
68                 if port not in config.av.videomode:
69                         mode = None
70                 else:
71                         mode = config.av.videomode[port].value
72
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)
75
76                 if not force_wide:
77                         self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspect))
78
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))
83
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))
88                         if level >= 1:
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))
92
93                 if level >= 1:
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))
97
98                 self["config"].list = self.list
99                 self["config"].l.setList(self.list)
100
101         def keyLeft(self):
102                 ConfigListScreen.keyLeft(self)
103                 self.createSetup()
104
105         def keyRight(self):
106                 ConfigListScreen.keyRight(self)
107                 self.createSetup()
108
109         def confirm(self, confirmed):
110                 if not confirmed:
111                         config.av.videoport.value = self.last_good[0]
112                         config.av.videomode[self.last_good[0]].value = self.last_good[1]
113                         config.av.videorate[self.last_good[1]].value = self.last_good[2]
114                         self.hw.setMode(*self.last_good)
115                 else:
116                         self.keySave()
117
118         def grabLastGoodMode(self):
119                 port = config.av.videoport.value
120                 mode = config.av.videomode[port].value
121                 rate = config.av.videorate[mode].value
122                 self.last_good = (port, mode, rate)
123
124         def apply(self):
125                 port = config.av.videoport.value
126                 mode = config.av.videomode[port].value
127                 rate =config.av.videorate[mode].value
128                 if (port, mode, rate) != self.last_good:
129                         config.av.videoport.value = self.last_good[0]
130                         config.av.videomode[port].value = self.last_good[1]
131                         config.av.videorate[mode].value = self.last_good[2]
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)
135                 else:
136                         self.keySave()
137
138         # for summary:
139         def changedEntry(self):
140                 for x in self.onChangedEntry:
141                         x()
142
143         def getCurrentEntry(self):
144                 return self["config"].getCurrent()[0]
145
146         def getCurrentValue(self):
147                 return str(self["config"].getCurrent()[1].getText())
148
149         def createSummary(self):
150                 from Screens.Setup import SetupSummary
151                 return SetupSummary
152
153 class VideomodeHotplug:
154         def __init__(self, hw):
155                 self.hw = hw
156
157         def start(self):
158                 self.hw.on_hotplug.append(self.hotplug)
159
160         def stop(self):
161                 self.hw.on_hotplug.remove(self.hotplug)
162
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
168
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."
174                                 return
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)
179
180 hotplug = None
181
182 def startHotplug():
183         global hotplug, video_hw
184         hotplug = VideomodeHotplug(video_hw)
185         hotplug.start()
186
187 def stopHotplug():
188         global hotplug
189         hotplug.stop()
190
191
192 def autostart(reason, session = None, **kwargs):
193         if session is not None:
194                 global my_global_session
195                 my_global_session = session
196                 return
197
198         if reason == 0:
199                 startHotplug()
200         elif reason == 1:
201                 stopHotplug()
202
203 def videoSetupMain(session, **kwargs):
204         session.open(VideoSetup, video_hw)
205
206 def startSetup(menuid):
207         if menuid != "system": 
208                 return [ ]
209
210         return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
211
212 def VideoWizard(*args, **kwargs):
213         from VideoWizard import VideoWizard
214         return VideoWizard(*args, **kwargs)
215
216 def Plugins(**kwargs):
217         list = [
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) 
220         ]
221         if config.misc.videowizardenabled.value:
222                 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))
223         return list