cb64f9acfb661610f549da169a31b065acff2030
[enigma2.git] / lib / python / Plugins / SystemPlugins / Videomode / VideoWizard.py
1 from Screens.Wizard import Wizard, wizardManager, WizardSummary
2 import sys
3 from VideoHardware import video_hw
4
5 from Components.Pixmap import Pixmap, MovingPixmap
6 from Components.config import config, ConfigBoolean, configfile
7
8 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
9 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT
10 from Tools.LoadPixmap import LoadPixmap
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,42" font="Regular;14" transparent="1" />
18                 <widget source="parent.list" render="Label" position="6,25" size="120,21" font="Regular;16">
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(Wizard):
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="wizard.png" position="40,50" zPosition="10" size="110,174" transparent="1" alphatest="on"/>
43                         <widget name="portpic" pixmap="%s" position="50,300" zPosition="10" size="150,150" transparent="1" alphatest="on"/>
44                         <widget name="rc" pixmap="rc.png" position="500,600" zPosition="10" size="154,475" transparent="1" alphatest="on"/>
45                         <widget name="arrowdown" pixmap="arrowdown.png" position="0,0" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
46                         <widget name="arrowup" pixmap="arrowup.png" position="-100,-100" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
47                         <widget name="arrowup2" pixmap="arrowup.png" position="-100,-100" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
48                 </screen>""" % (resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/Scart.png"))
49         
50         def __init__(self, session):
51                 # FIXME anyone knows how to use relative paths from the plugin's directory?
52                 self.xmlfile = resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/videowizard.xml")
53                 self.hw = video_hw
54                 
55                 Wizard.__init__(self, session, showSteps = False, showStepSlider = False)
56                 self["wizard"] = Pixmap()
57                 self["rc"] = MovingPixmap()
58                 self["portpic"] = Pixmap()
59                 self["arrowdown"] = MovingPixmap()
60                 self["arrowup"] = MovingPixmap()
61                 self["arrowup2"] = MovingPixmap()
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                 pass
75         
76         def listInputChannels(self):
77                 list = []
78
79                 for port in self.hw.getPortList():
80                         if self.hw.isPortUsed(port):
81                                 list.append((port,port))
82                 list.sort(key = lambda x: x[0])
83                 print "listInputChannels:", list
84                 return list
85
86         def inputSelectionMade(self, index):
87                 print "inputSelectionMade:", index
88                 self.port = index
89                 self.inputSelect(index)
90                 
91         def inputSelectionMoved(self):
92                 print "input selection moved:", self.selection
93                 self.inputSelect(self.selection)
94                 if self["portpic"].instance is not None:
95                         self["portpic"].instance.setPixmapFromFile(resolveFilename(SCOPE_PLUGINS, "SystemPlugins/Videomode/" + self.selection + ".png"))
96                 
97         def inputSelect(self, port):
98                 print "inputSelect:", port
99                 modeList = self.hw.getModeList(self.selection)
100                 print "modeList:", modeList
101                 self.hw.setMode(port = port, mode = modeList[0][0], rate = modeList[0][1][0])
102                 
103         def listModes(self):
104                 list = []
105                 print "modes for port", self.port
106                 for mode in self.hw.getModeList(self.port):
107                         if mode[0] != "PC":
108                                 list.append((mode[0], mode[0]))
109                 print "modeslist:", list
110                 return list
111         
112         def modeSelectionMade(self, index):
113                 print "modeSelectionMade:", index
114                 self.mode = index
115                 self.modeSelect(index)
116                 
117         def modeSelectionMoved(self):
118                 print "mode selection moved:", self.selection
119                 self.modeSelect(self.selection)
120                 
121         def modeSelect(self, mode):
122                 ratesList = self.listRates(mode)
123                 print "ratesList:", ratesList
124                 self.hw.setMode(port = self.port, mode = mode, rate = ratesList[0][0])
125                 
126         def listRates(self, querymode = None):
127                 if querymode is None:
128                         querymode = self.mode
129                 list = []
130                 print "modes for port", self.port, "and mode", querymode
131                 for mode in self.hw.getModeList(self.port):
132                         print mode
133                         if mode[0] == querymode:
134                                 for rate in mode[1]:
135                                         list.append((rate, rate))
136                 return list
137         
138         def rateSelectionMade(self, index):
139                 print "rateSelectionMade:", index
140                 self.rate = index
141                 self.rateSelect(index)
142                 
143         def rateSelectionMoved(self):
144                 print "rate selection moved:", self.selection
145                 self.rateSelect(self.selection)
146
147         def rateSelect(self, rate):
148                 self.hw.setMode(port = self.port, mode = self.mode, rate = rate)
149
150         def showTestCard(self, selection = None):
151                 if selection is None:
152                         selection = self.selection
153                 print "set config.misc.showtestcard to", {'yes': True, 'no': False}[selection]
154                 if selection == "yes":
155                         config.misc.showtestcard.value = True
156                 else:
157                         config.misc.showtestcard.value = False