added HD1200 box into InputDeviceSetup
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / InputDeviceSetup.py
1 from Screen import Screen
2 from Screens.HelpMenu import HelpableScreen
3 from Screens.MessageBox import MessageBox
4 from Components.InputDevice import iInputDevices, iRcTypeControl
5 from Components.Sources.StaticText import StaticText
6 from Components.Sources.List import List
7 from Components.config import config, ConfigYesNo, getConfigListEntry, ConfigSelection
8 from Components.ConfigList import ConfigListScreen
9 from Components.ActionMap import ActionMap, HelpableActionMap
10 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
11 from Tools.LoadPixmap import LoadPixmap
12
13 class InputDeviceSelection(Screen,HelpableScreen):
14         skin = """
15         <screen name="InputDeviceSelection" position="center,center" size="560,400" title="Select input device">
16                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on"/>
17                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on"/>
18                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on"/>
19                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on"/>
20                 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1"/>
21                 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1"/>
22                 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1"/>
23                 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1"/>
24                 <widget source="list" render="Listbox" position="5,50" size="550,280" zPosition="10" scrollbarMode="showOnDemand">
25                         <convert type="TemplatedMultiContent">
26                         <!--  device, description, devicepng, divpng  -->
27                                                         {"template": [
28                                                                         MultiContentEntryPixmapAlphaTest(pos = (2, 8), size = (54, 54), png = 2), # index 3 is the interface pixmap
29                                                                         MultiContentEntryText(pos = (65, 6), size = (450, 54), font=0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER|RT_WRAP, text = 1), # index 1 is the interfacename
30                                                                 ],
31                                                         "fonts": [gFont("Regular", 28),gFont("Regular", 20)],
32                                                         "itemHeight": 70
33                                                         }
34                         </convert>
35                 </widget>
36                 <ePixmap pixmap="skin_default/div-h.png" position="0,340" zPosition="1" size="560,2"/>
37                 <widget source="introduction" render="Label" position="0,350" size="560,50" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/>
38         </screen>"""
39
40
41         def __init__(self, session):
42                 Screen.__init__(self, session)
43                 HelpableScreen.__init__(self)
44
45                 self.edittext = _("Press OK to edit the settings.")
46
47                 self["key_red"] = StaticText(_("Close"))
48                 self["key_green"] = StaticText(_("Select"))
49                 self["key_yellow"] = StaticText("")
50                 self["key_blue"] = StaticText("")
51                 self["introduction"] = StaticText(self.edittext)
52
53                 self.devices = [(iInputDevices.getDeviceName(x),x) for x in iInputDevices.getDeviceList()]
54                 print "[InputDeviceSelection] found devices :->", len(self.devices),self.devices
55
56                 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
57                         {
58                         "cancel": (self.close, _("Exit input device selection.")),
59                         "ok": (self.okbuttonClick, _("Select input device.")),
60                         }, -2)
61
62                 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
63                         {
64                         "red": (self.close, _("Exit input device selection.")),
65                         "green": (self.okbuttonClick, _("Select input device.")),
66                         }, -2)
67
68                 self.currentIndex = 0
69                 self.list = []
70                 self["list"] = List(self.list)
71                 self.updateList()
72                 self.onLayoutFinish.append(self.layoutFinished)
73                 self.onClose.append(self.cleanup)
74
75         def layoutFinished(self):
76                 self.setTitle(_("Select input device"))
77
78         def cleanup(self):
79                 self.currentIndex = 0
80
81         def buildInterfaceList(self, device, description, type, isinputdevice = True):
82                 divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/div-h.png"))
83                 activepng = None
84                 devicepng = None
85                 enabled = iInputDevices.getDeviceAttribute(device, 'enabled')
86
87                 if type == 'remote':
88                         if config.misc.rcused.value == 0:
89                                 if enabled:
90                                         devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew-configured.png"))
91                                 else:
92                                         devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew.png"))
93                         else:
94                                 if enabled:
95                                         devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcold-configured.png"))
96                                 else:
97                                         devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcold.png"))
98                 elif type == 'keyboard':
99                         if enabled:
100                                 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_keyboard-configured.png"))
101                         else:
102                                 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_keyboard.png"))
103                 elif type == 'mouse':
104                         if enabled:
105                                 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_mouse-configured.png"))
106                         else:
107                                 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_mouse.png"))
108                 elif isinputdevice:
109                         devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew.png"))
110                 return ((device, description, devicepng, divpng))
111
112         def updateList(self):
113                 self.list = []
114
115                 if iRcTypeControl.multipleRcSupported():
116                         self.list.append(self.buildInterfaceList('rctype', _('Configure remote control type'), None, False))
117
118                 for x in self.devices:
119                         dev_type = iInputDevices.getDeviceAttribute(x[1], 'type')
120                         self.list.append(self.buildInterfaceList(x[1],_(x[0]), dev_type))
121
122                 self["list"].setList(self.list)
123                 self["list"].setIndex(self.currentIndex)
124
125         def okbuttonClick(self):
126                 selection = self["list"].getCurrent()
127                 self.currentIndex = self["list"].getIndex()
128                 if selection is not None:
129                         if selection[0] == 'rctype':
130                                 self.session.open(RemoteControlType)
131                         else:
132                                 self.session.openWithCallback(self.DeviceSetupClosed, InputDeviceSetup, selection[0])
133
134         def DeviceSetupClosed(self, *ret):
135                 self.updateList()
136
137
138 class InputDeviceSetup(Screen, ConfigListScreen):
139
140         skin = """
141                 <screen name="InputDeviceSetup" position="center,center" size="560,440" title="Input device setup">
142                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
143                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
144                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
145                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
146                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
147                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
148                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
149                         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
150                         <widget name="config" position="5,50" size="550,350" scrollbarMode="showOnDemand" />
151                         <ePixmap pixmap="skin_default/div-h.png" position="0,400" zPosition="1" size="560,2" />
152                         <widget source="introduction" render="Label" position="5,410" size="550,30" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
153                 </screen>"""
154
155         def __init__(self, session, device):
156                 Screen.__init__(self, session)
157                 self.inputDevice = device
158                 iInputDevices.currentDevice = self.inputDevice
159                 self.onChangedEntry = [ ]
160                 self.setup_title = _("Input device setup")
161                 self.isStepSlider = None
162                 self.enableEntry = None
163                 self.repeatEntry = None
164                 self.delayEntry = None
165                 self.nameEntry = None
166                 self.enableConfigEntry = None
167
168                 self.list = [ ]
169                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
170
171                 self["actions"] = ActionMap(["SetupActions", "MenuActions"],
172                         {
173                                 "cancel": self.keyCancel,
174                                 "save": self.apply,
175                                 "menu": self.closeRecursive,
176                         }, -2)
177
178                 self["key_red"] = StaticText(_("Cancel"))
179                 self["key_green"] = StaticText(_("OK"))
180                 self["key_yellow"] = StaticText()
181                 self["key_blue"] = StaticText()
182                 self["introduction"] = StaticText()
183
184                 self.createSetup()
185                 self.onLayoutFinish.append(self.layoutFinished)
186                 self.onClose.append(self.cleanup)
187
188         def layoutFinished(self):
189                 self.setTitle(self.setup_title)
190                 listWidth = self["config"].l.getItemSize().width()
191                 # use 20% of list width for sliders
192                 self["config"].l.setSeperation(int(listWidth*.8))
193
194         def cleanup(self):
195                 iInputDevices.currentDevice = ""
196
197         def createSetup(self):
198                 self.list = [ ]
199                 label = _("Change repeat and delay settings?")
200                 cmd = "self.enableEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".enabled)"
201                 exec (cmd)
202                 label = _("Interval between keys when repeating:")
203                 cmd = "self.repeatEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".repeat)"
204                 exec (cmd)
205                 label = _("Delay before key repeat starts:")
206                 cmd = "self.delayEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".delay)"
207                 exec (cmd)
208                 label = _("Devicename:")
209                 cmd = "self.nameEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".name)"
210                 exec (cmd)
211                 if self.enableEntry:
212                         if isinstance(self.enableEntry[1], ConfigYesNo):
213                                 self.enableConfigEntry = self.enableEntry[1]
214
215                 self.list.append(self.enableEntry)
216                 if self.enableConfigEntry:
217                         if self.enableConfigEntry.value is True:
218                                 self.list.append(self.repeatEntry)
219                                 self.list.append(self.delayEntry)
220                         else:
221                                 self.repeatEntry[1].setValue(self.repeatEntry[1].default)
222                                 self["config"].invalidate(self.repeatEntry)
223                                 self.delayEntry[1].setValue(self.delayEntry[1].default)
224                                 self["config"].invalidate(self.delayEntry)
225                                 self.nameEntry[1].setValue(self.nameEntry[1].default)
226                                 self["config"].invalidate(self.nameEntry)
227
228                 self["config"].list = self.list
229                 self["config"].l.setList(self.list)
230                 if not self.selectionChanged in self["config"].onSelectionChanged:
231                         self["config"].onSelectionChanged.append(self.selectionChanged)
232                 self.selectionChanged()
233
234         def selectionChanged(self):
235                 if self["config"].getCurrent() == self.enableEntry:
236                         self["introduction"].setText(_("Current device: ") + str(iInputDevices.getDeviceAttribute(self.inputDevice, 'name')) )
237                 else:
238                         self["introduction"].setText(_("Current value: ") + self.getCurrentValue() + _(" ms"))
239
240         def newConfig(self):
241                 current = self["config"].getCurrent()
242                 if current:
243                         if current == self.enableEntry:
244                                 self.createSetup()
245
246         def keyLeft(self):
247                 ConfigListScreen.keyLeft(self)
248                 self.newConfig()
249
250         def keyRight(self):
251                 ConfigListScreen.keyRight(self)
252                 self.newConfig()
253
254         def confirm(self, confirmed):
255                 if not confirmed:
256                         print "not confirmed"
257                         return
258                 else:
259                         self.nameEntry[1].setValue(iInputDevices.getDeviceAttribute(self.inputDevice, 'name'))
260                         cmd = "config.inputDevices." + self.inputDevice + ".name.save()"
261                         exec (cmd)
262                         self.keySave()
263
264         def apply(self):
265                 self.session.openWithCallback(self.confirm, MessageBox, _("Use these input device settings?"), MessageBox.TYPE_YESNO, timeout=20, default=True)
266
267         def cancelConfirm(self, result):
268                 if not result:
269                         return
270                 for x in self["config"].list:
271                         x[1].cancel()
272                 self.close()
273
274         def keyCancel(self):
275                 if self["config"].isChanged():
276                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"), MessageBox.TYPE_YESNO, timeout=20, default=True)
277                 else:
278                         self.close()
279         # for summary:
280         def changedEntry(self):
281                 for x in self.onChangedEntry:
282                         x()
283                 self.selectionChanged()
284
285         def getCurrentEntry(self):
286                 return self["config"].getCurrent()[0]
287
288         def getCurrentValue(self):
289                 return str(self["config"].getCurrent()[1].value)
290
291         def createSummary(self):
292                 from Screens.Setup import SetupSummary
293                 return SetupSummary
294
295
296 class RemoteControlType(Screen, ConfigListScreen):
297         rcList = [
298                         ("0", _("Default")),
299                         ("11", _("et9200/9500/6500")),
300                         ("13", _("et4000")),
301                         ("7", _("et5000/6000")),
302                         ("9", _("et8000/et10000")),
303                         ("4", _("DMM normal")),
304                         ("5", _("et9000/et9100")),
305                         ("6", _("DMM advanced")),
306                         ("14", _("xp1000")),
307                         ("8", _("VU+")),
308                         ("18", _("F1/F3")),
309                         ("16", _("HD1100/HD1200/et7x00/et8500")),
310                         ("19", _("HD2400"))
311                 ]
312
313         defaultRcList = [
314                         ("et4000", 13),
315                         ("et5000", 7),
316                         ("et6000", 7),
317                         ("et6500", 11),
318                         ("et8000", 9),
319                         ("et9000", 5),
320                         ("et9100", 5),
321                         ("et9200", 11),
322                         ("et9500", 11),
323                         ("et10000", 9),
324                         ("formuler1", 18),
325                         ("formuler3", 18),
326                         ("xp1000", 14),
327                         ("hd1200", 16),
328                         ("hd1100", 16),
329                         ("hd2400", 19),
330                         ("et7000", 16),
331                         ("et7500", 16),
332                         ("et8500", 16)
333                 ]
334
335         def __init__(self, session):
336                 Screen.__init__(self, session)
337                 self.skinName = ["RemoteControlType", "Setup" ]
338
339                 self["actions"] = ActionMap(["SetupActions"],
340                 {
341                         "cancel": self.keyCancel,
342                         "save": self.keySave,
343                 }, -1)
344
345                 self["key_green"] = StaticText(_("Save"))
346                 self["key_red"] = StaticText(_("Cancel"))
347
348                 self.list = []
349                 ConfigListScreen.__init__(self, self.list, session = self.session)
350
351                 rctype = config.plugins.remotecontroltype.rctype.value
352                 self.rctype = ConfigSelection(choices = self.rcList, default = str(rctype))
353                 self.list.append(getConfigListEntry(_("Remote control type"), self.rctype))
354                 self["config"].list = self.list
355
356                 self.defaultRcType = None
357                 self.getDefaultRcType()
358
359         def getDefaultRcType(self):
360                 data = iRcTypeControl.getBoxType()
361                 for x in self.defaultRcList:
362                         if x[0] in data:
363                                 self.defaultRcType = x[1]
364                                 break
365
366         def setDefaultRcType(self):
367                 iRcTypeControl.writeRcType(self.defaultRcType)
368
369         def keySave(self):
370                 if config.plugins.remotecontroltype.rctype.value == int(self.rctype.value):
371                         self.close()
372                 else:
373                         self.setNewSetting()
374                         self.session.openWithCallback(self.keySaveCallback, MessageBox, _("Is this setting ok?"), MessageBox.TYPE_YESNO, timeout=20, default=True, timeout_default=False)
375
376         def keySaveCallback(self, answer):
377                 if answer is False:
378                         self.restoreOldSetting()
379                 else:
380                         config.plugins.remotecontroltype.rctype.value = int(self.rctype.value)
381                         config.plugins.remotecontroltype.save()
382                         self.close()
383
384         def restoreOldSetting(self):
385                 if config.plugins.remotecontroltype.rctype.value == 0:
386                         self.setDefaultRcType()
387                 else:
388                         iRcTypeControl.writeRcType(config.plugins.remotecontroltype.rctype.value)
389
390         def setNewSetting(self):
391                 if int(self.rctype.value) == 0:
392                         self.setDefaultRcType()
393                 else:
394                         iRcTypeControl.writeRcType(int(self.rctype.value))
395
396         def keyCancel(self):
397                 self.restoreOldSetting()
398                 self.close()