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