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
13 class InputDeviceSelection(Screen,HelpableScreen):
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 -->
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
31 "fonts": [gFont("Regular", 28),gFont("Regular", 20)],
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"/>
41 def __init__(self, session):
42 Screen.__init__(self, session)
43 HelpableScreen.__init__(self)
45 self.edittext = _("Press OK to edit the settings.")
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)
53 self.devices = [(iInputDevices.getDeviceName(x),x) for x in iInputDevices.getDeviceList()]
54 print "[InputDeviceSelection] found devices :->", len(self.devices),self.devices
56 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
58 "cancel": (self.close, _("Exit input device selection.")),
59 "ok": (self.okbuttonClick, _("Select input device.")),
62 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
64 "red": (self.close, _("Exit input device selection.")),
65 "green": (self.okbuttonClick, _("Select input device.")),
70 self["list"] = List(self.list)
72 self.onLayoutFinish.append(self.layoutFinished)
73 self.onClose.append(self.cleanup)
75 def layoutFinished(self):
76 self.setTitle(_("Select input device"))
81 def buildInterfaceList(self, device, description, type, isinputdevice = True):
82 divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/div-h.png"))
85 enabled = iInputDevices.getDeviceAttribute(device, 'enabled')
88 if config.misc.rcused.value == 0:
90 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew-configured.png"))
92 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew.png"))
95 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcold-configured.png"))
97 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcold.png"))
98 elif type == 'keyboard':
100 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_keyboard-configured.png"))
102 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_keyboard.png"))
103 elif type == 'mouse':
105 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_mouse-configured.png"))
107 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_mouse.png"))
109 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew.png"))
110 return ((device, description, devicepng, divpng))
112 def updateList(self):
115 if iRcTypeControl.multipleRcSupported():
116 self.list.append(self.buildInterfaceList('rctype', _('Configure remote control type'), None, False))
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))
122 self["list"].setList(self.list)
123 self["list"].setIndex(self.currentIndex)
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)
132 self.session.openWithCallback(self.DeviceSetupClosed, InputDeviceSetup, selection[0])
134 def DeviceSetupClosed(self, *ret):
138 class InputDeviceSetup(Screen, ConfigListScreen):
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" />
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
169 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
171 self["actions"] = ActionMap(["SetupActions", "MenuActions"],
173 "cancel": self.keyCancel,
175 "menu": self.closeRecursive,
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()
185 self.onLayoutFinish.append(self.layoutFinished)
186 self.onClose.append(self.cleanup)
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))
195 iInputDevices.currentDevice = ""
197 def createSetup(self):
198 label = _("Change repeat and delay settings?")
199 cmd = "self.enableEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".enabled)"
201 label = _("Interval between keys when repeating:")
202 cmd = "self.repeatEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".repeat)"
204 label = _("Delay before key repeat starts:")
205 cmd = "self.delayEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".delay)"
207 label = _("Devicename:")
208 cmd = "self.nameEntry = getConfigListEntry(label, config.inputDevices." + self.inputDevice + ".name)"
211 if isinstance(self.enableEntry[1], ConfigYesNo):
212 self.enableConfigEntry = self.enableEntry[1]
214 self.list.append(self.enableEntry)
215 if self.enableConfigEntry:
216 if self.enableConfigEntry.value is True:
217 self.list.append(self.repeatEntry)
218 self.list.append(self.delayEntry)
220 self.repeatEntry[1].setValue(self.repeatEntry[1].default)
221 self["config"].invalidate(self.repeatEntry)
222 self.delayEntry[1].setValue(self.delayEntry[1].default)
223 self["config"].invalidate(self.delayEntry)
224 self.nameEntry[1].setValue(self.nameEntry[1].default)
225 self["config"].invalidate(self.nameEntry)
227 self["config"].list = self.list
228 self["config"].l.setList(self.list)
229 if not self.selectionChanged in self["config"].onSelectionChanged:
230 self["config"].onSelectionChanged.append(self.selectionChanged)
231 self.selectionChanged()
233 def selectionChanged(self):
234 if self["config"].getCurrent() == self.enableEntry:
235 self["introduction"].setText(_("Current device: ") + str(iInputDevices.getDeviceAttribute(self.inputDevice, 'name')) )
237 self["introduction"].setText(_("Current value: ") + self.getCurrentValue() + _(" ms"))
240 current = self["config"].getCurrent()
242 if current == self.enableEntry:
246 ConfigListScreen.keyLeft(self)
250 ConfigListScreen.keyRight(self)
253 def confirm(self, confirmed):
255 print "not confirmed"
258 self.nameEntry[1].setValue(iInputDevices.getDeviceAttribute(self.inputDevice, 'name'))
259 cmd = "config.inputDevices." + self.inputDevice + ".name.save()"
264 self.session.openWithCallback(self.confirm, MessageBox, _("Use these input device settings?"), MessageBox.TYPE_YESNO, timeout = 20, default = True)
266 def cancelConfirm(self, result):
269 for x in self["config"].list:
274 if self["config"].isChanged():
275 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"), MessageBox.TYPE_YESNO, timeout = 20, default = True)
279 def changedEntry(self):
280 for x in self.onChangedEntry:
282 self.selectionChanged()
284 def getCurrentEntry(self):
285 return self["config"].getCurrent()[0]
287 def getCurrentValue(self):
288 return str(self["config"].getCurrent()[1].value)
290 def createSummary(self):
291 from Screens.Setup import SetupSummary
295 class RemoteControlType(Screen, ConfigListScreen):
298 ("4", _("DMM normal")), ("6", _("DMM advanced")),
299 ("11", "et9x00/6500"), ("7", "et5000/6000"), ("13", "et4000"),
315 def __init__(self, session):
316 Screen.__init__(self, session)
317 self.skinName = ["RemoteControlType", "Setup" ]
319 self["actions"] = ActionMap(["SetupActions"],
321 "cancel": self.keyCancel,
322 "save": self.keySave,
325 self["key_green"] = StaticText(_("Save"))
326 self["key_red"] = StaticText(_("Cancel"))
329 ConfigListScreen.__init__(self, self.list, session = self.session)
331 rctype = config.plugins.remotecontroltype.rctype.value
332 self.rctype = ConfigSelection(choices = self.rcList, default = str(rctype))
333 self.list.append(getConfigListEntry(_("Remote control type"), self.rctype))
334 self["config"].list = self.list
336 self.defaultRcType = None
337 self.getDefaultRcType()
339 def getDefaultRcType(self):
340 data = iRcTypeControl.getBoxType()
341 for x in self.defaultRcList:
343 self.defaultRcType = x[1]
346 def setDefaultRcType(self):
347 iRcTypeControl.writeRcType(self.defaultRcType)
350 if config.plugins.remotecontroltype.rctype.value == int(self.rctype.value):
354 self.session.openWithCallback(self.keySaveCallback, MessageBox, _("Is this setting ok?"), MessageBox.TYPE_YESNO, timeout = 20, default = False)
356 def keySaveCallback(self, answer):
358 self.restoreOldSetting()
360 config.plugins.remotecontroltype.rctype.value = int(self.rctype.value)
361 config.plugins.remotecontroltype.save()
364 def restoreOldSetting(self):
365 if config.plugins.remotecontroltype.rctype.value == 0:
366 self.setDefaultRcType()
368 iRcTypeControl.writeRcType(config.plugins.remotecontroltype.rctype.value)
370 def setNewSetting(self):
371 if int(self.rctype.value) == 0:
372 self.setDefaultRcType()
374 iRcTypeControl.writeRcType(int(self.rctype.value))
377 self.restoreOldSetting()