Don't install *.jpg files with the Plugin metadata to save space.
[enigma2.git] / 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                         getConfigListEntry(_("Video Output"), config.av.videoport)
57                 ]
58
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]))
65                         else:
66                                 self.list.append(getConfigListEntry(_("Refresh Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
67
68                 port = config.av.videoport.value
69                 if port not in config.av.videomode:
70                         mode = None
71                 else:
72                         mode = config.av.videomode[port].value
73
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)
76
77                 if not force_wide:
78                         self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspect))
79
80                 if force_wide or config.av.aspect.value in ("16_9", "16_10"):
81                         self.list.extend((
82                                 getConfigListEntry(_("Display 4:3 content as"), config.av.policy_43),
83                                 getConfigListEntry(_("Display >16:9 content as"), config.av.policy_169)
84                         ))
85                 elif config.av.aspect.value == "4_3":
86                         self.list.append(getConfigListEntry(_("Display 16:9 content as"), config.av.policy_169))
87
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))
92                         if level >= 1:
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))
96
97                 if level >= 1:
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))
101                         self.list.extend((
102                                 getConfigListEntry(_("General AC3 Delay"), config.av.generalAC3delay),
103                                 getConfigListEntry(_("General PCM Delay"), config.av.generalPCMdelay)
104                         ))
105
106                 if SystemInfo["CanChangeOsdAlpha"]:
107                         self.list.append(getConfigListEntry(_("OSD visibility"), config.av.osd_alpha))
108
109                 self["config"].list = self.list
110                 self["config"].l.setList(self.list)
111
112         def keyLeft(self):
113                 ConfigListScreen.keyLeft(self)
114                 self.createSetup()
115
116         def keyRight(self):
117                 ConfigListScreen.keyRight(self)
118                 self.createSetup()
119
120         def confirm(self, confirmed):
121                 if not 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)
126                 else:
127                         self.keySave()
128
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)
134
135         def apply(self):
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)
143                 else:
144                         self.keySave()
145
146         # for summary:
147         def changedEntry(self):
148                 for x in self.onChangedEntry:
149                         x()
150
151         def getCurrentEntry(self):
152                 return self["config"].getCurrent()[0]
153
154         def getCurrentValue(self):
155                 return str(self["config"].getCurrent()[1].getText())
156
157         def createSummary(self):
158                 from Screens.Setup import SetupSummary
159                 return SetupSummary
160
161 class VideomodeHotplug:
162         def __init__(self, hw):
163                 self.hw = hw
164
165         def start(self):
166                 self.hw.on_hotplug.append(self.hotplug)
167
168         def stop(self):
169                 self.hw.on_hotplug.remove(self.hotplug)
170
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
176
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."
182                                 return
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)
187
188 hotplug = None
189
190 def startHotplug():
191         global hotplug, video_hw
192         hotplug = VideomodeHotplug(video_hw)
193         hotplug.start()
194
195 def stopHotplug():
196         global hotplug
197         hotplug.stop()
198
199
200 def autostart(reason, session = None, **kwargs):
201         if session is not None:
202                 global my_global_session
203                 my_global_session = session
204                 return
205
206         if reason == 0:
207                 startHotplug()
208         elif reason == 1:
209                 stopHotplug()
210
211 def videoSetupMain(session, **kwargs):
212         session.open(VideoSetup, video_hw)
213
214 def startSetup(menuid):
215         if menuid != "system": 
216                 return [ ]
217
218         return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
219
220 def VideoWizard(*args, **kwargs):
221         from VideoWizard import VideoWizard
222         return VideoWizard(*args, **kwargs)
223
224 def Plugins(**kwargs):
225         list = [
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) 
228         ]
229         if config.misc.videowizardenabled.value:
230                 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))
231         return list