fix off-by-one error on the progress and fix vars in ToolExistsPrecondition
[enigma2.git] / lib / python / Components / ConfigList.py
index 7ed6031a7fbc7612e5a26c54c93125f29793b037..9a68d428a32b08f132597dad4167f5235813d0f1 100644 (file)
@@ -1,8 +1,8 @@
 from HTMLComponent import HTMLComponent
 from GUIComponent import GUIComponent
-from config import KEY_LEFT, KEY_RIGHT, KEY_0, KEY_DELETE, KEY_OK, KEY_TIMEOUT, ConfigElement
+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 enigma import eListbox, eListboxPythonConfigContent, eTimer
+from enigma import eListbox, eListboxPythonConfigContent, eRCInput, eTimer
 from Screens.MessageBox import MessageBox
 
 class ConfigList(HTMLComponent, GUIComponent, object):
@@ -14,18 +14,17 @@ class ConfigList(HTMLComponent, GUIComponent, object):
                self.list = list
                self.onSelectionChanged = [ ]
                self.current = None
-               self.help_window = None
-               self.setHelpWindowSession(session)
+               self.session = session
 
        def execBegin(self):
-               self.timer.timeout.get().append(self.timeout)
+               rcinput = eRCInput.getInstance()
+               rcinput.setKeyboardMode(rcinput.kmAscii)
+               self.timer.callback.append(self.timeout)
 
        def execEnd(self):
-               self.timer.timeout.get().remove(self.timeout)
-
-       def setHelpWindowSession(self, session):
-               assert self.help_window is None, "you can't move a help window to another session"
-               self.session = session
+               rcinput = eRCInput.getInstance()
+               rcinput.setKeyboardMode(rcinput.kmNone)
+               self.timer.callback.remove(self.timeout)
 
        def toggle(self):
                selection = self.getCurrent()
@@ -37,9 +36,7 @@ class ConfigList(HTMLComponent, GUIComponent, object):
                if selection and selection[1].enabled:
                        selection[1].handleKey(key)
                        self.invalidateCurrent()
-                       if self.help_window:
-                               self.help_window.update(selection[1])
-                       if key not in [KEY_TIMEOUT, KEY_LEFT, KEY_RIGHT, KEY_DELETE, KEY_OK]:
+                       if key in KEY_NUMBERS:
                                self.timer.start(1000, 1)
 
        def getCurrent(self):
@@ -48,6 +45,10 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        def getCurrentIndex(self):
                return self.l.getCurrentSelectionIndex()
        
+       def setCurrentIndex(self, index):
+               if self.instance is not None:
+                       self.instance.moveSelectionTo(index)
+       
        def invalidateCurrent(self):
                self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
 
@@ -60,26 +61,23 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        GUI_WIDGET = eListbox
        
        def selectionChanged(self):
-               n = self.getCurrent()
-               
-               if self.help_window:
-                       self.session.deleteDialog(self.help_window)
-               
-               nh = n and n[1].helpWindow()
-               if nh is not None and self.session is not None:
-                       self.help_window = self.session.instantiateDialog(*nh)
-                       self.help_window.show()
-
-               self.current = n
+               if self.current:
+                       self.current[1].onDeselect(self.session)
+               self.current = self.getCurrent()
+               if self.current:
+                       self.current[1].onSelect(self.session)
                for x in self.onSelectionChanged:
                        x()
 
        def postWidgetCreate(self, instance):
-               instance.setContent(self.l)
                instance.selectionChanged.get().append(self.selectionChanged)
+               instance.setContent(self.l)
        
        def preWidgetRemove(self, instance):
+               if self.current:
+                       self.current[1].onDeselect(self.session)
                instance.selectionChanged.get().remove(self.selectionChanged)
+               instance.setContent(None)
        
        def setList(self, l):
                self.timer.stop()
@@ -107,12 +105,17 @@ class ConfigList(HTMLComponent, GUIComponent, object):
 
 class ConfigListScreen:
        def __init__(self, list, session = None, on_change = None):
-               self["config_actions"] = NumberActionMap(["SetupActions", "TextInputActions"],
+               self["config_actions"] = NumberActionMap(["SetupActions", "InputAsciiActions", "KeyboardInputActions"],
                {
+                       "gotAsciiCode": self.keyGotAscii,
                        "ok": self.keyOK,
                        "left": self.keyLeft,
                        "right": self.keyRight,
-                       "delete": self.keyDelete,
+                       "home": self.keyHome,
+                       "end": self.keyEnd,
+                       "deleteForward": self.keyDelete,
+                       "deleteBackward": self.keyBackspace,
+                       "toggleOverwrite": self.keyToggleOW,
                        "1": self.keyNumberGlobal,
                        "2": self.keyNumberGlobal,
                        "3": self.keyNumberGlobal,
@@ -142,10 +145,30 @@ class ConfigListScreen:
                self["config"].handleKey(KEY_RIGHT)
                self.__changed()
 
+       def keyHome(self):
+               self["config"].handleKey(KEY_HOME)
+               self.__changed()
+
+       def keyEnd(self):
+               self["config"].handleKey(KEY_END)
+               self.__changed()
+
        def keyDelete(self):
                self["config"].handleKey(KEY_DELETE)
                self.__changed()
 
+       def keyBackspace(self):
+               self["config"].handleKey(KEY_BACKSPACE)
+               self.__changed()
+
+       def keyToggleOW(self):
+               self["config"].handleKey(KEY_TOGGLEOW)
+               self.__changed()
+
+       def keyGotAscii(self):
+               self["config"].handleKey(KEY_ASCII)
+               self.__changed()
+
        def keyNumberGlobal(self, number):
                self["config"].handleKey(KEY_0 + number)
                self.__changed()