Merge branch 'obi/master'
[enigma2.git] / lib / python / Components / ConfigList.py
old mode 100644 (file)
new mode 100755 (executable)
index d1b295b..24f917f
@@ -1,7 +1,7 @@
 from HTMLComponent import HTMLComponent
 from GUIComponent import GUIComponent
 from HTMLComponent import HTMLComponent
 from GUIComponent import GUIComponent
-from config import KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS, ConfigElement
-from Components.ActionMap import NumberActionMap
+from config import KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS, ConfigElement, ConfigText, ConfigPassword
+from Components.ActionMap import NumberActionMap, ActionMap
 from enigma import eListbox, eListboxPythonConfigContent, eRCInput, eTimer
 from Screens.MessageBox import MessageBox
 
 from enigma import eListbox, eListboxPythonConfigContent, eRCInput, eTimer
 from Screens.MessageBox import MessageBox
 
@@ -9,7 +9,7 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        def __init__(self, list, session = None):
                GUIComponent.__init__(self)
                self.l = eListboxPythonConfigContent()
        def __init__(self, list, session = None):
                GUIComponent.__init__(self)
                self.l = eListboxPythonConfigContent()
-               self.l.setSeperation(100)
+               self.l.setSeperation(200)
                self.timer = eTimer()
                self.list = list
                self.onSelectionChanged = [ ]
                self.timer = eTimer()
                self.list = list
                self.onSelectionChanged = [ ]
@@ -24,7 +24,7 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        def execEnd(self):
                rcinput = eRCInput.getInstance()
                rcinput.setKeyboardMode(rcinput.kmNone)
        def execEnd(self):
                rcinput = eRCInput.getInstance()
                rcinput.setKeyboardMode(rcinput.kmNone)
-               self.timer.timeout.get().remove(self.timeout)
+               self.timer.callback.remove(self.timeout)
 
        def toggle(self):
                selection = self.getCurrent()
 
        def toggle(self):
                selection = self.getCurrent()
@@ -61,11 +61,13 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        GUI_WIDGET = eListbox
        
        def selectionChanged(self):
        GUI_WIDGET = eListbox
        
        def selectionChanged(self):
-               if self.current:
+               if isinstance(self.current,tuple) and len(self.current) == 2:
                        self.current[1].onDeselect(self.session)
                self.current = self.getCurrent()
                        self.current[1].onDeselect(self.session)
                self.current = self.getCurrent()
-               if self.current:
+               if isinstance(self.current,tuple) and len(self.current) == 2:
                        self.current[1].onSelect(self.session)
                        self.current[1].onSelect(self.session)
+               else:
+                       return
                for x in self.onSelectionChanged:
                        x()
 
                for x in self.onSelectionChanged:
                        x()
 
@@ -74,10 +76,11 @@ class ConfigList(HTMLComponent, GUIComponent, object):
                instance.setContent(self.l)
        
        def preWidgetRemove(self, instance):
                instance.setContent(self.l)
        
        def preWidgetRemove(self, instance):
-               if self.current:
+               if isinstance(self.current,tuple) and len(self.current) == 2:
                        self.current[1].onDeselect(self.session)
                instance.selectionChanged.get().remove(self.selectionChanged)
                        self.current[1].onDeselect(self.session)
                instance.selectionChanged.get().remove(self.selectionChanged)
-       
+               instance.setContent(None)
+
        def setList(self, l):
                self.timer.stop()
                self.__list = l
        def setList(self, l):
                self.timer.stop()
                self.__list = l
@@ -85,7 +88,7 @@ class ConfigList(HTMLComponent, GUIComponent, object):
 
                if l is not None:
                        for x in l:
 
                if l is not None:
                        for x in l:
-                               assert isinstance(x[1], ConfigElement), "entry in ConfigList " + str(x[1]) + " must be a ConfigElement"
+                               assert len(x) < 2 or isinstance(x[1], ConfigElement), "entry in ConfigList " + str(x[1]) + " must be a ConfigElement"
 
        def getList(self):
                return self.__list
 
        def getList(self):
                return self.__list
@@ -126,13 +129,52 @@ class ConfigListScreen:
                        "9": self.keyNumberGlobal,
                        "0": self.keyNumberGlobal
                }, -1) # to prevent left/right overriding the listbox
                        "9": self.keyNumberGlobal,
                        "0": self.keyNumberGlobal
                }, -1) # to prevent left/right overriding the listbox
+
+               self["VirtualKB"] = ActionMap(["VirtualKeyboardActions"],
+               {
+                       "showVirtualKeyboard": self.KeyText,
+               }, -2)
+               self["VirtualKB"].setEnabled(False)
                
                self["config"] = ConfigList(list, session = session)
                
                self["config"] = ConfigList(list, session = session)
+               
                if on_change is not None:
                        self.__changed = on_change
                else:
                        self.__changed = lambda: None
                if on_change is not None:
                        self.__changed = on_change
                else:
                        self.__changed = lambda: None
-
+               
+               if not self.handleInputHelpers in self["config"].onSelectionChanged:
+                       self["config"].onSelectionChanged.append(self.handleInputHelpers)
+
+       def handleInputHelpers(self):
+               if self["config"].getCurrent() is not None:
+                       if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
+                               if self.has_key("VKeyIcon"):
+                                       self["VirtualKB"].setEnabled(True)
+                                       self["VKeyIcon"].boolean = True
+                               if self.has_key("HelpWindow"):
+                                       if self["config"].getCurrent()[1].help_window.instance is not None:
+                                               helpwindowpos = self["HelpWindow"].getPosition()
+                                               from enigma import ePoint
+                                               self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
+                       else:
+                               if self.has_key("VKeyIcon"):
+                                       self["VirtualKB"].setEnabled(False)
+                                       self["VKeyIcon"].boolean = False
+               else:
+                       if self.has_key("VKeyIcon"):
+                               self["VirtualKB"].setEnabled(False)
+                               self["VKeyIcon"].boolean = False
+
+       def KeyText(self):
+               from Screens.VirtualKeyBoard import VirtualKeyBoard
+               self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue())
+
+       def VirtualKeyBoardCallback(self, callback = None):
+               if callback is not None and len(callback):
+                       self["config"].getCurrent()[1].setValue(callback)
+                       self["config"].invalidate(self["config"].getCurrent())
+                       
        def keyOK(self):
                self["config"].handleKey(KEY_OK)
 
        def keyOK(self):
                self["config"].handleKey(KEY_OK)
 
@@ -171,12 +213,15 @@ class ConfigListScreen:
        def keyNumberGlobal(self, number):
                self["config"].handleKey(KEY_0 + number)
                self.__changed()
        def keyNumberGlobal(self, number):
                self["config"].handleKey(KEY_0 + number)
                self.__changed()
+               
+       def saveAll(self):
+               for x in self["config"].list:
+                       x[1].save()
 
        # keySave and keyCancel are just provided in case you need them.
        # you have to call them by yourself.
        def keySave(self):
 
        # keySave and keyCancel are just provided in case you need them.
        # you have to call them by yourself.
        def keySave(self):
-               for x in self["config"].list:
-                       x[1].save()
+               self.saveAll()
                self.close()
        
        def cancelConfirm(self, result):
                self.close()
        
        def cancelConfirm(self, result):