Commit e7f1ab2a authored by Bram Schoenmakers's avatar Bram Schoenmakers

Shift focus of a todo item within a column.

parent 4b1bbdb8
...@@ -102,6 +102,7 @@ class UIApplication(CLIApplicationBase): ...@@ -102,6 +102,7 @@ class UIApplication(CLIApplicationBase):
item = (todolist, options) item = (todolist, options)
self.columns.contents.append(item) self.columns.contents.append(item)
self.columns.focus_position = len(self.columns.contents) - 1
def run(self): def run(self):
self.todofile = TodoFile.TodoFile(config().todotxt()) self.todofile = TodoFile.TodoFile(config().todotxt())
......
...@@ -18,7 +18,7 @@ import urwid ...@@ -18,7 +18,7 @@ import urwid
from topydo.ui.TodoWidget import TodoWidget from topydo.ui.TodoWidget import TodoWidget
class TodoListWidget(urwid.WidgetWrap): class TodoListWidget(urwid.LineBox):
def __init__(self, p_view, p_title): def __init__(self, p_view, p_title):
self.view = p_view self.view = p_view
...@@ -27,17 +27,39 @@ class TodoListWidget(urwid.WidgetWrap): ...@@ -27,17 +27,39 @@ class TodoListWidget(urwid.WidgetWrap):
todos = [] todos = []
for todo in self.view.todos: for todo in self.view.todos:
todos.append(('pack', TodoWidget(todo))) todowidget = TodoWidget(todo)
todos.append(('pack', todowidget))
todos.append(urwid.Divider(u'-')) todos.append(urwid.Divider(u'-'))
todo_pile = urwid.Pile(todos) self.todo_pile = urwid.Pile(todos)
pile = urwid.Pile([ pile = urwid.Pile([
(1, title_widget), (1, title_widget),
(1, urwid.Filler(urwid.Divider(u'\u2500'))), (1, urwid.Filler(urwid.Divider(u'\u2500'))),
('weight', 1, urwid.Filler(todo_pile, valign='top')), ('weight', 1, urwid.Filler(self.todo_pile, valign='top')),
]) ])
widget = urwid.LineBox(pile) pile.focus_position = 2
super(TodoListWidget, self).__init__(pile)
def _focus_down(self):
size = len(self.todo_pile.contents)
if self.todo_pile.focus_position < size - 2:
self.todo_pile.focus_position += 2
def _focus_up(self):
if self.todo_pile.focus_position > 1:
self.todo_pile.focus_position -= 2
def keypress(self, p_size, p_key):
if p_key == 'j' or p_key == 'down':
self._focus_down()
elif p_key == 'k' or p_key == 'up':
self._focus_up()
else:
return super(TodoListWidget, self).keypress(p_size, p_key)
super(TodoListWidget, self).__init__(widget) def selectable(self):
return True
...@@ -29,14 +29,18 @@ class TodoWidget(urwid.WidgetWrap): ...@@ -29,14 +29,18 @@ class TodoWidget(urwid.WidgetWrap):
todo_text = todo_text[4:] todo_text = todo_text[4:]
priority_widget = urwid.Text(priority_text) priority_widget = urwid.Text(priority_text)
text_widget = urwid.Text(todo_text) self.text_widget = urwid.Text(todo_text)
columns = urwid.Columns( self.columns = urwid.Columns(
[ [
(3, priority_widget), (3, priority_widget),
('weight', 1, text_widget), ('weight', 1, self.text_widget),
], ],
dividechars=1 dividechars=1
) )
super(TodoWidget, self).__init__(columns) attr = urwid.AttrSpec('black', 'light gray', 16)
self.widget = urwid.AttrMap(self.columns, {}, attr)
super(TodoWidget, self).__init__(self.widget)
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