Commit d7decafa authored by Jacek Sowiński's avatar Jacek Sowiński

Rename signals and functions dealing with 'mark'

Use rahter 'mark' and 'marked' instead of 'pending' here and try to use
verb-based function names wherever possible.

Also some minor code-style changes suggested by @bram85.
parent 1e2f92a8
...@@ -96,7 +96,7 @@ class UIApplication(CLIApplicationBase): ...@@ -96,7 +96,7 @@ class UIApplication(CLIApplicationBase):
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())
self.pending_todos = [] self.marked_todos = []
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> ')
...@@ -174,7 +174,7 @@ class UIApplication(CLIApplicationBase): ...@@ -174,7 +174,7 @@ class UIApplication(CLIApplicationBase):
Executes a command, given as a string. Executes a command, given as a string.
""" """
if '{}' in p_command: if '{}' in p_command:
todos = ' '.join(self.pending_todos) todos = ' '.join(self.marked_todos)
p_command = p_command.format(todos) p_command = p_command.format(todos)
p_output = p_output or self._output p_output = p_output or self._output
p_command = shlex.split(p_command) p_command = shlex.split(p_command)
...@@ -208,7 +208,7 @@ class UIApplication(CLIApplicationBase): ...@@ -208,7 +208,7 @@ class UIApplication(CLIApplicationBase):
dirty = self.todolist.dirty dirty = self.todolist.dirty
super()._post_execute() super()._post_execute()
if dirty or self.pending_todos: if dirty or self.marked_todos:
self._reset_state() self._reset_state()
def _save_cmd(self, p_cmd, p_execute_signal): def _save_cmd(self, p_cmd, p_execute_signal):
...@@ -230,13 +230,13 @@ class UIApplication(CLIApplicationBase): ...@@ -230,13 +230,13 @@ class UIApplication(CLIApplicationBase):
if '{}' in cmd: if '{}' in cmd:
if not p_todo_id: if not p_todo_id:
p_todo_id = ' '.join(self.pending_todos) p_todo_id = ' '.join(self.marked_todos)
cmd = cmd.format(p_todo_id) cmd = cmd.format(p_todo_id)
self._execute_handler(cmd, output) self._execute_handler(cmd, output)
def _reset_state(self): def _reset_state(self):
self.pending_todos = [] self.marked_todos = []
self._update_all_columns() self._update_all_columns()
def _blur_commandline(self): def _blur_commandline(self):
...@@ -373,8 +373,10 @@ class UIApplication(CLIApplicationBase): ...@@ -373,8 +373,10 @@ class UIApplication(CLIApplicationBase):
urwid.connect_signal(todolist, 'remove_pending_action', self._remove_alarm) urwid.connect_signal(todolist, 'remove_pending_action', self._remove_alarm)
urwid.connect_signal(todolist, 'column_action', self._column_action_handler) urwid.connect_signal(todolist, 'column_action', self._column_action_handler)
urwid.connect_signal(todolist, 'show_keystate', self._print_keystate) urwid.connect_signal(todolist, 'show_keystate', self._print_keystate)
urwid.connect_signal(todolist, 'append_pending_todos', self._pending_todos_handler) urwid.connect_signal(todolist, 'toggle_mark',
urwid.connect_signal(todolist, 'check_pending_todos', self._is_pending) self._process_mark_toggle)
urwid.connect_signal(todolist, 'has_marked_todos',
self._has_marked_todos)
options = self.columns.options( options = self.columns.options(
width_type='given', width_type='given',
...@@ -491,18 +493,20 @@ class UIApplication(CLIApplicationBase): ...@@ -491,18 +493,20 @@ class UIApplication(CLIApplicationBase):
return sz return sz
def _is_pending(self): def _has_marked_todos(self):
if len(self.pending_todos) > 0: return len(self.marked_todos) > 0
return True
else:
return False
def _pending_todos_handler(self, p_todo_id): def _process_mark_toggle(self, p_todo_id):
if p_todo_id not in self.pending_todos: """
self.pending_todos.append(p_todo_id) Adds p_todo_id to marked_todos attribute and returns True if p_todo_id
is not already present. Removes p_todo_id from marked_todos and returns
False otherwise.
"""
if p_todo_id not in self.marked_todos:
self.marked_todos.append(p_todo_id)
return True return True
else: else:
self.pending_todos.remove(p_todo_id) self.marked_todos.remove(p_todo_id)
return False return False
def run(self): def run(self):
......
...@@ -64,8 +64,8 @@ class TodoListWidget(urwid.LineBox): ...@@ -64,8 +64,8 @@ class TodoListWidget(urwid.LineBox):
'repeat_cmd', 'repeat_cmd',
'column_action', 'column_action',
'show_keystate', 'show_keystate',
'append_pending_todos', 'toggle_mark',
'check_pending_todos', 'has_marked_todos',
]) ])
@property @property
...@@ -203,11 +203,11 @@ class TodoListWidget(urwid.LineBox): ...@@ -203,11 +203,11 @@ class TodoListWidget(urwid.LineBox):
def selectable(self): def selectable(self):
return True return True
def _append_pending_todos(self): def _toggle_marked_status(self):
try: try:
todo = self.listbox.focus.todo todo = self.listbox.focus.todo
todo_id = str(self.view.todolist.number(todo)) todo_id = str(self.view.todolist.number(todo))
result = urwid.emit_signal(self, 'append_pending_todos', todo_id) result = urwid.emit_signal(self, 'toggle_mark', todo_id)
attr_spec = {None: markup(todo, result)} attr_spec = {None: markup(todo, result)}
self.listbox.focus.widget.set_attr_map(attr_spec) self.listbox.focus.widget.set_attr_map(attr_spec)
except AttributeError: except AttributeError:
...@@ -228,7 +228,7 @@ class TodoListWidget(urwid.LineBox): ...@@ -228,7 +228,7 @@ class TodoListWidget(urwid.LineBox):
todo = self.listbox.focus.todo todo = self.listbox.focus.todo
todo_id = str(self.view.todolist.number(todo)) todo_id = str(self.view.todolist.number(todo))
result = urwid.emit_signal(self, 'check_pending_todos') result = urwid.emit_signal(self, 'has_marked_todos')
if result: if result:
cmd = p_cmd_str cmd = p_cmd_str
else: else:
...@@ -303,7 +303,7 @@ class TodoListWidget(urwid.LineBox): ...@@ -303,7 +303,7 @@ class TodoListWidget(urwid.LineBox):
elif p_action_str == 'pri': elif p_action_str == 'pri':
pass pass
elif p_action_str == 'mark': elif p_action_str == 'mark':
self._append_pending_todos() self._toggle_marked_status()
elif p_action_str == 'repeat': elif p_action_str == 'repeat':
self._repeat_cmd() self._repeat_cmd()
...@@ -364,7 +364,7 @@ class TodoListWidget(urwid.LineBox): ...@@ -364,7 +364,7 @@ class TodoListWidget(urwid.LineBox):
except AttributeError: except AttributeError:
todo_id = None todo_id = None
result = urwid.emit_signal(self, 'check_pending_todos') result = urwid.emit_signal(self, 'has_marked_todos')
if result: if result:
todo_id = None todo_id = None
urwid.emit_signal(self, 'repeat_cmd', todo_id) urwid.emit_signal(self, 'repeat_cmd', todo_id)
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