# HG changeset patch # User souliane # Date 1399469497 -7200 # Node ID 2d66ac0f4d75f6b7c4f5df2a79cdbe7b570f9e26 # Parent 33677d99ebdfbfc50a7bb86bc36790b90f0affa1 add move_focus parameter to the methods selectValue(s) of list widgets diff -r 33677d99ebdf -r 2d66ac0f4d75 urwid_satext/sat_widgets.py --- 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)