Commit 3e7b2479 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Move markup method outside class

parent 3513603a
......@@ -20,6 +20,28 @@ from topydo.ui.Colors import color_map256
import urwid
def _markup(p_todo, p_focus):
"""
Returns an attribute spec for the colors that correspond to the given todo
item.
"""
priority_colors = config().priority_colors()
color_map = color_map256()
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, 256)
class TodoWidget(urwid.WidgetWrap):
def __init__(self, p_todo, p_number):
# pass a None todo list, since we won't use %i or %I here
......@@ -44,29 +66,12 @@ class TodoWidget(urwid.WidgetWrap):
self.widget = urwid.AttrMap(
self.columns,
self._markup(p_todo, False), # no focus
self._markup(p_todo, True) # focus
_markup(p_todo, False), # no focus
_markup(p_todo, True) # focus
)
super().__init__(self.widget)
def _markup(self, p_todo, p_focus):
priority_colors = config().priority_colors()
color_map = color_map256()
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, 256)
def keypress(self, p_size, p_key):
"""
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