allow language selection in video wizard
[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="wizard.png" position="40,50" zPosition="10" size="110,174" transparent="1" alphatest="on"/>
44                         <ePixmap pixmap="skin_default/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="rc.png" position="500,600" zPosition="10" size="154,475" transparent="1" alphatest="on"/>
48                         <widget name="arrowdown" pixmap="arrowdown.png" position="0,0" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
49                         <widget name="arrowup" pixmap="arrowup.png" position="-100,-100" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
50                         <widget name="arrowup2" pixmap="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                 pass
78         
79         def listInputChannels(self):
80                 list = []
81
82                 for port in self.hw.getPortList():
83                         if self.hw.isPortUsed(port):
84                                 list.append((port,port))
85                 list.sort(key = lambda x: x[0])
86                 print "listInputChannels:", list
87                 return list
88
89         def inputSelectionMade(self, index):
90                 print "inputSelectionMade:", index
91                 self.port = index
92                 self.inputSelect(index)
93                 
94         def inputSelectionMoved(self):
95                 print "input selection moved:", self.selection
96                 self.inputSelect(self.selection)
97                 if self["portpic"].instance is not None:
98                         self["portpic"].instance.setPixmapFromFile(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/" + self.selection + ".png"))
99                 
100         def inputSelect(self, port):
101                 print "inputSelect:", port
102                 modeList = self.hw.getModeList(self.selection)
103                 print "modeList:", modeList
104                 self.hw.setMode(port = port, mode = modeList[0][0], rate = modeList[0][1][0])
105                 
106         def listModes(self):
107                 list = []
108                 print "modes for port", self.port
109                 for mode in self.hw.getModeList(self.port):
110                         if mode[0] != "PC":
111                                 list.append((mode[0], mode[0]))
112                 print "modeslist:", list
113                 return list
114         
115         def modeSelectionMade(self, index):
116                 print "modeSelectionMade:", index
117                 self.mode = index
118                 self.modeSelect(index)
119                 
120         def modeSelectionMoved(self):
121                 print "mode selection moved:", self.selection
122                 self.modeSelect(self.selection)
123                 
124         def modeSelect(self, mode):
125                 ratesList = self.listRates(mode)
126                 print "ratesList:", ratesList
127                 self.hw.setMode(port = self.port, mode = mode, rate = ratesList[0][0])
128                 
129         def listRates(self, querymode = None):
130                 if querymode is None:
131                         querymode = self.mode
132                 list = []
133                 print "modes for port", self.port, "and mode", querymode
134                 for mode in self.hw.getModeList(self.port):
135                         print mode
136                         if mode[0] == querymode:
137                                 for rate in mode[1]:
138                                         list.append((rate, rate))
139                 return list
140         
141         def rateSelectionMade(self, index):
142                 print "rateSelectionMade:", index
143                 self.rate = index
144                 self.rateSelect(index)
145                 
146         def rateSelectionMoved(self):
147                 print "rate selection moved:", self.selection
148                 self.rateSelect(self.selection)
149
150         def rateSelect(self, rate):
151                 self.hw.setMode(port = self.port, mode = self.mode, rate = rate)
152
153         def showTestCard(self, selection = None):
154                 if selection is None:
155                         selection = self.selection
156                 print "set config.misc.showtestcard to", {'yes': True, 'no': False}[selection]
157                 if selection == "yes":
158                         config.misc.showtestcard.value = True
159                 else:
160                         config.misc.showtestcard.value = False