Example #1
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))
Example #2
0
    def load_todos(self):
        list_of_todos = todotxtio.from_file(self.todo_file)
        list_of_todos.sort(reverse=False, key=self.sort)

        while self.todos > len(self.menu_todos):
            menuitem = Gtk.CheckMenuItem.new_with_label("")
            menuitem.remove(menuitem.get_child())
            menuitem.add(Gtk.Label.new(""))
            menuitem.get_child().set_use_markup(True)
            self.menu_todos.append(menuitem)
        for i in range(0, min(len(list_of_todos), self.todos)):
            if len(list_of_todos[i].text) > 25:
                content = list_of_todos[i].text[:22] + "..."
            else:
                content = list_of_todos[i].text
            if list_of_todos[i].priority:
                content = "({}) {}".format(list_of_todos[i].priority, content)
            self.menu_todos[i].file_index = i
            self.menu_todos[i].set_label(content)
            self.menu_todos[i].set_active(list_of_todos[i].completed)
            self.menu_todos[i].connect("toggled", self.on_menu_todo_toggled)
            hide_by_project = False
            if self.filter_projects:
                if (not set(list_of_todos[i].projects).isdisjoint(
                        self.get_project_showed())
                        or not list_of_todos[i].projects):
                    self.menu_todos[i].show()
                else:
                    self.menu_todos[i].hide()
                    hide_by_project = True

            hide_by_context = False
            if self.filter_contexts:
                if (not set(list_of_todos[i].contexts).isdisjoint(
                        self.get_context_showed()) or
                        not list_of_todos[i].contexts) and not hide_by_project:
                    self.menu_todos[i].show()
                else:
                    self.menu_todos[i].hide()
                    hide_by_context = True

            if not hide_by_project:
                if self.hide_completed and list_of_todos[i].completed:
                    self.menu_todos[i].hide()
                elif (self.hide_completed and not list_of_todos[i].completed
                      and not hide_by_context):
                    self.menu_todos[i].show()

            if not hide_by_context:
                if (self.hide_completed and not list_of_todos[i].completed
                        and not hide_by_project):
                    self.menu_todos[i].show()

            if (not self.filter_projects and not self.filter_contexts
                    and not self.hide_completed):
                self.menu_todos[i].show()

        if len(list_of_todos) < self.todos:
            for i in range(len(list_of_todos), self.todos):
                self.menu_todos[i].hide()
Example #3
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)
Example #4
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()
Example #5
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()
Example #6
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()
Example #7
0
 def load_preferences(self):
     self.configuration = Configuration()
     preferences = self.configuration.get('preferences')
     self.theme_light = preferences['theme-light']
     self.todos = preferences['todos']
     todo_file = Path(os.path.expanduser(preferences['todo-file']))
     if not todo_file.exists():
         if not todo_file.parent.exists():
             os.makedirs(todo_file.parent)
         todo_file.touch()
     self.todo_file = todo_file.as_posix()
     projects = preferences['projects']
     contexts = preferences['contexts']
     tags = preferences['tags']
     self.hide_completed = preferences.get('hide-completed', False)
     list_of_todos = todotxtio.from_file(self.todo_file)
     pattern = r'^\d{4}-\d{2}-\d{2}$'
     for todo in list_of_todos:
         for aproject in todo.projects:
             if aproject not in projects:
                 projects.append(aproject)
         for acontext in todo.contexts:
             if acontext not in contexts:
                 contexts.append(acontext)
         for atag in todo.tags:
             if atag not in [tag['name'] for tag in tags]:
                 if re.search(pattern, todo.tags[atag]):
                     tags.append({'name': atag, 'type': 'date'})
                 elif todo.tags[atag].lower() in ['true', 'false']:
                     tags.append({'name': atag, 'type': 'boolean'})
                 elif todo.tags[atag].lower() in ['true', 'false']:
                     tags.append({'name': atag, 'type': 'boolean'})
                 else:
                     tags.append({'name': atag, 'type': 'string'})
     preferences['projects'] = projects
     preferences['contexts'] = contexts
     preferences['tags'] = tags
     self.configuration.set('preferences', preferences)
     self.configuration.save()
     self.set_icon(True)
Example #8
0
    def load_todos(self):
        list_of_todos = todotxtio.from_file(self.todo_file)
        list_of_todos.sort(reverse=False, key=self.sort)

        while self.todos > len(self.menu_todos):
            self.menu_todos.append(Gtk.CheckMenuItem.new_with_label(''))
        for i in range(0, min(len(list_of_todos), self.todos)):
            if list_of_todos[i].priority:
                text = '({}) {}'.format(list_of_todos[i].priority,
                                        list_of_todos[i].text)
            else:
                text = list_of_todos[i].text
            self.menu_todos[i].file_index = i
            self.menu_todos[i].set_label(text)
            self.menu_todos[i].set_active(list_of_todos[i].completed)
            self.menu_todos[i].connect('toggled', self.on_menu_todo_toggled)
            if self.hide_completed and list_of_todos[i].completed:
                self.menu_todos[i].hide()
            else:
                self.menu_todos[i].show()
        if len(list_of_todos) < self.todos:
            for i in range(len(list_of_todos), self.todos):
                self.menu_todos[i].hide()
Example #9
0
 def load_todos(self):
     list_of_todos = todotxtio.from_file(self.todo_file)
     self.todos.add_all(list_of_todos)
