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