Esempio n. 1
0
    def quit(self, menu_item):
        list_of_todos = todotxtio.from_file(self.todo_file)
        for atodo in list_of_todos:
            if 'started_at' in atodo.tags and atodo.tags['started_at']:
                started_at = float(atodo.tags.get('started_at', 0))
                lbhook = plugin_manager.get_list_box_todo_plugin_manager().hook
                just_now = time.time()
                if started_at:
                    total_time = float(atodo.tags.get('total_time', 0)) + time.time() - started_at
                    atodo.tags['started_at'] = '0'
                    atodo.tags['total_time'] = str(total_time)
                    lbhook.after_track_time(
                        todo=atodo,
                        before_started_at=started_at,
                        after_started_at=0,
                        total_time=total_time,
                        just_now=just_now
                    )
                elif not started_at and atodo.completed and started_at:
                    atodo.tags['started_at'] = '0'
                    lbhook.after_track_time(
                        todo=atodo,
                        before_started_at=started_at,
                        after_started_at=0,
                        total_time=None,
                        just_now=just_now
                    )
        todotxtio.to_file(self.todo_file, list_of_todos)

        Gtk.main_quit()
        # If Gtk throws an error or just a warning, main_quit() might not
        # actually close the app
        sys.exit(0)
Esempio n. 2
0
    def after_track_time(self, todo, before_started_at, after_started_at,
                         total_time, just_now):
        """
        This event is fired after user click on one task or close the app with a task started
        Take on account that this event is fired per task and one click may fire this event two times:
        one to finalize previous, other for initialize this
        In the original code only track total time per task. To sum all time inverted in a task
        you need to know when started it and with the current time you can sum time to total time
        With this hook you can know when was started and the total time in one step
        Arguments:
        * todo (todo object. See todotxt.io) Object that hold information
        * before_started_at: Unix time. Last started time
        * after_started_at (float): Unix time. If greater than 0 todo has initialized
                                               else the todo has being finalized
        * total_time: Acumulated time in todo
        * just_now: Unix time. Only one time instance accross call's
        """
        if before_started_at:
            list_of_todos = todotxtio.from_file(self.todo_histoy)
            new_todo_history = todotxtio.Todo(text=todo.text)
            new_todo_history.projects = todo.projects
            new_todo_history.contexts = todo.contexts
            new_todo_history.completed = True
            new_todo_history.tags['started'] = str(before_started_at)
            new_todo_history.tags['ended'] = str(just_now)
            new_todo_history.tags['step_time'] = str(just_now -
                                                     before_started_at)
            new_todo_history.tags['total_time'] = str(todo.tags['total_time'])
            list_of_todos.append(new_todo_history)
            todotxtio.to_file(self.todo_histoy, list_of_todos)

        print('todo: {}, before_started_at: {}, after_started_at: {}, total_time: {}, just_now: {}'.\
              format(todo.text, before_started_at, after_started_at, total_time, just_now))
Esempio n. 3
0
 def on_menu_todo_toggled(self, widget):
     list_of_todos = todotxtio.from_file(self.todo_file)
     list_of_todos[widget.file_index].completed = widget.get_active()
     if widget.get_active():
         creation_date = datetime.datetime.now().strftime('%Y-%m-%d')
         list_of_todos[widget.file_index].completion_date = creation_date 
     else:
         list_of_todos[widget.file_index].completion_date = None
     todotxtio.to_file(self.todo_file, list_of_todos)
     if self.hide_completed:
         widget.hide()
Esempio n. 4
0
 def callback(self, widget):
     addTodoDialog = AddTodoDialog()
     if addTodoDialog.run() == Gtk.ResponseType.ACCEPT:
         todo = addTodoDialog.get_task()
         list_of_todos = todotxtio.from_file(self.todo_file)
         for atodo in list_of_todos:
             if todo.text == atodo.text:
                 return
         list_of_todos.append(todo)
         todotxtio.to_file(self.todo_file, list_of_todos)
         self.load_todos()
     addTodoDialog.destroy()
Esempio n. 5
0
 def on_menu_add_todo_activate(self, widget):
     addTodoDialog = AddTodoDialog(_('Add task'))
     if addTodoDialog.run() == Gtk.ResponseType.ACCEPT:
         todo = addTodoDialog.get_task()
         list_of_todos = todotxtio.from_file(self.todo_file)
         finded = False
         for atodo in list_of_todos:
             if todo.text == atodo.text:
                 finded = True
         if not finded:
             list_of_todos.append(todo)
         todotxtio.to_file(self.todo_file, list_of_todos)
         self.load_todos()
     addTodoDialog.destroy()
Esempio n. 6
0
 def save(self):
     todotxtio.to_file(self.todo_file, self.todos.get_items())
Esempio n. 7
0
 def save(self):
     items = self.todos.get_items()
     self.changed = self.changed or list(
         filter(lambda todo: todo.time_tracked, items))
     if self.changed:
         todotxtio.to_file(self.todo_file, items)