add videowizard
[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, ConfigNothing, ConfigSelection, ConfigSubDict
13 from VideoWizard import VideoWizard
14 from Components.config import config
15
16 from Tools.CList import CList
17
18 from VideoHardware import video_hw
19
20 class VideoSetup(Screen, ConfigListScreen):
21         def __init__(self, session, hw):
22                 Screen.__init__(self, session)
23                 self.skinName = "Setup"
24                 self.setup_title = "Videomode Setup"
25                 self.hw = hw
26                 self.onChangedEntry = [ ]
27
28                 # handle hotplug by re-creating setup
29                 self.onShow.append(self.startHotplug)
30                 self.onHide.append(self.stopHotplug)
31
32                 self.list = [ ]
33                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
34
35                 self["actions"] = ActionMap(["SetupActions"], 
36                         {
37                                 "cancel": self.keyCancel,
38                                 "save": self.apply,
39                         }, -2)
40
41                 self["title"] = Label(_("Video-Setup"))
42
43                 self["oktext"] = Label(_("OK"))
44                 self["canceltext"] = Label(_("Cancel"))
45                 self["ok"] = Pixmap()
46                 self["cancel"] = Pixmap()
47
48                 self.createSetup()
49                 self.grabLastGoodMode()
50
51         def startHotplug(self):
52                 self.hw.on_hotplug.append(self.createSetup)
53
54         def stopHotplug(self):
55                 self.hw.on_hotplug.remove(self.createSetup)
56
57         def createSetup(self):
58                 self.list = [ ]
59                 self.list.append(getConfigListEntry(_("Output Type"), 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(_("Rate"), config.av.videorate[config.av.videomode[config.av.videoport.value].value]))
66
67                 self["config"].list = self.list
68                 self["config"].l.setList(self.list)
69
70         def keyLeft(self):
71                 ConfigListScreen.keyLeft(self)
72                 self.createSetup()
73
74         def keyRight(self):
75                 ConfigListScreen.keyRight(self)
76                 self.createSetup()
77
78         def confirm(self, confirmed):
79                 if not confirmed:
80                         self.hw.setMode(*self.last_good)
81                 else:
82                         self.keySave()
83
84         def grabLastGoodMode(self):
85                 port = config.av.videoport.value
86                 mode = config.av.videomode[port].value
87                 rate = config.av.videorate[mode].value
88                 self.last_good = (port, mode, rate)
89
90         def apply(self):
91                 port = config.av.videoport.value
92                 mode = config.av.videomode[port].value
93                 rate = config.av.videorate[mode].value
94                 if (port, mode, rate) != self.last_good or True:
95                         self.hw.setMode(port, mode, rate)
96                         self.session.openWithCallback(self.confirm, MessageBox, "Is this videomode ok?", MessageBox.TYPE_YESNO, timeout = 5, default = False)
97                 else:
98                         self.keySave()
99
100         # for summary:
101         def changedEntry(self):
102                 for x in self.onChangedEntry:
103                         x()
104
105         def getCurrentEntry(self):
106                 return self["config"].getCurrent()[0]
107
108         def getCurrentValue(self):
109                 return str(self["config"].getCurrent()[1].getText())
110
111         def createSummary(self):
112                 return SetupSummary
113
114 #class VideomodeHotplug:
115 #       def __init__(self, hw):
116 #               self.hw = hw
117 #               self.hw.on_hotplug.append(self.hotplug)
118 #
119 #       def hotplug(self, what):
120 #               print "hotplug detected on port '%s'" % (what)
121 # ...
122 #
123 #hotplug = None
124 #
125 #def startHotplug(self):
126 #       global hotplug
127 #       hotplug = VideomodeHotplug()
128 #       hotplug.start()
129 #
130 #def stopHotplug(self):
131 #       global hotplug
132 #       hotplug.stop()
133 #
134 #
135 #def autostart(reason, session = None, **kwargs):
136 #       if session is not None:
137 #               global my_global_session
138 #               my_global_session = session
139 #               return
140 #
141 #       if reason == 0:
142 #               startHotplug()
143 #       elif reason == 1:
144 #               stopHotplug()
145
146 def videoSetupMain(session, **kwargs):
147         session.open(VideoSetup, video_hw)
148
149 def startSetup(menuid):
150         if menuid != "system": 
151                 return [ ]
152
153         return [(_("Video Setup"), videoSetupMain, "video_setup", None)]
154
155 def Plugins(**kwargs):
156         list = []
157         list.append(PluginDescriptor(name=_("Video Setup"), description=_("Advanced Video Setup"), where = PluginDescriptor.WHERE_MENU, fnc=startSetup))
158         if config.misc.firstrun.value:
159                 list.append(PluginDescriptor(name=_("Video Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=VideoWizard))
160         return list