b5e12c2e27c2a321f10617ba8b7ac3b6b1c219f0
[enigma2.git] / lib / python / Plugins / SystemPlugins / Videomode / plugin.py
1 from Screens.Screen import Screen
2 from Plugins.Plugin import PluginDescriptor
3
4 from enigma import eTimer
5
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
15
16 from VideoHardware import video_hw
17
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"
23                 self.hw = hw
24                 self.onChangedEntry = [ ]
25
26                 # handle hotplug by re-creating setup
27                 self.onShow.append(self.startHotplug)
28                 self.onHide.append(self.stopHotplug)
29
30                 self.list = [ ]
31                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
32
33                 self["actions"] = ActionMap(["SetupActions"], 
34                         {
35                                 "cancel": self.keyCancel,
36                                 "save": self.apply,
37                         }, -2)
38
39                 self["title"] = Label(_("A/V Settings"))
40
41                 self["oktext"] = Label(_("OK"))
42                 self["canceltext"] = Label(_("Cancel"))
43                 self["ok"] = Pixmap()
44                 self["cancel"] = Pixmap()
45
46                 self.createSetup()
47                 self.grabLastGoodMode()
48
49         def startHotplug(self):
50                 self.hw.on_hotplug.append(self.createSetup)
51
52         def stopHotplug(self):
53                 self.hw.on_hotplug.remove(self.createSetup)
54
55         def createSetup(self):
56                 level = config.usage.setup_level.index
57
58                 self.list = [ ]
59                 self.list.append(getConfigListEntry(_("Video Output"), config.av.videoport))
60
61                 # if we have modes for this port:
62                 if config.av.videoport.value in config.av.videomode:
63                         # add mode- and rate-selection:
64                         self.list.append(getConfigListEntry(_("Mode"), config.av.videomode[config.av.videoport.value]))
65                         self.list.append(getConfigListEntry(_("Refresh Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
66
67 #               if config.av.videoport.value == "DVI":
68 #                       self.list.append(getConfigListEntry(_("Allow Unsupported Modes"), config.av.edid_override))
69                 if config.av.videoport.value == "Scart":
70                         self.list.append(getConfigListEntry(_("Color Format"), config.av.colorformat))
71                         self.list.append(getConfigListEntry(_("Aspect Ratio"), config.av.aspectratio))
72                         if level >= 1:
73                                 self.list.append(getConfigListEntry(_("WSS on 4:3"), config.av.wss))
74
75                 if level >= 1:
76                         self.list.append(getConfigListEntry(_("AC3 default"), config.av.defaultac3))
77
78                 self["config"].list = self.list
79                 self["config"].l.setList(self.list)
80
81         def keyLeft(self):
82                 ConfigListScreen.keyLeft(self)
83                 self.createSetup()
84
85         def keyRight(self):
86                 ConfigListScreen.keyRight(self)
87                 self.createSetup()
88
89         def confirm(self, confirmed):
90                 if not confirmed:
91                         self.hw.setMode(*self.last_good)
92                 else:
93                         self.keySave()
94
95         def grabLastGoodMode(self):
96                 port = config.av.videoport.value
97                 mode = config.av.videomode[port].value
98                 rate = config.av.videorate[mode].value
99                 self.last_good = (port, mode, rate)
100
101         def apply(self):
102                 port = config.av.videoport.value
103                 mode = config.av.videomode[port].value
104                 rate = config.av.videorate[mode].value
105                 if (port, mode, rate) != self.last_good:
106                         self.hw.setMode(port, mode, rate)
107                         self.session.openWithCallback(self.confirm, MessageBox, "Is this videomode ok?", MessageBox.TYPE_YESNO, timeout = 20, default = False)
108                 else:
109                         self.keySave()
110
111         # for summary:
112         def changedEntry(self):
113                 for x in self.onChangedEntry:
114                         x()
115
116         def getCurrentEntry(self):
117                 return self["config"].getCurrent()[0]
118
119         def getCurrentValue(self):
120                 return str(self["config"].getCurrent()[1].getText())
121
122         def createSummary(self):
123                 return SetupSummary
124
125 class VideomodeHotplug:
126         def __init__(self, hw):
127                 self.hw = hw
128
129         def start(self):
130                 self.hw.on_hotplug.append(self.hotplug)
131
132         def stop(self):
133                 self.hw.on_hotplug.remove(self.hotplug)
134
135         def hotplug(self, what):
136                 print "hotplug detected on port '%s'" % (what)
137                 port = config.av.videoport.value
138                 mode = config.av.videomode[port].value
139                 rate = config.av.videorate[mode].value
140
141                 if not self.hw.isModeAvailable(port, mode, rate):
142                         print "mode %s/%s/%s went away!" % (port, mode, rate)
143                         modelist = self.hw.getModeList(port)
144                         if not len(modelist):
145                                 print "sorry, no other mode is available (unplug?). Doing nothing."
146                                 return
147                         mode = modelist[0][0]
148                         rate = modelist[0][1]
149                         print "setting %s/%s/%s" % (port, mode, rate)
150                         self.hw.setMode(port, mode, rate)
151
152 hotplug = None
153
154 def startHotplug():
155         global hotplug, video_hw
156         hotplug = VideomodeHotplug(video_hw)
157         hotplug.start()
158
159 def stopHotplug():
160         global hotplug
161         hotplug.stop()
162
163
164 def autostart(reason, session = None, **kwargs):
165         if session is not None:
166                 global my_global_session
167                 my_global_session = session
168                 return
169
170         if reason == 0:
171                 startHotplug()
172         elif reason == 1:
173                 stopHotplug()
174
175 def videoSetupMain(session, **kwargs):
176         session.open(VideoSetup, video_hw)
177
178 def startSetup(menuid):
179         if menuid != "system": 
180                 return [ ]
181
182         return [(_("A/V Settings") + "...", videoSetupMain, "av_setup", 40)]
183
184 def Plugins(**kwargs):
185         list = [
186 #               PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART], fnc = autostart),
187                 PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup) 
188         ]
189         if config.misc.firstrun.value:
190                 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(0, VideoWizard)))
191         return list