Commit 74288f2c authored by Bram Schoenmakers's avatar Bram Schoenmakers

Complete the highlighted todo by pressing 'x'.

parent 06c2223a
......@@ -39,7 +39,7 @@ class UIApplication(CLIApplicationBase):
urwid.connect_signal(self.commandline, 'blur',
self._blur_commandline)
urwid.connect_signal(self.commandline, 'execute_command',
self._execute_input)
self._execute_handler)
urwid.connect_signal(self.console, 'close', self._hide_console)
self.mainwindow = urwid.Pile([
......@@ -56,9 +56,9 @@ class UIApplication(CLIApplicationBase):
pop_ups=True
)
def _execute_input(self, p_command):
def _execute_handler(self, p_command):
"""
Callback for executing a command that was entered on the command line box.
Executes a command, given as a string.
"""
(subcommand, args) = get_subcommand(p_command.split())
......@@ -110,6 +110,7 @@ class UIApplication(CLIApplicationBase):
def _add_column(self, p_view, p_title):
todolist = TodoListWidget(p_view, p_title)
urwid.connect_signal(todolist, 'execute_command', self._execute_handler)
options = self.columns.options(
width_type='given',
......
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from six import text_type
import urwid
from topydo.ui.TodoWidget import TodoWidget
......@@ -37,6 +38,8 @@ class TodoListWidget(urwid.LineBox):
super(TodoListWidget, self).__init__(pile)
urwid.register_signal(TodoListWidget, ['execute_command'])
def update(self):
"""
Updates the todo list according to the todos in the view associated
......@@ -67,12 +70,25 @@ class TodoListWidget(urwid.LineBox):
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:
dispatch = {
'j': self._focus_down,
'down': self._focus_down,
'k': self._focus_up,
'up': self._focus_up,
'x': self._complete_selected_item,
}
try:
dispatch[p_key]()
except KeyError:
return super(TodoListWidget, self).keypress(p_size, p_key)
def selectable(self):
return True
def _complete_selected_item(self):
todo = self.todo_pile.focus.todo
self.view.todolist.number(todo)
urwid.emit_signal(self, 'execute_command', "do {}".format(
text_type(self.view.todolist.number(todo))))
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