ChoiceBox : fix summarytext.
[vuplus_dvbapp] / lib / python / Screens / ChoiceBox.py
old mode 100644 (file)
new mode 100755 (executable)
index b378f2a..c763280
@@ -1,20 +1,21 @@
-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
+from Components.Sources.StaticText import StaticText
 
 class ChoiceBox(Screen):
-       def __init__(self, session, title = "", list = [], keys = None, selection = 0):
+       def __init__(self, session, title = "", list = [], keys = None, selection = 0, skin_name = []):
                Screen.__init__(self, session)
 
+               if isinstance(skin_name, str):
+                       skin_name = [skin_name]
+               self.skinName = skin_name + ["ChoiceBox"] 
+               self.lcd_xres = None
+               self.lcd_xres=self.readlcdxres()
                self["text"] = Label(title)
                self.list = []
+               self.summarylist = []
                if keys is None:
                        self.__keys = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "red", "green", "yellow", "blue" ] + (len(list) - 10) * [""]
                else:
@@ -27,8 +28,11 @@ class ChoiceBox(Screen):
                        self.list.append(ChoiceEntryComponent(key = strpos, text = x))
                        if self.__keys[pos] != "":
                                self.keymap[self.__keys[pos]] = list[pos]
+                       self.summarylist.append((self.__keys[pos],x[0]))
                        pos += 1
                self["list"] = ChoiceList(list = self.list, selection = selection)
+               self["summary_list"] = StaticText()
+               self.updateSummary()
                                
                self["actions"] = NumberActionMap(["WizardActions", "InputActions", "ColorActions", "DirectionActions"], 
                {
@@ -62,59 +66,83 @@ class ChoiceBox(Screen):
                if len(self["list"].list) > 0:
                        while 1:
                                self["list"].instance.moveSelection(self["list"].instance.moveUp)
+                               self.updateSummary(self["list"].l.getCurrentSelectionIndex())
                                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:
                                self["list"].instance.moveSelection(self["list"].instance.moveDown)
+                               self.updateSummary(self["list"].l.getCurrentSelectionIndex())
                                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.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(None)
+                       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])
+               self.goKey("blue")
+
+       def updateSummary(self, curpos=0):
+               pos = 0
+               summarytext = ""
+               for entry in self.summarylist:
+                       if self.lcd_xres is not None and self.lcd_xres > 140:
+                               if pos > curpos-2 and pos < curpos+5:
+                                       if pos == curpos:
+                                               summarytext += ">"
+                                       else:
+                                               summarytext += entry[0]
+                                       summarytext += ' ' + entry[1] + '\n'
                        else:
-                               self.close(entry)
+                               if pos == curpos:
+                                       summarytext += entry[0]+' '+ entry[1]
+                       pos += 1
+               self["summary_list"].setText(summarytext)
 
        def cancel(self):
                self.close(None)
+
+       def readlcdxres(self):
+               try:
+                       fd = open("/proc/stb/lcd/xres","r")
+                       value = int(fd.read().strip(),16)
+                       fd.close()
+                       return value
+               except:
+                       return None