Commit 7b5d3c52 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Some refactoring in preparation for editing and persisting columns.

parent ea5c6204
......@@ -25,6 +25,8 @@ from topydo.ui.TodoListWidget import TodoListWidget
from topydo.ui.ViewWidget import ViewWidget
from topydo.lib.Config import config
from topydo.lib.Sorter import Sorter
from topydo.lib.Filter import get_filter_list, RelevanceFilter, DependencyFilter
from topydo.lib.View import View
from topydo.lib import TodoFile
from topydo.lib import TodoList
......@@ -54,7 +56,8 @@ class UIApplication(CLIApplicationBase):
# view widget
self.viewwidget = ViewWidget(self.todolist)
urwid.connect_signal(self.viewwidget, 'save', self._create_view)
urwid.connect_signal(self.viewwidget, 'save',
lambda: self._create_view(self.viewwidget.data))
def hide_viewwidget():
self._viewwidget_visible = False
......@@ -168,8 +171,26 @@ class UIApplication(CLIApplicationBase):
# the key is unknown, ignore
pass
def _create_view(self):
self._add_column(self.viewwidget.view, self.viewwidget.title)
def _viewdata_to_view(self, p_data):
"""
Converts a dictionary describing a view to an actual View instance.
"""
sorter = Sorter(p_data['sortexpr'])
filters = []
if not p_data['show_all']:
filters.append(DependencyFilter(self.todolist))
filters.append(RelevanceFilter())
filters += get_filter_list(p_data['filterexpr'])
return View(sorter, filters, self.todolist)
def _create_view(self, p_data):
""" Creates a view from the data entered in the view widget. """
view = self._viewdata_to_view(p_data)
self._add_column(view, p_data['title'])
self._viewwidget_visible = False
def _add_column(self, p_view, p_title):
......
......@@ -17,9 +17,6 @@
import urwid
from six import u
from topydo.lib.Filter import get_filter_list, DependencyFilter, RelevanceFilter
from topydo.lib.Sorter import Sorter
class ViewWidget(urwid.LineBox):
def __init__(self, p_todolist):
self._todolist = p_todolist
......@@ -49,30 +46,21 @@ class ViewWidget(urwid.LineBox):
urwid.register_signal(ViewWidget, ['save', 'close'])
@property
def view(self):
""" Returns a tuple (title, view). """
sorter = Sorter(self.sortedit.edit_text)
filters = []
if self.relevantradio.state == True:
filters.append(DependencyFilter(self._todolist))
filters.append(RelevanceFilter())
filters += get_filter_list(self.filteredit.edit_text.split())
return self._todolist.view(sorter, filters)
@view.setter
def view(self, p_view):
pass # TODO
@property
def title(self):
return self.titleedit.edit_text
@title.setter
def title(self, p_title):
self.titleedit.edit_text = p_title
def data(self):
return {
'title': self.titleedit.edit_text,
'sortexpr': self.sortedit.edit_text,
'filterexpr': self.filteredit.edit_text,
'show_all': self.allradio.state,
}
@data.setter
def data(self, p_data):
self.titleedit.edit_text = p_data['title']
self.sortedit.edit_text = p_data['sortexpr']
self.filteredit.edit_text = p_data['filterexpr']
self.relevantradio.set_state(not p_data['show_all'])
self.allradio.set_state(p_data['show_all'])
def reset(self):
""" Resets the form. """
......
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