Example #1
0
    def button_press(self, x, y, button):
        if button == 1:
            active_tasks = self.tw.tasks.filter('+ACTIVE')
            if active_tasks:
                task = active_tasks.get()
                task.stop()
            else:
                tasks = "\n".join("#{id}:[{project}] {desc} | +{tags}".format(
                    id=t['id'],
                    project=t['project'],
                    desc=t['description'],
                    tags=" +".join(t['tags']) or "(untagged)")
                                  for t in sorted(self.tw.tasks.pending(),
                                                  key=lambda x: x['urgency'],
                                                  reverse=True))
                cmd = 'dmenu -p "Start task? >" -fn "Iosevka-10" -sb "#DDDDDD" -sf "#000000" -nb "#000000" -i -l 10 -b'
                try:
                    result = subprocess.run(cmd,
                                            input=tasks,
                                            stdout=subprocess.PIPE,
                                            check=True,
                                            universal_newlines=True,
                                            shell=True)
                    selection = result.stdout
                    match = self.TASK_RE.match(selection)
                    if match:
                        task_id = match.group(1)
                        task = self.tw.tasks.get(id=task_id)
                        task.start()
                    else:
                        options = dict(self.OPTION_RE.findall(selection))
                        tags = self.TAG_RE.findall(selection)
                        descr = self.OPTION_RE.sub('', selection).strip()
                        descr = self.TAG_RE.sub('', descr).strip()
                        task = Task(self.tw, description=descr)
                        if options:
                            for k, v in options.items():
                                task[k] = v
                        if tags:
                            task['tags'] = tags
                        task.save()

                        task.start()
                except subprocess.CalledProcessError:
                    pass
        elif button == 2:
            active_tasks = self.tw.tasks.filter('+ACTIVE')
            if active_tasks:
                task = active_tasks.get()
                if 'ongoing' not in task['tags']:
                    task.done()
                else:
                    task.stop()
        elif button == 3:
            self.tw.execute_command(['sync'])
        super(TaskWarriorWidget, self).button_press(x, y, button)
Example #2
0
 def update(self, idx, description=None, completed=None, due=None):
     if idx is None:
         task = Task(self.taskwarrior)
     else:
         task = self[idx]
     if description is not None:
         task["description"] = description
     if completed is not None:
         if is_task_completed(task):
             if not completed:
                 task["status"] = "pending"
         else:
             if completed:
                 task.done()
     if due is not None:
         task["due"] = due
     if idx is None:
         return self.add(task)
     else:
         return self.commit(idx)
Example #3
0
 def test_resume(self):
     self.start()
     self.assertEquals(interface.do_fsm("stop")[0], "ok")
     self.assertEquals(interface.do_fsm("start")[0], "ok")
     prog = re.compile('started .* left.*')
     self.assertTrue(prog.match(interface.do_fsm("status")[0]))
     self.assertEquals(interface.do_fsm("pause")[0], "ok")
     prog = re.compile('paused .* left.*')
     self.assertTrue(prog.match(interface.do_fsm("status")[0]))
     self.assertEquals(interface.do_fsm("start")[0], "ok")
     self.assertEquals(interface.do_fsm("start")[0], "Already started")
     # test done and resume
     other_task = Task(self.tw, description="task 2 for the test")
     other_task.save()
     uuid2 = other_task['uuid']
     self.assertEquals(
         interface.do_start(dbus.Dictionary({
             'uuid': uuid2,
             'resume': 'No'
         }))[0], "started:" + uuid2)
     prog = re.compile('started .* left.*')
     self.assertTrue(prog.match(interface.do_fsm("status")[0]))
     self.assertEquals(interface.do_fsm("stop")[0], "ok")
     other_task.done()
     self.assertEquals(interface.do_fsm("start")[0], "ok")
     self.assertTrue(prog.match(interface.do_fsm("status")[0]))
     # test delete and resume
     other_task = Task(self.tw, description="task 3 for the test")
     other_task.save()
     uuid2 = other_task['uuid']
     self.assertEquals(
         interface.do_start(dbus.Dictionary({
             'uuid': uuid2,
             'resume': 'No'
         }))[0], "started:" + uuid2)
     prog = re.compile('started .* left.*')
     self.assertTrue(prog.match(interface.do_fsm("status")[0]))
     self.assertEquals(interface.do_fsm("stop")[0], "ok")
     other_task.delete()
     self.assertEquals(interface.do_fsm("start")[0], "ok")
     self.assertTrue(prog.match(interface.do_fsm("status")[0]))