Example #10
0
    def load_preferences(self):
        self.configuration = Configuration()
        preferences = self.configuration.get('preferences')
        self.theme_light = preferences['theme-light']
        self.todos = preferences['todos']
        todo_file = Path(os.path.expanduser(preferences['todo-file']))
        if not todo_file.exists():
            if not todo_file.parent.exists():
                os.makedirs(todo_file.parent)
            todo_file.touch()
        self.todo_file = todo_file.as_posix()
        self.projects = preferences['projects']
        contexts = preferences['contexts']
        tags = preferences['tags']
        self.hide_completed = preferences.get('hide-completed', False)
        self.filter_projects = preferences.get('filter-projects', False)
        self.last_filtered_projects = preferences.get('last-filtered-projects', [])
        list_of_todos = todotxtio.from_file(self.todo_file)
        pattern = r'^\d{4}-\d{2}-\d{2}$'
        for todo in list_of_todos:
            for aproject in todo.projects:
                if aproject not in self.projects:
                    self.projects.append(aproject)
            for acontext in todo.contexts:
                if acontext not in contexts:
                    contexts.append(acontext)
            for atag in todo.tags:
                if atag not in [tag['name'] for tag in tags]:
                    if re.search(pattern, todo.tags[atag]):
                        tags.append({'name': atag, 'type': 'date'})
                    elif todo.tags[atag].lower() in ['true', 'false']:
                        tags.append({'name': atag, 'type': 'boolean'})
                    elif todo.tags[atag].lower() in [ 'true', 'false']:
                        tags.append({'name': atag, 'type': 'boolean'})
                    else:
                        tags.append({'name': atag, 'type': 'string'})
        preferences['projects'] = self.projects
        preferences['contexts'] = contexts
        preferences['tags'] = tags
        self.new_task_keybind = '<Control><Super>t'
        self.show_tasks_keybind = '<Control><Super>a'
        keybindings = preferences.get('keybindings', [])
        if keybindings:
            self.new_task_keybind = list(
                filter(lambda obj: obj.get('name') == 'new_task', keybindings)
            )[0]['keybind']
            self.show_tasks_keybind = list(
                filter(lambda obj: obj.get('name') == 'show_tasks',
                       keybindings)
            )[0]['keybind']

        Keybinder.bind(self.new_task_keybind, self.on_menu_add_todo_activate)
        Keybinder.bind(self.show_tasks_keybind,
                       self.on_menu_list_todos_activate)

        preferences['keybindings'] = [
            {'name': 'new_task', 'keybind': self.new_task_keybind},
            {'name': 'show_tasks', 'keybind': self.show_tasks_keybind},
        ]
        self.configuration.set('preferences', preferences)
        self.configuration.save()
        self.set_icon()
Example #11
0
 def get_plaindata(self,):
     return todotxtio.from_file(self.todo_file)
Example #12
0
    def load_preferences(self):
        self.configuration = Configuration()
        preferences = self.configuration.get("preferences")
        self.theme_light = preferences["theme-light"]
        self.todos = preferences["todos"]
        todo_file = Path(os.path.expanduser(preferences["todo-file"]))
        if not todo_file.exists():
            if not todo_file.parent.exists():
                os.makedirs(todo_file.parent)
            todo_file.touch()
        self.todo_file = todo_file.as_posix()
        self.projects = preferences["projects"]
        self.contexts = preferences["contexts"]
        tags = preferences["tags"]
        self.hide_completed = preferences.get("hide-completed", False)
        self.filter_projects = preferences.get("filter-projects", False)
        self.filter_contexts = preferences.get("filter-contexts", False)
        self.last_filtered_projects = preferences.get("last-filtered-projects",
                                                      [])
        self.last_filtered_contexts = preferences.get("last-filtered-contexts",
                                                      [])
        list_of_todos = todotxtio.from_file(self.todo_file)
        pattern = r"^\d{4}-\d{2}-\d{2}$"
        for todo in list_of_todos:
            for aproject in todo.projects:
                if aproject not in self.projects:
                    self.projects.append(aproject)
            for acontext in todo.contexts:
                if acontext not in self.contexts:
                    self.contexts.append(acontext)
            for atag in todo.tags:
                if atag not in [tag["name"] for tag in tags]:
                    if re.search(pattern, todo.tags[atag]):
                        tags.append({"name": atag, "type": "date"})
                    elif todo.tags[atag].lower() in ["true", "false"]:
                        tags.append({"name": atag, "type": "boolean"})
                    elif todo.tags[atag].lower() in ["true", "false"]:
                        tags.append({"name": atag, "type": "boolean"})
                    else:
                        tags.append({"name": atag, "type": "string"})
        preferences["projects"] = self.projects
        preferences["contexts"] = self.contexts
        preferences["tags"] = tags
        self.new_task_keybind = "<Control><Super>t"
        self.show_tasks_keybind = "<Control><Super>a"
        keybindings = preferences.get("keybindings", [])
        if keybindings:
            self.new_task_keybind = list(
                filter(lambda obj: obj.get("name") == "new_task",
                       keybindings))[0]["keybind"]
            self.show_tasks_keybind = list(
                filter(lambda obj: obj.get("name") == "show_tasks",
                       keybindings))[0]["keybind"]

        Keybinder.bind(self.new_task_keybind, self.on_menu_add_todo_activate)
        Keybinder.bind(self.show_tasks_keybind,
                       self.on_menu_list_todos_activate)

        preferences["keybindings"] = [
            {
                "name": "new_task",
                "keybind": self.new_task_keybind
            },
            {
                "name": "show_tasks",
                "keybind": self.show_tasks_keybind
            },
        ]
        self.configuration.set("preferences", preferences)
        self.configuration.save()
        self.set_icon()