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