X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/4abbbe07af12cb550130f51dfe00d667fd7c5f57..9a8c3eab7a0823b5dfc6111f07a04cf05d00b57b:/lib/python/Screens/ChoiceBox.py diff --git a/lib/python/Screens/ChoiceBox.py b/lib/python/Screens/ChoiceBox.py index b378f2ac..b1d74ad5 100644 --- a/lib/python/Screens/ChoiceBox.py +++ b/lib/python/Screens/ChoiceBox.py @@ -1,14 +1,10 @@ -from enigma import * from Screens.Screen import Screen from Screens.MessageBox import MessageBox from Components.ActionMap import NumberActionMap from Components.Label import Label from Components.MenuList import MenuList -from Components.GUIComponent import * from Components.ChoiceList import ChoiceEntryComponent, ChoiceList -import os - class ChoiceBox(Screen): def __init__(self, session, title = "", list = [], keys = None, selection = 0): Screen.__init__(self, session) @@ -64,7 +60,7 @@ class ChoiceBox(Screen): self["list"].instance.moveSelection(self["list"].instance.moveUp) if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == 0: break - + def down(self): if len(self["list"].list) > 0: while 1: @@ -72,49 +68,45 @@ class ChoiceBox(Screen): if self["list"].l.getCurrentSelection()[0][0] != "--" or self["list"].l.getCurrentSelectionIndex() == len(self["list"].list) - 1: break + # runs a number shortcut def keyNumberGlobal(self, number): - print "pressed", number - if self.keymap.has_key(str(number)): - self.close(self.keymap[str(number)]) - + self.goKey(str(number)) + + # runs the current selected entry def go(self): - if len(self["list"].list) > 0: - self.close(self["list"].l.getCurrentSelection()[0]) + cursel = self["list"].l.getCurrentSelection() + if cursel: + self.goEntry(cursel[0]) else: - self.close(None) + self.cancel() + # runs a specific entry + def goEntry(self, entry): + if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC": + # CALLFUNC wants to have the current selection as argument + arg = self["list"].l.getCurrentSelection()[0] + entry[2](arg) + else: + self.close(entry) + + # lookups a key in the keymap, then runs it + def goKey(self, key): + if self.keymap.has_key(key): + entry = self.keymap[key] + self.goEntry(entry) + + # runs a color shortcut def keyRed(self): - if self.keymap.has_key("red"): - entry = self.keymap["red"] - if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC": - entry[2](self["list"].l.getCurrentSelection()[0]) - else: - self.close(entry) + self.goKey("red") def keyGreen(self): - if self.keymap.has_key("green"): - entry = self.keymap["green"] - print entry - if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC": - entry[2](self["list"].l.getCurrentSelection()[0]) - else: - self.close(entry) - + self.goKey("green") + def keyYellow(self): - if self.keymap.has_key("yellow"): - entry = self.keymap["yellow"] - if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC": - entry[2](self["list"].l.getCurrentSelection()[0]) - else: - self.close(entry) + self.goKey("yellow") def keyBlue(self): - if self.keymap.has_key("blue"): - entry = self.keymap["blue"] - if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC": - entry[2](self["list"].l.getCurrentSelection()[0]) - else: - self.close(entry) + self.goKey("blue") def cancel(self): self.close(None)