+ def refresh(self):
+ self.refresh_list()
+ super(ListView, self).refresh()
+
+ def refresh_list(self):
+ """ Reload the list items. Calls items() again. """
+ # Remember which item was selected
+ selected = self.selected_item()
+ # Refresh the list
+ self.items_cache = self.items()
+ try:
+ # Try to find the selected item in the new list (based on
+ # the display text).
+ selected_index = self.items_cache.index(selected)
+ except ValueError:
+ # If the selected item is no longer present, just keep the
+ # index the same (but be careful not to fall off the end).
+ selected_index = self.clip_index(self.selected_index())
+ # Update the items in the view
+ self.view.set_list(self.items_cache, selected_index)
+