93d77c6208f61133fa47d109fdc38cd72f57333c
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / Hotkey.py
1 from Components.ActionMap import ActionMap, HelpableActionMap, NumberActionMap
2 from Components.Button import Button
3 from Components.ChoiceList import ChoiceList, ChoiceEntryComponent
4 from Components.SystemInfo import SystemInfo
5 from Components.config import config, ConfigSubsection, ConfigText, ConfigYesNo
6 from Components.PluginComponent import plugins
7 from Screens.ChoiceBox import ChoiceBox
8 from Screens.Screen import Screen
9 from Screens.MessageBox import MessageBox
10 from Plugins.Plugin import PluginDescriptor
11 from Tools.BoundFunction import boundFunction
12 from ServiceReference import ServiceReference
13 from enigma import eServiceReference
14 import os
15
16 def getHotkeys():
17         return [(_("Red") + " " + _("long"), "red_long", ""),
18                 (_("Green") + " " + _("long"), "green_long", ""),
19                 (_("Yellow") + " " + _("long"), "yellow_long", ""),
20                 (_("Blue") + " " + _("long"), "blue_long", "Plugins/PLi/SoftcamSetup/1"),
21                 ("F1/LAN", "f1", ""),
22                 ("F1" + " " + _("long"), "f1_long", ""),
23                 ("F2", "f2", ""),
24                 ("F2" + " " + _("long"), "f2_long", ""),
25                 ("F3", "f3", ""),
26                 ("F3" + " " + _("long"), "f3_long", ""),
27                 (_("Red"), "red", ""),
28                 (_("Green"), "green", ""),
29                 (_("Yellow"), "yellow", ""),
30                 (_("Blue"), "blue", ""),
31                 ("Rec", "rec", ""),
32                 ("Radio", "radio", ""),
33                 ("TV", "showTv", ""),
34                 ("Teletext", "text", ""),
35                 ("Help", "displayHelp", ""),
36                 ("Help" + " " + _("long"), "displayHelp_long", ""),
37                 ("Subtitle", "subtitle", ""),
38                 ("Menu", "mainMenu", ""),
39                 ("Info (EPG)", "info", "Infobar/openEventView"),
40                 ("Info (EPG)" + " " + _("long"), "info_long", "Infobar/showEventInfoPlugins"),
41                 ("List/Fav/PVR", "list", ""),
42                 ("Back/Recall", "back", ""),
43                 ("Back/Recall" + " " + _("long"), "back_long", ""),
44                 ("End", "end", ""),
45                 ("Epg/Guide", "epg", "Plugins/Extensions/GraphMultiEPG/1"),
46                 ("Epg/Guide" + " " + _("long"), "epg_long", "Infobar/showEventInfoPlugins"),
47                 ("Left", "cross_left", ""),
48                 ("Right", "cross_right", ""),
49                 ("Up", "cross_up", ""),
50                 ("Down", "cross_down", ""),
51                 ("Ok", "ok", ""),
52                 ("Channel up", "channelup", ""),
53                 ("Channel down", "channeldown", ""),
54                 ("Next", "next", ""),
55                 ("Previous", "previous", ""),
56                 ("Audio", "audio", ""),
57                 ("Play", "play", ""),
58                 ("Playpause", "playpause", ""),
59                 ("Stop", "stop", ""),
60                 ("Pause", "pause", ""),
61                 ("Rewind", "rewind", ""),
62                 ("Fastforward", "fastforward", ""),
63                 ("Skip back", "skip_back", ""),
64                 ("Skip forward", "skip_forward", ""),
65                 ("activatePiP", "activatePiP", ""),
66                 ("Timer", "timer", ""),
67                 ("Timer" + " " + _("long"), "timer_long", ""),
68                 ("Playlist", "playlist", ""),
69                 ("Timeshift", "timeshift", ""),
70                 ("Search", "search", ""),
71                 ("Search" + " " + _("long"), "search_long", ""),
72                 ("Slow", "slow", ""),
73                 ("Mark/Portal/Playlist", "mark", ""),
74                 ("Mark/Portal/Playlist" + " " + _("long"), "mark_long", ""),
75                 ("Sleep", "sleep", ""),
76                 ("Sleep" + " " + _("long"), "sleep_long", ""),
77                 ("Context", "contextmenu", ""),
78                 ("Context" + " " + _("long"), "contextmenu_long", ""),
79                 ("Video Mode", "vmode", ""),
80                 ("Video Mode" + " " + _("long"), "vmode_long", ""),
81                 ("Home", "home", ""),
82                 ("Power", "power", ""),
83                 ("Power" + " " + _("long"), "power_long", ""),
84                 ("HDMIin", "HDMIin", "Infobar/HDMIIn"),
85                 ("HDMIin" + " " + _("long"), "HDMIin_long", SystemInfo["LcdLiveTV"] and "Infobar/ToggleLCDLiveTV" or "")]
86
87 config.misc.hotkey = ConfigSubsection()
88 config.misc.hotkey.additional_keys = ConfigYesNo(default=False)
89 for x in getHotkeys():
90         exec "config.misc.hotkey." + x[1] + " = ConfigText(default='" + x[2] + "')"
91
92 def getHotkeyFunctions():
93         hotkeyFunctions = []
94         twinPlugins = []
95         twinPaths = {}
96         pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_EVENTINFO)
97         pluginlist.sort(key=lambda p: p.name)
98         for plugin in pluginlist:
99                 if plugin.name not in twinPlugins and plugin.path and 'selectedevent' not in plugin.__call__.func_code.co_varnames:
100                         if twinPaths.has_key(plugin.path[24:]):
101                                 twinPaths[plugin.path[24:]] += 1
102                         else:
103                                 twinPaths[plugin.path[24:]] = 1
104                         hotkeyFunctions.append((plugin.name, plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) , "EPG"))
105                         twinPlugins.append(plugin.name)
106         pluginlist = plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU])
107         pluginlist.sort(key=lambda p: p.name)
108         for plugin in pluginlist:
109                 if plugin.name not in twinPlugins and plugin.path:
110                         if twinPaths.has_key(plugin.path[24:]):
111                                 twinPaths[plugin.path[24:]] += 1
112                         else:
113                                 twinPaths[plugin.path[24:]] = 1
114                         hotkeyFunctions.append((plugin.name, plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) , "Plugins"))
115                         twinPlugins.append(plugin.name)
116         hotkeyFunctions.append((_("Main menu"), "Infobar/mainMenu", "InfoBar"))
117         hotkeyFunctions.append((_("Show help"), "Infobar/showHelp", "InfoBar"))
118         hotkeyFunctions.append((_("Show extension selection"), "Infobar/showExtensionSelection", "InfoBar"))
119         hotkeyFunctions.append((_("Zap down"), "Infobar/zapDown", "InfoBar"))
120         hotkeyFunctions.append((_("Zap up"), "Infobar/zapUp", "InfoBar"))
121         hotkeyFunctions.append((_("Switch channel up"), "Infobar/switchChannelUp", "InfoBar"))
122         hotkeyFunctions.append((_("Switch channel down"), "Infobar/switchChannelDown", "InfoBar"))
123         hotkeyFunctions.append((_("Show service list"), "Infobar/openServiceList", "InfoBar"))
124         hotkeyFunctions.append((_("Show movies"), "Infobar/showMovies", "InfoBar"))
125         hotkeyFunctions.append((_("Show servicelist or movies"), "Infobar/showServiceListOrMovies", "InfoBar"))
126         hotkeyFunctions.append((_("Show favourites list"), "Infobar/openFavouritesList", "InfoBar"))
127         hotkeyFunctions.append((_("History back"), "Infobar/historyBack", "InfoBar"))
128         hotkeyFunctions.append((_("History next"), "Infobar/historyNext", "InfoBar"))
129         hotkeyFunctions.append((_("Recall to previous service"), "Infobar/servicelist/recallPrevService", "InfoBar"))
130         hotkeyFunctions.append((_("Show eventinfo plugins"), "Infobar/showEventInfoPlugins", "EPG"))
131         hotkeyFunctions.append((_("Show event details"), "Infobar/openEventView", "EPG"))
132         hotkeyFunctions.append((_("Show single service EPG"), "Infobar/openSingleServiceEPG", "EPG"))
133         hotkeyFunctions.append((_("Show multi channel EPG"), "Infobar/openMultiServiceEPG", "EPG"))
134         hotkeyFunctions.append((_("Show Audioselection"), "Infobar/audioSelection", "InfoBar"))
135         hotkeyFunctions.append((_("Switch to radio mode"), "Infobar/showRadio", "InfoBar"))
136         hotkeyFunctions.append((_("Switch to TV mode"), "Infobar/showTv", "InfoBar"))
137         hotkeyFunctions.append((_("Instant record"), "Infobar/instantRecord", "InfoBar"))
138         hotkeyFunctions.append((_("Start instant recording"), "Infobar/startInstantRecording", "InfoBar"))
139         hotkeyFunctions.append((_("Activate timeshift End"), "Infobar/activateTimeshiftEnd", "InfoBar"))
140         hotkeyFunctions.append((_("Activate timeshift end and pause"), "Infobar/activateTimeshiftEndAndPause", "InfoBar"))
141         hotkeyFunctions.append((_("Start timeshift"), "Infobar/startTimeshift", "InfoBar"))
142         hotkeyFunctions.append((_("Stop timeshift"), "Infobar/stopTimeshift", "InfoBar"))
143         hotkeyFunctions.append((_("Start teletext"), "Infobar/startTeletext", "InfoBar"))
144         hotkeyFunctions.append((_("Show subservice selection"), "Infobar/subserviceSelection", "InfoBar"))
145         hotkeyFunctions.append((_("Show subtitle selection"), "Infobar/subtitleSelection", "InfoBar"))
146         hotkeyFunctions.append((_("Show InfoBar"), "Infobar/showFirstInfoBar", "InfoBar"))
147         hotkeyFunctions.append((_("Show second InfoBar"), "Infobar/showSecondInfoBar", "InfoBar"))
148         hotkeyFunctions.append((_("Toggle infoBar"), "Infobar/toggleShow", "InfoBar"))
149         hotkeyFunctions.append((_("Letterbox zoom"), "Infobar/vmodeSelection", "InfoBar"))
150         if SystemInfo["PIPAvailable"]:
151                 hotkeyFunctions.append((_("Show PIP"), "Infobar/showPiP", "InfoBar"))
152                 hotkeyFunctions.append((_("Swap PIP"), "Infobar/swapPiP", "InfoBar"))
153                 hotkeyFunctions.append((_("Move PIP"), "Infobar/movePiP", "InfoBar"))
154                 hotkeyFunctions.append((_("Toggle PIPzap"), "Infobar/togglePipzap", "InfoBar"))
155         hotkeyFunctions.append((_("Activate HbbTV (Redbutton)"), "Infobar/activateRedButton", "InfoBar"))
156         hotkeyFunctions.append((_("Toggle HDMI In"), "Infobar/HDMIIn", "InfoBar"))
157         if SystemInfo["LcdLiveTV"]:
158                 hotkeyFunctions.append((_("Toggle LCD LiveTV"), "Infobar/ToggleLCDLiveTV", "InfoBar"))
159         hotkeyFunctions.append((_("Do nothing"), "Void", "InfoBar"))
160         hotkeyFunctions.append((_("HotKey Setup"), "Module/Screens.Hotkey/HotkeySetup", "Setup"))
161         hotkeyFunctions.append((_("Software update"), "Module/Screens.SoftwareUpdate/UpdatePlugin", "Setup"))
162         hotkeyFunctions.append((_("Latest Commits"), "Module/Screens.About/CommitInfo", "Setup"))
163         hotkeyFunctions.append((_("CI (Common Interface) Setup"), "Module/Screens.Ci/CiSelection", "Setup"))
164         hotkeyFunctions.append((_("Tuner Configuration"), "Module/Screens.Satconfig/NimSelection", "Scanning"))
165         hotkeyFunctions.append((_("Manual Scan"), "Module/Screens.ScanSetup/ScanSetup", "Scanning"))
166         hotkeyFunctions.append((_("Automatic Scan"), "Module/Screens.ScanSetup/ScanSimple", "Scanning"))
167         for plugin in plugins.getPluginsForMenu("scan"):
168                 hotkeyFunctions.append((plugin[0], "MenuPlugin/scan/" + plugin[2], "Scanning"))
169         hotkeyFunctions.append((_("Network"), "Module/Screens.NetworkSetup/NetworkAdapterSelection", "Setup"))
170         hotkeyFunctions.append((_("Plugin Browser"), "Module/Screens.PluginBrowser/PluginBrowser", "Setup"))
171         hotkeyFunctions.append((_("Sleeptimer edit"), "Module/Screens.SleepTimerEdit/SleepTimerEdit", "Setup"))
172         hotkeyFunctions.append((_("Channel Info"), "Module/Screens.ServiceInfo/ServiceInfo", "Setup"))
173         hotkeyFunctions.append((_("Timer"), "Module/Screens.TimerEdit/TimerEditList", "Setup"))
174         for plugin in plugins.getPluginsForMenu("system"):
175                 if plugin[2]:
176                         hotkeyFunctions.append((plugin[0], "MenuPlugin/system/" + plugin[2], "Setup"))
177         hotkeyFunctions.append((_("Standby"), "Module/Screens.Standby/Standby", "Power"))
178         hotkeyFunctions.append((_("Restart"), "Module/Screens.Standby/TryQuitMainloop/2", "Power"))
179         hotkeyFunctions.append((_("Restart enigma"), "Module/Screens.Standby/TryQuitMainloop/3", "Power"))
180         hotkeyFunctions.append((_("Deep standby"), "Module/Screens.Standby/TryQuitMainloop/1", "Power"))
181         hotkeyFunctions.append((_("Usage Setup"), "Setup/usage", "Setup"))
182         hotkeyFunctions.append((_("User interface"), "Setup/userinterface", "Setup"))
183         hotkeyFunctions.append((_("Recording Setup"), "Setup/recording", "Setup"))
184         hotkeyFunctions.append((_("Harddisk Setup"), "Setup/harddisk", "Setup"))
185         hotkeyFunctions.append((_("Subtitles Settings"), "Setup/subtitlesetup", "Setup"))
186         hotkeyFunctions.append((_("Language"), "Module/Screens.LanguageSelection/LanguageSelection", "Setup"))
187         hotkeyFunctions.append((_("Skin setup"), "Module/Screens.SkinSelector/SkinSelector", "Setup"))
188         hotkeyFunctions.append((_("Memory Info"), "Module/Screens.About/MemoryInfo", "Setup"))
189         if os.path.isdir("/etc/ppanels"):
190                 for x in [x for x in os.listdir("/etc/ppanels") if x.endswith(".xml")]:
191                         x = x[:-4]
192                         hotkeyFunctions.append((_("PPanel") + " " + x, "PPanel/" + x, "PPanels"))
193         if os.path.isdir("/usr/script"):
194                 for x in [x for x in os.listdir("/usr/script") if x.endswith(".sh")]:
195                         x = x[:-3]
196                         hotkeyFunctions.append((_("Shellscript") + " " + x, "Shellscript/" + x, "Shellscripts"))
197         return hotkeyFunctions
198
199 class HotkeySetup(Screen):
200         def __init__(self, session, args=None):
201                 Screen.__init__(self, session)
202                 self.session = session
203                 self.setTitle(_("Hotkey Setup"))
204                 self["key_red"] = Button(_("Exit"))
205                 self["key_green"] = Button(_("Toggle Extra Keys"))
206                 self.list = []
207                 self.hotkeys = getHotkeys()
208                 self.hotkeyFunctions = getHotkeyFunctions()
209                 for x in self.hotkeys:
210                         self.list.append(ChoiceEntryComponent('',(x[0], x[1])))
211                 self["list"] = ChoiceList(list=self.list[:config.misc.hotkey.additional_keys.value and len(self.hotkeys) or 10], selection = 0)
212                 self["choosen"] = ChoiceList(list=[])
213                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "MenuActions"],
214                 {
215                         "ok": self.keyOk,
216                         "cancel": self.close,
217                         "red": self.close,
218                         "green": self.toggleAdditionalKeys,
219                         "up": self.keyUp,
220                         "down": self.keyDown,
221                         "left": self.keyLeft,
222                         "right": self.keyRight,
223                         "menu": boundFunction(self.close, True),
224                 }, -1)
225                 self["NumberActions"] = NumberActionMap(["NumberActions"],
226                 {
227                         "0": self.keyNumberGlobal
228                 })
229                 self["HotkeyButtonActions"] = hotkeyActionMap(["HotkeyActions"], dict((x[1], self.hotkeyGlobal) for x in self.hotkeys))
230                 self.longkeyPressed = False
231                 self.onLayoutFinish.append(self.__layoutFinished)
232                 self.onExecBegin.append(self.getFunctions)
233
234         def __layoutFinished(self):
235                 self["choosen"].selectionEnabled(0)
236
237         def hotkeyGlobal(self, key):
238                 if self.longkeyPressed:
239                         self.longkeyPressed = False
240                 else:
241                         index = 0
242                         for x in self.list[:config.misc.hotkey.additional_keys.value and len(self.hotkeys) or 10]:
243                                 if key == x[0][1]:
244                                         self["list"].moveToIndex(index)
245                                         if key.endswith("_long"):
246                                                 self.longkeyPressed = True
247                                         break
248                                 index += 1
249                         self.getFunctions()
250
251         def keyOk(self):
252                 self.session.openWithCallback(self.HotkeySetupSelectCallback, HotkeySetupSelect, self["list"].l.getCurrentSelection())
253
254         def HotkeySetupSelectCallback(self, answer):
255                 if answer:
256                         self.close(True)
257
258         def keyLeft(self):
259                 self["list"].instance.moveSelection(self["list"].instance.pageUp)
260                 self.getFunctions()
261
262         def keyRight(self):
263                 self["list"].instance.moveSelection(self["list"].instance.pageDown)
264                 self.getFunctions()
265
266         def keyUp(self):
267                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
268                 self.getFunctions()
269
270         def keyDown(self):
271                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
272                 self.getFunctions()
273
274         def setDefaultHotkey(self, answer):
275                 if answer:
276                         for x in getHotkeys():
277                                 current_config = eval("config.misc.hotkey." + x[1])
278                                 current_config.value = str(x[2])
279                                 current_config.save()
280                         self.getFunctions()
281
282         def keyNumberGlobal(self, number):
283                 self.session.openWithCallback(self.setDefaultHotkey, MessageBox, _("Set all hotkey to default?"), MessageBox.TYPE_YESNO)
284
285         def toggleAdditionalKeys(self):
286                 config.misc.hotkey.additional_keys.value = not config.misc.hotkey.additional_keys.value
287                 config.misc.hotkey.additional_keys.save()
288                 self["list"].setList(self.list[:config.misc.hotkey.additional_keys.value and len(self.hotkeys) or 10])
289
290         def getFunctions(self):
291                 key = self["list"].l.getCurrentSelection()[0][1]
292                 if key:
293                         selected = []
294                         for x in eval("config.misc.hotkey." + key + ".value.split(',')"):
295                                 if x.startswith("ZapPanic"):
296                                         selected.append(ChoiceEntryComponent('',((_("Panic to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
297                                 elif x.startswith("Zap"):
298                                         selected.append(ChoiceEntryComponent('',((_("Zap to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
299                                 else:
300                                         function = list(function for function in self.hotkeyFunctions if function[1] == x )
301                                         if function:
302                                                 selected.append(ChoiceEntryComponent('',((function[0][0]), function[0][1])))
303                         self["choosen"].setList(selected)
304
305 class HotkeySetupSelect(Screen):
306         def __init__(self, session, key, args=None):
307                 Screen.__init__(self, session)
308                 self.skinName="HotkeySetup"
309                 self.session = session
310                 self.key = key
311                 self.setTitle(_("Hotkey Setup") + " " + key[0][0])
312                 self["key_red"] = Button(_("Cancel"))
313                 self["key_green"] = Button(_("Save"))
314                 self.mode = "list"
315                 self.hotkeyFunctions = getHotkeyFunctions()
316                 self.config = eval("config.misc.hotkey." + key[0][1])
317                 self.expanded = []
318                 self.selected = []
319                 for x in self.config.value.split(','):
320                         if x.startswith("ZapPanic"):
321                                 self.selected.append(ChoiceEntryComponent('',((_("Panic to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
322                         elif x.startswith("Zap"):
323                                 self.selected.append(ChoiceEntryComponent('',((_("Zap to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
324                         else:
325                                 function = list(function for function in self.hotkeyFunctions if function[1] == x )
326                                 if function:
327                                         self.selected.append(ChoiceEntryComponent('',((function[0][0]), function[0][1])))
328                 self.prevselected = self.selected[:]
329                 self["choosen"] = ChoiceList(list=self.selected, selection=0)
330                 self["list"] = ChoiceList(list=self.getFunctionList(), selection=0)
331                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "KeyboardInputActions", "MenuActions"],
332                 {
333                         "ok": self.keyOk,
334                         "cancel": self.cancel,
335                         "red": self.cancel,
336                         "green": self.save,
337                         "up": self.keyUp,
338                         "down": self.keyDown,
339                         "left": self.keyLeft,
340                         "right": self.keyRight,
341                         "upRepeated": self.keyUp,
342                         "downRepeated": self.keyDown,
343                         "leftRepeated": self.keyLeft,
344                         "rightRepeated": self.keyRight,
345                         "pageUp": self.toggleMode,
346                         "pageDown": self.toggleMode,
347                         "moveUp": self.moveUp,
348                         "moveDown": self.moveDown,
349                         "menu": boundFunction(self.close, True),
350                 }, -1)
351                 self.onLayoutFinish.append(self.__layoutFinished)
352
353         def __layoutFinished(self):
354                 self["choosen"].selectionEnabled(0)
355
356         def getFunctionList(self):
357                 functionslist = []
358                 catagories = {}
359                 for function in self.hotkeyFunctions:
360                         if not catagories.has_key(function[2]):
361                                 catagories[function[2]] = []
362                         catagories[function[2]].append(function)
363                 for catagorie in sorted(list(catagories)):
364                         if catagorie in self.expanded:
365                                 functionslist.append(ChoiceEntryComponent('expanded',((catagorie), "Expander")))
366                                 for function in catagories[catagorie]:
367                                         functionslist.append(ChoiceEntryComponent('verticalline',((function[0]), function[1])))
368                                 if catagorie == "InfoBar":
369                                         functionslist.append(ChoiceEntryComponent('verticalline',((_("Zap to")), "Zap")))
370                                         functionslist.append(ChoiceEntryComponent('verticalline',((_("Panic to")), "ZapPanic")))
371                         else:
372                                 functionslist.append(ChoiceEntryComponent('expandable',((catagorie), "Expander")))
373                 return functionslist
374
375         def toggleMode(self):
376                 if self.mode == "list" and self.selected:
377                         self.mode = "choosen"
378                         self["choosen"].selectionEnabled(1)
379                         self["list"].selectionEnabled(0)
380                 elif self.mode == "choosen":
381                         self.mode = "list"
382                         self["choosen"].selectionEnabled(0)
383                         self["list"].selectionEnabled(1)
384
385         def keyOk(self):
386                 if self.mode == "list":
387                         currentSelected = self["list"].l.getCurrentSelection()
388                         if currentSelected[0][1] == "Expander":
389                                 if currentSelected[0][0] in self.expanded:
390                                         self.expanded.remove(currentSelected[0][0])
391                                 else:
392                                         self.expanded.append(currentSelected[0][0])
393                                 self["list"].setList(self.getFunctionList())
394                         else:
395                                 if currentSelected[:2] in self.selected:
396                                         self.selected.remove(currentSelected[:2])
397                                 else:
398                                         if currentSelected[0][1].startswith("ZapPanic"):
399                                                 from Screens.ChannelSelection import SimpleChannelSelection
400                                                 self.session.openWithCallback(self.zaptoCallback, SimpleChannelSelection, _("Hotkey Panic") + " " + self.key[0][0], currentBouquet=True)
401                                         elif currentSelected[0][1].startswith("Zap"):
402                                                 from Screens.ChannelSelection import SimpleChannelSelection
403                                                 self.session.openWithCallback(self.zaptoCallback, SimpleChannelSelection, _("Hotkey zap") + " " + self.key[0][0], currentBouquet=True)
404                                         else:
405                                                 self.selected.append(currentSelected[:2])
406                 elif self.selected:
407                         self.selected.remove(self["choosen"].l.getCurrentSelection())
408                         if not self.selected:
409                                 self.toggleMode()
410                 self["choosen"].setList(self.selected)
411
412         def zaptoCallback(self, *args):
413                 if args:
414                         currentSelected = self["list"].l.getCurrentSelection()[:]
415                         currentSelected[1]=currentSelected[1][:-1] + (currentSelected[0][0] + " " + ServiceReference(args[0]).getServiceName(),)
416                         self.selected.append([(currentSelected[0][0], currentSelected[0][1] + "/" + args[0].toString()), currentSelected[1]])
417
418         def keyLeft(self):
419                 self[self.mode].instance.moveSelection(self[self.mode].instance.pageUp)
420
421         def keyRight(self):
422                 self[self.mode].instance.moveSelection(self[self.mode].instance.pageDown)
423
424         def keyUp(self):
425                 self[self.mode].instance.moveSelection(self[self.mode].instance.moveUp)
426
427         def keyDown(self):
428                 self[self.mode].instance.moveSelection(self[self.mode].instance.moveDown)
429
430         def moveUp(self):
431                 self.moveChoosen(self.keyUp)
432
433         def moveDown(self):
434                 self.moveChoosen(self.keyDown)
435
436         def moveChoosen(self, direction):
437                 if self.mode == "choosen":
438                         currentIndex = self["choosen"].getSelectionIndex()
439                         swapIndex = (currentIndex + (direction == self.keyDown and 1 or -1)) % len(self["choosen"].list)
440                         self["choosen"].list[currentIndex], self["choosen"].list[swapIndex] = self["choosen"].list[swapIndex], self["choosen"].list[currentIndex]
441                         self["choosen"].setList(self["choosen"].list)
442                         direction()
443                 else:
444                         return 0
445
446         def save(self):
447                 configValue = []
448                 for x in self.selected:
449                         configValue.append(x[0][1])
450                 self.config.value = ",".join(configValue)
451                 self.config.save()
452                 self.close(False)
453
454         def cancel(self):
455                 if self.selected != self.prevselected:
456                         self.session.openWithCallback(self.cancelCallback, MessageBox, _("are you sure to cancel all changes"), default=False)
457                 else:
458                         self.close(None)
459
460         def cancelCallback(self, answer):
461                 answer and self.close(None)
462
463 class hotkeyActionMap(ActionMap):
464         def action(self, contexts, action):
465                 if (action in tuple(x[1] for x in getHotkeys()) and self.actions.has_key(action)):
466                         res = self.actions[action](action)
467                         if res is not None:
468                                 return res
469                         return 1
470                 else:
471                         return ActionMap.action(self, contexts, action)
472
473 class helpableHotkeyActionMap(HelpableActionMap):
474         def action(self, contexts, action):
475                 if (action in tuple(x[1] for x in getHotkeys()) and self.actions.has_key(action)):
476                         res = self.actions[action](action)
477                         if res is not None:
478                                 return res
479                         return 1
480                 else:
481                         return ActionMap.action(self, contexts, action)
482
483 class InfoBarHotkey():
484         def __init__(self):
485                 self.hotkeys = getHotkeys()
486                 self["HotkeyButtonActions"] = helpableHotkeyActionMap(self, "HotkeyActions",
487                         dict((x[1],(self.hotkeyGlobal, boundFunction(self.getHelpText, x[1]))) for x in self.hotkeys), -10)
488                 self.onExecBegin.append(self.clearLongkeyPressed)
489
490         def clearLongkeyPressed(self):
491                 self.longkeyPressed = False
492
493         def getKeyFunctions(self, key):
494                 if key in ("play", "playpause", "Stop", "stop", "pause", "rewind", "next", "previous", "fastforward", "skip_back", "skip_forward") and (self.__class__.__name__ == "MoviePlayer" or hasattr(self, "timeshiftActivated") and self.timeshiftActivated()):
495                         return False
496                 selection = eval("config.misc.hotkey." + key + ".value.split(',')")
497                 selected = []
498                 for x in selection:
499                         if x.startswith("ZapPanic"):
500                                 selected.append(((_("Panic to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x))
501                         elif x.startswith("Zap"):
502                                 selected.append(((_("Zap to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x))
503                         else:
504                                 function = list(function for function in getHotkeyFunctions() if function[1] == x )
505                                 if function:
506                                         selected.append(function[0])
507                 return selected
508
509         def getHelpText(self, key):
510                 selected = self.getKeyFunctions(key)
511                 if not selected:
512                         return
513                 if len(selected) == 1:
514                         return selected[0][0]
515                 else:
516                         return _("Hotkey") + " " + tuple(x[0] for x in self.hotkeys if x[1] == key)[0]
517
518         def hotkeyGlobal(self, key):
519                 if self.longkeyPressed:
520                         self.longkeyPressed = False
521                 else:
522                         selected = self.getKeyFunctions(key)
523                         if not selected:
524                                 return 0
525                         elif len(selected) == 1:
526                                 self.longkeyPressed = key.endswith("_long")
527                                 return self.execHotkey(selected[0])
528                         else:
529                                 key = tuple(x[0] for x in self.hotkeys if x[1] == key)[0]
530                                 self.session.openWithCallback(self.execHotkey, ChoiceBox, _("Hotkey") + " " + key, selected)
531
532         def execHotkey(self, selected):
533                 if selected:
534                         selected = selected[1].split("/")
535                         if selected[0] == "Plugins":
536                                 twinPlugins = []
537                                 twinPaths = {}
538                                 pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_EVENTINFO)
539                                 pluginlist.sort(key=lambda p: p.name)
540                                 for plugin in pluginlist:
541                                         if plugin.name not in twinPlugins and plugin.path and 'selectedevent' not in plugin.__call__.func_code.co_varnames:
542                                                 if twinPaths.has_key(plugin.path[24:]):
543                                                         twinPaths[plugin.path[24:]] += 1
544                                                 else:
545                                                         twinPaths[plugin.path[24:]] = 1
546                                                 if plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) == "/".join(selected):
547                                                         self.runPlugin(plugin)
548                                                         return
549                                                 twinPlugins.append(plugin.name)
550                                 pluginlist = plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU])
551                                 pluginlist.sort(key=lambda p: p.name)
552                                 for plugin in pluginlist:
553                                         if plugin.name not in twinPlugins and plugin.path:
554                                                 if twinPaths.has_key(plugin.path[24:]):
555                                                         twinPaths[plugin.path[24:]] += 1
556                                                 else:
557                                                         twinPaths[plugin.path[24:]] = 1
558                                                 if plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) == "/".join(selected):
559                                                         self.runPlugin(plugin)
560                                                         return
561                                                 twinPlugins.append(plugin.name)
562                         elif selected[0] == "MenuPlugin":
563                                 for plugin in plugins.getPluginsForMenu(selected[1]):
564                                         if plugin[2] == selected[2]:
565                                                 self.runPlugin(plugin[1])
566                                                 return
567                         elif selected[0] == "Infobar":
568                                 if hasattr(self, selected[1]):
569                                         exec "self." + ".".join(selected[1:]) + "()"
570                                 else:
571                                         return 0
572                         elif selected[0] == "Module":
573                                 try:
574                                         exec "from " + selected[1] + " import *"
575                                         exec "self.session.open(" + ",".join(selected[2:]) + ")"
576                                 except:
577                                         print "[Hotkey] error during executing module %s, screen %s" % (selected[1], selected[2])
578                         elif selected[0] == "Setup":
579                                 exec "from Screens.Setup import *"
580                                 exec "self.session.open(Setup, \"" + selected[1] + "\")"
581                         elif selected[0].startswith("Zap"):
582                                 if selected[0] == "ZapPanic":
583                                         self.servicelist.history = []
584                                         self.pipShown() and self.showPiP()
585                                 self.servicelist.servicelist.setCurrent(eServiceReference("/".join(selected[1:])))
586                                 self.servicelist.zap(enable_pipzap = True)
587                                 if hasattr(self, "lastservice"):
588                                         self.lastservice = eServiceReference("/".join(selected[1:]))
589                                         self.close()
590                                 else:
591                                         self.show()
592                                 from Screens.MovieSelection import defaultMoviePath
593                                 moviepath = defaultMoviePath()
594                                 if moviepath:
595                                         config.movielist.last_videodir.value = moviepath
596                         elif selected[0] == "PPanel":
597                                 ppanelFileName = '/etc/ppanels/' + selected[1] + ".xml"
598                                 if os.path.isfile(ppanelFileName) and os.path.isdir('/usr/lib/enigma2/python/Plugins/Extensions/PPanel'):
599                                         from Plugins.Extensions.PPanel.ppanel import PPanel
600                                         self.session.open(PPanel, name=selected[1] + ' PPanel', node=None, filename=ppanelFileName, deletenode=None)
601                         elif selected[0] == "Shellscript":
602                                 command = '/usr/script/' + selected[1] + ".sh"
603                                 if os.path.isfile(command) and os.path.isdir('/usr/lib/enigma2/python/Plugins/Extensions/PPanel'):
604                                         from Plugins.Extensions.PPanel.ppanel import Execute
605                                         self.session.open(Execute, selected[1] + " shellscript", None, command)
606
607         def showServiceListOrMovies(self):
608                 if hasattr(self, "openServiceList"):
609                         self.openServiceList()
610                 elif hasattr(self, "showMovies"):
611                         self.showMovies()
612
613         def ToggleLCDLiveTV(self):
614                 config.lcd.showTv.value = not config.lcd.showTv.value