Don't install *.jpg files with the Plugin metadata to save space.
[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                 ratesList = self.listRates(modeList[0][0])
109                 self.hw.setMode(port = port, mode = modeList[0][0], rate = ratesList[0][0])
110                 
111         def listModes(self):
112                 list = []
113                 print "modes for port", self.port
114                 for mode in self.hw.getModeList(self.port):
115                         #if mode[0] != "PC":
116                                 list.append((mode[0], mode[0]))
117                 print "modeslist:", list
118                 return list
119         
120         def modeSelectionMade(self, index):
121                 print "modeSelectionMade:", index
122                 self.mode = index
123                 self.modeSelect(index)
124                 
125         def modeSelectionMoved(self):
126                 print "mode selection moved:", self.selection
127                 self.modeSelect(self.selection)
128                 
129         def modeSelect(self, mode):
130                 ratesList = self.listRates(mode)
131                 print "ratesList:", ratesList
132                 self.hw.setMode(port = self.port, mode = mode, rate = ratesList[0][0])
133                 
134         def listRates(self, querymode = None):
135                 if querymode is None:
136                         querymode = self.mode
137                 list = []
138                 print "modes for port", self.port, "and mode", querymode
139                 for mode in self.hw.getModeList(self.port):
140                         print mode
141                         if mode[0] == querymode:
142                                 for rate in mode[1]:
143                                         if self.port == "DVI-PC":
144                                                 print "rate:", rate
145                                                 if rate == "640x480":
146                                                         list.insert(0, (rate, rate))
147                                                         continue
148                                         list.append((rate, rate))
149                 return list
150         
151         def rateSelectionMade(self, index):
152                 print "rateSelectionMade:", index
153                 self.rate = index
154                 self.rateSelect(index)
155                 
156         def rateSelectionMoved(self):
157                 print "rate selection moved:", self.selection
158                 self.rateSelect(self.selection)
159
160         def rateSelect(self, rate):
161                 self.hw.setMode(port = self.port, mode = self.mode, rate = rate)
162
163         def showTestCard(self, selection = None):
164                 if selection is None:
165                         selection = self.selection
166                 print "set config.misc.showtestcard to", {'yes': True, 'no': False}[selection]
167                 if selection == "yes":
168                         config.misc.showtestcard.value = True
169                 else:
170                         config.misc.showtestcard.value = False
171
172         def keyNumberGlobal(self, number):
173                 if number in (1,2,3):
174                         if number == 1:
175                                 self.hw.saveMode("DVI", "720p", "multi")
176                         elif number == 2:
177                                 self.hw.saveMode("DVI", "1080i", "multi")
178                         elif number == 3:
179                                 self.hw.saveMode("Scart", "Multi", "multi")
180                         self.hw.setConfiguredMode()
181                         self.close()
182
183                 WizardLanguage.keyNumberGlobal(self, number)