1 from Screen import Screen
2 from Screens.HelpMenu import HelpableScreen
3 from Screens.MessageBox import MessageBox
4 from Components.InputDevice import iInputDevices
5 from Components.Sources.StaticText import StaticText
6 from Components.Sources.Boolean import Boolean
7 from Components.Sources.List import List
8 from Components.config import config, ConfigSlider, ConfigSubsection, ConfigYesNo, ConfigText, getConfigListEntry, ConfigNothing
9 from Components.ConfigList import ConfigListScreen
10 from Components.ActionMap import ActionMap, NumberActionMap, HelpableActionMap
11 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
12 from Tools.LoadPixmap import LoadPixmap
14 class InputDeviceSelection(Screen,HelpableScreen):
16 <screen name="InputDeviceSelection" position="center,center" size="560,400" title="Select input device">
17 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on"/>
18 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on"/>
19 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on"/>
20 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on"/>
21 <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"/>
22 <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"/>
23 <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"/>
24 <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"/>
25 <widget source="list" render="Listbox" position="5,50" size="550,280" zPosition="10" scrollbarMode="showOnDemand">
26 <convert type="TemplatedMultiContent">
27 <!-- device, description, devicepng, divpng -->
29 MultiContentEntryPixmapAlphaTest(pos = (2, 8), size = (54, 54), png = 2), # index 3 is the interface pixmap
30 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
32 "fonts": [gFont("Regular", 28),gFont("Regular", 20)],
38 <ePixmap pixmap="skin_default/div-h.png" position="0,340" zPosition="1" size="560,2"/>
39 <widget source="introduction" render="Label" position="0,350" size="560,50" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/>
43 def __init__(self, session):
44 Screen.__init__(self, session)
45 HelpableScreen.__init__(self)
47 self.edittext = _("Press OK to edit the settings.")
49 self["key_red"] = StaticText(_("Close"))
50 self["key_green"] = StaticText(_("Select"))
51 self["key_yellow"] = StaticText("")
52 self["key_blue"] = StaticText("")
53 self["introduction"] = StaticText(self.edittext)
55 self.devices = [(iInputDevices.getDeviceName(x),x) for x in iInputDevices.getDeviceList()]
56 print "[InputDeviceSelection] found devices :->", len(self.devices),self.devices
58 self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
60 "cancel": (self.close, _("Exit input device selection.")),
61 "ok": (self.okbuttonClick, _("Select input device.")),
64 self["ColorActions"] = HelpableActionMap(self, "ColorActions",
66 "red": (self.close, _("Exit input device selection.")),
67 "green": (self.okbuttonClick, _("Select input device.")),
72 self["list"] = List(self.list)
74 self.onLayoutFinish.append(self.layoutFinished)
75 self.onClose.append(self.cleanup)
77 def layoutFinished(self):
78 self.setTitle(_("Select input device"))
83 def buildInterfaceList(self,device,description,type ):
84 divpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/div-h.png"))
87 enabled = iInputDevices.getDeviceAttribute(device, 'enabled')
90 if config.misc.rcused.value == 0:
92 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew-configured.png"))
94 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew.png"))
97 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcold-configured.png"))
99 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcold.png"))
100 elif type == 'keyboard':
102 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_keyboard-configured.png"))
104 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_keyboard.png"))
105 elif type == 'mouse':
107 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_mouse-configured.png"))
109 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_mouse.png"))
111 devicepng = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, "skin_default/icons/input_rcnew.png"))
112 return((device, description, devicepng, divpng))
114 def updateList(self):
116 for x in self.devices:
117 dev_type = iInputDevices.getDeviceAttribute(x[1], 'type')
118 self.list.append(self.buildInterfaceList(x[1],_(x[0]), dev_type ))
119 self["list"].setList(self.list)
120 self["list"].setIndex(self.currentIndex)
122 def okbuttonClick(self):
123 selection = self["list"].getCurrent()
124 self.currentIndex = self["list"].getIndex()
125 if selection is not None:
126 self.session.openWithCallback(self.DeviceSetupClosed, InputDeviceSetup, selection[0])
128 def DeviceSetupClosed(self, *ret):
132 class InputDeviceSetup(Screen, ConfigListScreen):
135 <screen name="InputDeviceSetup" position="center,center" size="560,440" title="Input device setup">
136 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
137 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
138 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
139 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
140 <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" />
141 <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" />
142 <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" />
143 <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" />
144 <widget name="config" position="5,50" size="550,350" scrollbarMode="showOnDemand" />
145 <ePixmap pixmap="skin_default/div-h.png" position="0,400" zPosition="1" size="560,2" />
146 <widget source="introduction" render="Label" position="5,410" size="550,30" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
149 def __init__(self, session, device):
150 Screen.__init__(self, session)
151 self.inputDevice = device
152 iInputDevices.currentDevice = self.inputDevice
153 self.onChangedEntry = [ ]
154 self.setup_title = _("Input device setup")
155 self.isStepSlider = None
156 self.enableEntry = None
157 self.repeatEntry = None
158 self.delayEntry = None
159 self.nameEntry = None
160 self.enableConfigEntry = None
163 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changedEntry)
165 self["actions"] = ActionMap(["SetupActions"],
167 "cancel": self.keyCancel,
171 self["key_red"] = StaticText(_("Cancel"))
172 self["key_green"] = StaticText(_("OK"))
173 self["key_yellow"] = StaticText()
174 self["key_blue"] = StaticText()
175 self["introduction"] = StaticText()
178 self.onLayoutFinish.append(self.layoutFinished)
179 self.onClose.append(self.cleanup)
181 def layoutFinished(self):
182 self.setTitle(self.setup_title)
185 iInputDevices.currentDevice = ""
187 def createSetup(self):
189 cmd = "self.enableEntry = getConfigListEntry(_('"'Change repeat and delay settings?'"'), config.inputDevices." + self.inputDevice + ".enabled)"
191 cmd = "self.repeatEntry = getConfigListEntry(_('"'Interval between keys when repeating:'"'), config.inputDevices." + self.inputDevice + ".repeat)"
193 cmd = "self.delayEntry = getConfigListEntry(_('"'Delay before key repeat starts:'"'), config.inputDevices." + self.inputDevice + ".delay)"
195 cmd = "self.nameEntry = getConfigListEntry(_('"'Devicename:'"'), config.inputDevices." + self.inputDevice + ".name)"
198 if isinstance(self.enableEntry[1], ConfigYesNo):
199 self.enableConfigEntry = self.enableEntry[1]
201 self.list.append(self.enableEntry)
202 if self.enableConfigEntry:
203 if self.enableConfigEntry.value is True:
204 self.list.append(self.repeatEntry)
205 self.list.append(self.delayEntry)
207 self.repeatEntry[1].setValue(self.repeatEntry[1].default)
208 self["config"].invalidate(self.repeatEntry)
209 self.delayEntry[1].setValue(self.delayEntry[1].default)
210 self["config"].invalidate(self.delayEntry)
211 self.nameEntry[1].setValue(self.nameEntry[1].default)
212 self["config"].invalidate(self.nameEntry)
214 self["config"].list = self.list
215 self["config"].l.setSeperation(400)
216 self["config"].l.setList(self.list)
217 if not self.selectionChanged in self["config"].onSelectionChanged:
218 self["config"].onSelectionChanged.append(self.selectionChanged)
219 self.selectionChanged()
221 def selectionChanged(self):
222 if self["config"].getCurrent() == self.enableEntry:
223 self["introduction"].setText(_("Current device: ") + str(iInputDevices.getDeviceAttribute(self.inputDevice, 'name')) )
225 self["introduction"].setText(_("Current value: ") + self.getCurrentValue() + _(" ms"))
228 current = self["config"].getCurrent()
230 if current == self.enableEntry:
234 ConfigListScreen.keyLeft(self)
238 ConfigListScreen.keyRight(self)
241 def confirm(self, confirmed):
243 print "not confirmed"
246 self.nameEntry[1].setValue(iInputDevices.getDeviceAttribute(self.inputDevice, 'name'))
247 cmd = "config.inputDevices." + self.inputDevice + ".name.save()"
252 self.session.openWithCallback(self.confirm, MessageBox, _("Use this input device settings?"), MessageBox.TYPE_YESNO, timeout = 20, default = True)
254 def cancelConfirm(self, result):
257 for x in self["config"].list:
262 if self["config"].isChanged():
263 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"), MessageBox.TYPE_YESNO, timeout = 20, default = True)
267 def changedEntry(self):
268 for x in self.onChangedEntry:
270 self.selectionChanged()
272 def getCurrentEntry(self):
273 return self["config"].getCurrent()[0]
275 def getCurrentValue(self):
276 return str(self["config"].getCurrent()[1].value)
278 def createSummary(self):
279 from Screens.Setup import SetupSummary