Commit a46cb090 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Give todo items the color according to their priority.

parent c8131432
# 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/>.
""" Provides color support suitable for urwid. """
COLOR_MAP = {
'black': 'black',
'red': 'dark red',
'green': 'dark green',
'yellow': 'brown',
'blue': 'dark blue',
'magenta': 'dark magenta',
'cyan': 'dark cyan',
'gray': 'light gray',
'darkgray': 'dark gray',
'light-red': 'light red',
'light-green': 'light green',
'light-yellow': 'yellow',
'light-blue': 'light blue',
'light-magenta': 'light magenta',
'light-cyan': 'light cyan',
'white': 'white',
}
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
from six import text_type, u from six import text_type, u
from topydo.lib.Config import config
from topydo.ui.Colors import COLOR_MAP
import urwid import urwid
class TodoWidget(urwid.WidgetWrap): class TodoWidget(urwid.WidgetWrap):
...@@ -32,8 +35,8 @@ class TodoWidget(urwid.WidgetWrap): ...@@ -32,8 +35,8 @@ class TodoWidget(urwid.WidgetWrap):
# strip the first characters off # strip the first characters off
todo_text = todo_text[4:] todo_text = todo_text[4:]
priority_widget = urwid.Text(priority_text)
id_widget = urwid.Text(text_type(p_number), align='right') id_widget = urwid.Text(text_type(p_number), align='right')
priority_widget = urwid.Text(priority_text)
self.text_widget = urwid.Text(todo_text) self.text_widget = urwid.Text(todo_text)
self.columns = urwid.Columns( self.columns = urwid.Columns(
...@@ -45,11 +48,30 @@ class TodoWidget(urwid.WidgetWrap): ...@@ -45,11 +48,30 @@ class TodoWidget(urwid.WidgetWrap):
dividechars=1 dividechars=1
) )
attr = urwid.AttrSpec('black', 'light gray', 16) self.widget = urwid.AttrMap(
self.widget = urwid.AttrMap(self.columns, {}, attr) self.columns,
self._markup(p_todo, False), # no focus
self._markup(p_todo, True) # focus
)
super(TodoWidget, self).__init__(self.widget) super(TodoWidget, self).__init__(self.widget)
def _markup(self, p_todo, p_focus):
priority_colors = config().priority_colors()
try:
# retrieve the assigned value in the config file
fg_color = priority_colors[p_todo.priority()]
# convert to a color that urwid understands
fg_color = COLOR_MAP[fg_color]
except KeyError:
fg_color = 'black' if p_focus else 'default'
bg_color = 'light gray' if p_focus else 'default'
return urwid.AttrSpec(fg_color, bg_color, 16)
def keypress(self, p_size, p_key): def keypress(self, p_size, p_key):
""" """
Override keypress to prevent the wrapped Columns widget to Override keypress to prevent the wrapped Columns widget to
......
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