Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / python / Plugins / SystemPlugins / Videomode / VideoWizard.py
1 from Screens.Wizard import WizardSummary
2 from Screens.WizardLanguage import WizardLanguage
3 from Screens.Rc import Rc
4 from VideoHardware import video_hw
5
6 from Components.Pixmap import Pixmap, MovingPixmap, MultiPixmap
7 from Components.config import config, ConfigBoolean, configfile
8
9 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
10 from Tools.HardwareInfo import HardwareInfo
11
12 config.misc.showtestcard = ConfigBoolean(default = False)
13
14 class VideoWizardSummary(WizardSummary):
15         skin = """
16         <screen position="0,0" size="132,64">
17                 <widget name="text" position="6,4" size="120,40" font="Regular;12" transparent="1" />
18                 <widget source="parent.list" render="Label" position="6,40" size="120,21" font="Regular;14">
19                         <convert type="StringListSelection" />
20                 </widget>
21                 <!--widget name="pic" pixmap="%s" position="6,22" zPosition="10" size="64,64" transparent="1" alphatest="on"/-->
22         </screen>""" #% (resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/lcd_Scart.png"))
23         
24         def __init__(self, session, parent):
25                 WizardSummary.__init__(self, session, parent)
26                 #self["pic"] = Pixmap()
27                 
28         def setLCDPicCallback(self):
29                 self.parent.setLCDTextCallback(self.setText)
30                 
31         def setLCDPic(self, file):
32                 self["pic"].instance.setPixmapFromFile(file)
33
34 class VideoWizard(WizardLanguage, Rc):
35         skin = """
36                 <screen position="0,0" size="720,576" title="Welcome..." flags="wfNoBorder" >
37                         <widget name="text" position="153,50" size="340,270" font="Regular;23" />
38                         <widget source="list" render="Listbox" position="200,300" size="290,200" scrollbarMode="showOnDemand" >
39                                 <convert type="StringList" />
40                         </widget>
41                         <widget name="config" position="50,300" zPosition="1" size="440,200" transparent="1" scrollbarMode="showOnDemand" />
42                         <widget name="wizard" pixmap="skin_default/wizard.png" position="40,50" zPosition="10" size="110,174" transparent="1" alphatest="on"/>
43                         <ePixmap pixmap="skin_default/buttons/button_red.png" position="40,225" zPosition="0" size="15,16" transparent="1" alphatest="on" />
44                         <widget name="languagetext" position="55,225" size="95,30" font="Regular;18" />
45                         <widget name="portpic" pixmap="%s" position="50,300" zPosition="10" size="150,150" transparent="1" alphatest="on"/>
46                         <widget name="rc" pixmaps="skin_default/rc.png,skin_default/rcold.png" position="500,50" zPosition="10" size="154,500" transparent="1" alphatest="on"/>
47                         <widget name="arrowdown" pixmap="skin_default/arrowdown.png" position="0,0" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
48                         <widget name="arrowdown2" pixmap="skin_default/arrowdown.png" position="0,0" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
49                         <widget name="arrowup" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
50                         <widget name="arrowup2" pixmap="skin_default/arrowup.png" position="-100,-100" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
51                 </screen>""" % (resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/Scart.png"))
52         
53         def __init__(self, session):
54                 # FIXME anyone knows how to use relative paths from the plugin's directory?
55                 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/videowizard.xml")
56                 self.hw = video_hw
57                 
58                 WizardLanguage.__init__(self, session, showSteps = False, showStepSlider = False)
59                 Rc.__init__(self)
60                 self["wizard"] = Pixmap()
61                 self["portpic"] = Pixmap()
62                 
63                 self.port = None
64                 self.mode = None
65                 self.rate = None
66                 
67                 
68         def createSummary(self):
69                 print "++++++++++++***++**** VideoWizard-createSummary"
70                 from Screens.Wizard import WizardSummary
71                 return VideoWizardSummary
72                 
73         def markDone(self):
74                 config.misc.videowizardenabled.value = 0
75                 config.misc.videowizardenabled.save()
76                 configfile.save()
77         
78         def listInputChannels(self):
79                 hw_type = HardwareInfo().get_device_name()
80                 list = []
81
82                 for port in self.hw.getPortList():
83                         if self.hw.isPortUsed(port):
84                                 descr = port
85                                 if descr == 'DVI' and hw_type == 'dm500hd':
86                                         descr = 'HDMI'
87                                 list.append((descr,port))
88                 list.sort(key = lambda x: x[0])
89                 print "listInputChannels:", list
90                 return list
91
92         def inputSelectionMade(self, index):
93                 print "inputSelectionMade:", index
94                 self.port = index
95                 self.inputSelect(index)
96                 
97         def inputSelectionMoved(self):
98                 print "input selection moved:", self.selection
99                 self.inputSelect(self.selection)
100                 if self["portpic"].instance is not None:
101                         self["portpic"].instance.setPixmapFromFile(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/" + self.selection + ".png"))
102                 
103         def inputSelect(self, port):
104                 print "inputSelect:", port
105                 modeList = self.hw.getModeList(self.selection)
106                 print "modeList:", modeList
107                 self.port = port
108                 if (len(modeList) > 0):
109                         ratesList = self.listRates(modeList[0][0])
110                         self.hw.setMode(port = port, mode = modeList[0][0], rate = ratesList[0][0])
111                 
112         def listModes(self):
113                 list = []
114                 print "modes for port", self.port
115                 for mode in self.hw.getModeList(self.port):
116                         #if mode[0] != "PC":
117                                 list.append((mode[0], mode[0]))
118                 print "modeslist:", list
119                 return list
120         
121         def modeSelectionMade(self, index):
122                 print "modeSelectionMade:", index
123                 self.mode = index
124                 self.modeSelect(index)
125                 
126         def modeSelectionMoved(self):
127                 print "mode selection moved:", self.selection
128                 self.modeSelect(self.selection)
129                 
130         def modeSelect(self, mode):
131                 ratesList = self.listRates(mode)
132                 print "ratesList:", ratesList
133                 self.hw.setMode(port = self.port, mode = mode, rate = ratesList[0][0])
134                 
135         def listRates(self, querymode = None):
136                 if querymode is None:
137                         querymode = self.mode
138                 list = []
139                 print "modes for port", self.port, "and mode", querymode
140                 for mode in self.hw.getModeList(self.port):
141                         print mode
142                         if mode[0] == querymode:
143                                 for rate in mode[1]:
144                                         if self.port == "DVI-PC":
145                                                 print "rate:", rate
146                                                 if rate == "640x480":
147                                                         list.insert(0, (rate, rate))
148                                                         continue
149                                         list.append((rate, rate))
150                 return list
151         
152         def rateSelectionMade(self, index):
153                 print "rateSelectionMade:", index
154                 self.rate = index
155                 self.rateSelect(index)
156                 
157         def rateSelectionMoved(self):
158                 print "rate selection moved:", self.selection
159                 self.rateSelect(self.selection)
160
161         def rateSelect(self, rate):
162                 self.hw.setMode(port = self.port, mode = self.mode, rate = rate)
163
164         def showTestCard(self, selection = None):
165                 if selection is None:
166                         selection = self.selection
167                 print "set config.misc.showtestcard to", {'yes': True, 'no': False}[selection]
168                 if selection == "yes":
169                         config.misc.showtestcard.value = True
170                 else:
171                         config.misc.showtestcard.value = False
172
173         def keyNumberGlobal(self, number):
174                 if number in (1,2,3):
175                         if number == 1:
176                                 self.hw.saveMode("DVI", "720p", "multi")
177                         elif number == 2:
178                                 self.hw.saveMode("DVI", "1080i", "multi")
179                         elif number == 3:
180                                 self.hw.saveMode("Scart", "Multi", "multi")
181                         self.hw.setConfiguredMode()
182                         self.close()
183
184                 WizardLanguage.keyNumberGlobal(self, number)