Commit ca7f7cf4 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Show output and errors of the commands in a new console widget.

parent da3132a9
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2015 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urwid
class ConsoleWidget(urwid.LineBox):
def __init__(self, p_text=""):
urwid.register_signal(ConsoleWidget, ['close'])
self.text = urwid.Text(p_text)
super(ConsoleWidget, self).__init__(self.text)
def keypress(self, p_size, p_key):
if p_key == 'enter' or p_key == 'q' or p_key == 'esc':
urwid.emit_signal(self, 'close')
# don't return the key, 'enter', 'escape' or 'q' are your only escape.
def selectable(self):
return True
def print_text(self, p_text):
self.text.set_text(self.text.text + p_text)
def clear(self):
self.text.set_text("")
...@@ -19,6 +19,7 @@ import urwid ...@@ -19,6 +19,7 @@ import urwid
from topydo.cli.CLIApplicationBase import CLIApplicationBase from topydo.cli.CLIApplicationBase import CLIApplicationBase
from topydo.Commands import get_subcommand from topydo.Commands import get_subcommand
from topydo.ui.CommandLineWidget import CommandLineWidget from topydo.ui.CommandLineWidget import CommandLineWidget
from topydo.ui.ConsoleWidget import ConsoleWidget
from topydo.ui.TodoListWidget import TodoListWidget from topydo.ui.TodoListWidget import TodoListWidget
from topydo.lib.Config import config from topydo.lib.Config import config
from topydo.lib.Sorter import Sorter from topydo.lib.Sorter import Sorter
...@@ -33,10 +34,13 @@ class UIApplication(CLIApplicationBase): ...@@ -33,10 +34,13 @@ class UIApplication(CLIApplicationBase):
self.columns = urwid.Columns([], dividechars=0, min_width=COLUMN_WIDTH) self.columns = urwid.Columns([], dividechars=0, min_width=COLUMN_WIDTH)
self.commandline = CommandLineWidget('topydo> ') self.commandline = CommandLineWidget('topydo> ')
self.console = ConsoleWidget()
urwid.connect_signal(self.commandline, 'blur', urwid.connect_signal(self.commandline, 'blur',
self._blur_commandline) self._blur_commandline)
urwid.connect_signal(self.commandline, 'execute_command', urwid.connect_signal(self.commandline, 'execute_command',
self._execute_input) self._execute_input)
urwid.connect_signal(self.console, 'close', self._hide_console)
self.mainwindow = urwid.Pile([ self.mainwindow = urwid.Pile([
('weight', 1, self.columns), ('weight', 1, self.columns),
...@@ -62,8 +66,8 @@ class UIApplication(CLIApplicationBase): ...@@ -62,8 +66,8 @@ class UIApplication(CLIApplicationBase):
command = subcommand( command = subcommand(
args, args,
self.todolist, self.todolist,
lambda _: None, # TODO output self._output,
lambda _: None, # TODO error self._output,
lambda _: None, # TODO input lambda _: None, # TODO input
) )
...@@ -117,6 +121,27 @@ class UIApplication(CLIApplicationBase): ...@@ -117,6 +121,27 @@ class UIApplication(CLIApplicationBase):
self.columns.contents.append(item) self.columns.contents.append(item)
self.columns.focus_position = len(self.columns.contents) - 1 self.columns.focus_position = len(self.columns.contents) - 1
def _show_console(self):
self.mainwindow.contents.append((self.console, ('pack', None)))
self.mainwindow.focus_position = 2
def _hide_console(self):
if self._console_is_visible():
self.console.clear()
del self.mainwindow.contents[2]
def _console_is_visible(self):
return len(self.mainwindow.contents) == 3
def _print_to_console(self, p_text):
if not self._console_is_visible():
self._show_console()
self.console.print_text(p_text)
def _output(self, p_text):
self._print_to_console(p_text + "\n")
def run(self): def run(self):
self.todofile = TodoFile.TodoFile(config().todotxt()) self.todofile = TodoFile.TodoFile(config().todotxt())
self.todolist = TodoList.TodoList(self.todofile.read()) self.todolist = TodoList.TodoList(self.todofile.read())
......
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