set voltage before send diseqc command (like DiSEqC spec)
[enigma2.git] / lib / python / Components / ConfigList.py
index 2de075c62f07044cda85e6ea2869658505b6cca9..534459e4e4b9fddcb10a9896d554848a8cf6e1ce 100644 (file)
@@ -3,6 +3,7 @@ from GUIComponent import *
 from config import KEY_LEFT, KEY_RIGHT, KEY_0, KEY_DELETE, KEY_OK, KEY_TIMEOUT, ConfigElement
 from Components.ActionMap import NumberActionMap
 from enigma import eListbox, eListboxPythonConfigContent, eTimer
+from Screens.MessageBox import MessageBox
 
 class ConfigList(HTMLComponent, GUIComponent, object):
        def __init__(self, list, session = None):
@@ -44,11 +45,17 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        def getCurrent(self):
                return self.l.getCurrentSelection()
        
+       def getCurrentIndex(self):
+               return self.l.getCurrentSelectionIndex()
+       
        def invalidateCurrent(self):
                self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
-               
+
        def invalidate(self, entry):
-               self.l.invalidateEntry(self.__list.index(entry))
+               # when the entry to invalidate does not exist, just ignore the request.
+               # this eases up conditional setup screens a lot.
+               if entry in self.__list:
+                       self.l.invalidateEntry(self.__list.index(entry))
 
        GUI_WIDGET = eListbox
        
@@ -91,6 +98,13 @@ class ConfigList(HTMLComponent, GUIComponent, object):
        def timeout(self):
                self.handleKey(KEY_TIMEOUT)
 
+       def isChanged(self):
+               is_changed = False
+               for x in self.list:
+                       is_changed |= x[1].isChanged()
+
+               return is_changed
+
 class ConfigListScreen:
        def __init__(self, list, session = None, on_change = None):
                self["config_actions"] = NumberActionMap(["SetupActions", "TextInputActions"],
@@ -136,3 +150,23 @@ class ConfigListScreen:
                self["config"].handleKey(KEY_0 + number)
                self.__changed()
 
+       # 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.close()
+       
+       def cancelConfirm(self, result):
+               if not result:
+                       return
+
+               for x in self["config"].list:
+                       x[1].cancel()
+               self.close()
+
+       def keyCancel(self):
+               if self["config"].isChanged():
+                       self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
+               else:
+                       self.close()