comparison urwid_satext/sat_widgets.py @ 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
comparison
equal deleted inserted replaced
79:33677d99ebdf 80:2d66ac0f4d75
495 display_widget = self.getDisplayWidget() 495 display_widget = self.getDisplayWidget()
496 self._set_w(display_widget) 496 self._set_w(display_widget)
497 self._emit('change') 497 self._emit('change')
498 self.first_display = False 498 self.first_display = False
499 499
500 def selectValue(self, value): 500 def selectValue(self, value, move_focus=True):
501 """Select the first item which has the given value""" 501 """Select the first item which has the given value.
502
503 @param value
504 @param move_focus (boolean): True to move the focus on the selected value,
505 False to leave the focus position unchanged.
506 """
502 self.unselectAll() 507 self.unselectAll()
503 idx = 0 508 idx = 0
504 for widget in self.content: 509 for widget in self.content:
505 if widget.getValue() == value: 510 if widget.getValue() == value:
506 widget.setState(True) 511 widget.setState(True)
507 self.list_box.focus_position = idx 512 if move_focus:
513 self.list_box.focus_position = idx
508 return 514 return
509 idx+=1 515 idx+=1
510 516
511 def selectValues(self, values): 517 def selectValues(self, values, move_focus=True):
512 """Select all the given values""" 518 """Select all the given values.
519
520 @param values [set, list]
521 @param move_focus (boolean): True to move the focus on the last selected value,
522 False to leave the focus position unchanged.
523 """
513 if self.single: 524 if self.single:
514 if values: 525 if values:
515 self.selectValue(values[-1]) 526 self.selectValue(values[-1], move_focus)
516 return 527 return
517 self.unselectAll() 528 self.unselectAll()
518 for value in values: 529 for value in values:
519 idx = 0 530 idx = 0
520 for widget in self.content: 531 for widget in self.content:
521 if widget.getValue() == value: 532 if widget.getValue() == value:
522 widget.setState(True) 533 widget.setState(True)
523 self.list_box.focus_position = idx 534 if move_focus:
535 self.list_box.focus_position = idx
524 idx += 1 536 idx += 1
525 537
526 538
527 class List(urwid.Widget): 539 class List(urwid.Widget):
528 """FlowWidget list, same arguments as GenericList, with an additional one 'max_height'""" 540 """FlowWidget list, same arguments as GenericList, with an additional one 'max_height'"""
565 return self.genericList.getSelectedValues() 577 return self.genericList.getSelectedValues()
566 578
567 def changeValues(self, new_values): 579 def changeValues(self, new_values):
568 return self.genericList.changeValues(new_values) 580 return self.genericList.changeValues(new_values)
569 581
570 def selectValue(self, value): 582 def selectValue(self, value, move_focus):
571 return self.genericList.selectValue(value) 583 return self.genericList.selectValue(value, move_focus)
572 584
573 def selectValues(self, values): 585 def selectValues(self, values, move_focus):
574 return self.genericList.selectValues(values) 586 return self.genericList.selectValues(values, move_focus)
575 587
576 def render(self, size, focus=False): 588 def render(self, size, focus=False):
577 return self.displayWidget(size, focus).render(size, focus) 589 return self.displayWidget(size, focus).render(size, focus)
578 590
579 def rows(self, size, focus=False): 591 def rows(self, size, focus=False):