Commit a1b35608 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Created an update method for TodoListTest.

parent ca7f7cf4
......@@ -24,15 +24,8 @@ class TodoListWidget(urwid.LineBox):
title_widget = urwid.Filler(urwid.Text(p_title, align='center'))
todos = []
for todo in self.view.todos:
todowidget = TodoWidget(todo)
todos.append(('pack', todowidget))
todos.append(urwid.Divider(u'-'))
self.todo_pile = urwid.Pile(todos)
self.todo_pile = urwid.Pile([])
self.update()
pile = urwid.Pile([
(1, title_widget),
......@@ -44,6 +37,26 @@ class TodoListWidget(urwid.LineBox):
super(TodoListWidget, self).__init__(pile)
def update(self):
"""
Updates the todo list according to the todos in the view associated
with this list.
"""
try:
old_focus_position = self.todo_pile.focus_position
except IndexError:
old_focus_position = 0
items = []
for todo in self.view.todos:
todowidget = TodoWidget(todo)
items.append((todowidget, ('pack', None)))
items.append((urwid.Divider(u'-'), ('weight', 1)))
self.todo_pile.contents = items
self.todo_pile.focus_position = min(old_focus_position, len(items) - 1)
def _focus_down(self):
size = len(self.todo_pile.contents)
if self.todo_pile.focus_position < size - 2:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment