changeset 80:2d66ac0f4d75

add move_focus parameter to the methods selectValue(s) of list widgets
author souliane <souliane@mailoo.org>
date Wed, 07 May 2014 15:31:37 +0200
parents 33677d99ebdf
children 0ebd13729039
files urwid_satext/sat_widgets.py
diffstat 1 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/urwid_satext/sat_widgets.py	Mon Apr 07 19:58:13 2014 +0200
+++ b/urwid_satext/sat_widgets.py	Wed May 07 15:31:37 2014 +0200
@@ -497,22 +497,33 @@
         self._emit('change')
         self.first_display = False
 
-    def selectValue(self, value):
-        """Select the first item which has the given value"""
+    def selectValue(self, value, move_focus=True):
+        """Select the first item which has the given value.
+
+        @param value
+        @param move_focus (boolean): True to move the focus on the selected value,
+                                     False to leave the focus position unchanged.
+        """
         self.unselectAll()
         idx = 0
         for widget in self.content:
             if widget.getValue() == value:
                 widget.setState(True)
-                self.list_box.focus_position = idx
+                if move_focus:
+                    self.list_box.focus_position = idx
                 return
             idx+=1
 
-    def selectValues(self, values):
-        """Select all the given values"""
+    def selectValues(self, values, move_focus=True):
+        """Select all the given values.
+
+        @param values [set, list]
+        @param move_focus (boolean): True to move the focus on the last selected value,
+                                     False to leave the focus position unchanged.
+        """
         if self.single:
             if values:
-                self.selectValue(values[-1])
+                self.selectValue(values[-1], move_focus)
             return
         self.unselectAll()
         for value in values:
@@ -520,7 +531,8 @@
             for widget in self.content:
                 if widget.getValue() == value:
                     widget.setState(True)
-                    self.list_box.focus_position = idx
+                    if move_focus:
+                        self.list_box.focus_position = idx
                 idx += 1
 
 
@@ -567,11 +579,11 @@
     def changeValues(self, new_values):
         return self.genericList.changeValues(new_values)
 
-    def selectValue(self, value):
-        return self.genericList.selectValue(value)
+    def selectValue(self, value, move_focus):
+        return self.genericList.selectValue(value, move_focus)
 
-    def selectValues(self, values):
-        return self.genericList.selectValues(values)
+    def selectValues(self, values, move_focus):
+        return self.genericList.selectValues(values, move_focus)
 
     def render(self, size, focus=False):
         return self.displayWidget(size, focus).render(size, focus)