Ejemplo n.º 1
0
Archivo: ui.py Proyecto: Kazade/Tasks
 def update(self):
     """Either add a new task or update an existing one."""
     text = unicode(self.task_edit.text(), 'utf-8')
     if not text:
         # There was no text in the edit field so do nothing.
         return
     if self.item is None:
         # No task was selected, so add a new one.
         task = self.store.new_task(text, tags=extract_tags(text))
         self.add_task(task)
     else:
         # A task was selected, so update it.
         self.update_task_text(text)
     # Clear the current selection.
     self.todo_list.setCurrentRow(-1)
     self.task_edit.clear()
     self.item = None
Ejemplo n.º 2
0
Archivo: ui.py Proyecto: Kazade/Tasks
 def update_task_text(self, text):
     """Edit an existing todo item."""
     item = self.item
     task = item.task
     # Change the task's title to the text in the edit field.
     task.title = text
     # Record the current tags.
     old_tags = set(task.tags) if task.tags else set([])
     # Extract the new tags from the new text.
     new_tags = set(extract_tags(text))
     # Check if the tag filter buttons need updating.
     self.update_tags(item.task.task_id, old_tags, new_tags)
     # Set the tags on the task.
     task.tags = list(new_tags)
     # disconnect the signal temporarily while we change the title
     self.todo_list.itemChanged.disconnect(self.item_changed)
     # Change the text in the UI.
     item.setText(text)
     # reconnect the signal after we changed the title
     self.todo_list.itemChanged.connect(self.item_changed)
     # Save the changed task to the database.
     self.store.save_task(task)
Ejemplo n.º 3
0
 def test_extracts_tags(self):
     """Tags are extracted from the item's text."""
     title = "#buy beer at [liquor store]"
     self.assertEqual(['buy', 'liquor store'], sorted(extract_tags(title)))