示例#1
0
 def task_goto(self, task_number, project=None):
     """Sets given task number as current task.
     Can manually set the project, else defaults to current_project.
     """
     
     if not project:
         project = self.current_project
         
     if project not in self.projects:
         return trans("project not found", self.language, (project))
     
     try:
         # since we're dealing with reversed numbers for tasks (1 being the
         # last task in list, handle it similarly here)
         
         task_count = len(self.projects[project])
         
         # Ensure we pass numbers
         task_number = task_count - int(task_number)
         
         # Remove the task from its current position
         task = self.projects[project][task_number]
         del(self.projects[project][task_number])
         
         # Add the task back at top of the list 
         self.projects[project].append(task)
         
         return trans("focus on task", self.language, (task))
     
     except:
         return trans("cannot find task number", self.language, task_number)
示例#2
0
 def get_task(self):
     """Returns current task"""
     try:
         task = self.projects[self.current_project].pop()
         self.projects[self.current_project].append(task)
         return trans("focus on task", self.language, (task))
     except:
         return trans("nothing", self.language)
示例#3
0
 def set_language(self, language):
     """Sets given locale"""
     if is_valid_language(language):
         
         # what command to run if user asks to UnDo, with its arguments 
         self.set_undo(self.set_language, (language))
         
         self.language = language
         return trans("language set", self.language)
     
     else:
         return trans("language not supported", self.language, (language))
示例#4
0
    def task_done(self, task_number=None, project=None):
        """Marks the given task_number as done (removes from list)
        If task_number is None, defaults to the last task.
        If project is none, defaults to current_project
        """
        
        if not project:
            project = self.current_project
            
        if project not in self.projects:
            return trans("project not found", self.language, (project))
        
        # check if we have a task_number, if yes, delete the corresponding task
        if task_number:
            # since we're dealing with reversed numbers for tasks (1 being the
            # last task in list, handle it similarly here)
            
            task_count = len(self.projects[project])
            
            # Ensure we pass numbers
            task_number = task_count - int(task_number)
            

            try:
                task = self.projects[project][task_number]
                
                self.set_undo(self.task_add, (task))
                
                del(self.projects[project][task_number])
                
            except:
                return trans("cannot find task number", self.language,
                             (task_number))
                
        else:
            try:
                task = self.projects[project].pop()
            except:
                # project is empty, and everything is done, delete the project
                # don't worry about 'general' project, if deleted, it will
                # be automatically created again
                
                del(self.projects[project])
                
                return "%s\n%s" %(trans("list empty", self.language),
                                  self.set_project("general"))
        
        return trans("task done", self.language, (task, self.get_task()))
示例#5
0
 def task_add(self, task, project=None, do_later=False):
     """Adds task to project, uses current_project project if not specified.
     
     if do_later == True, task is added below the topmost task in the given
     project.
     
     Expected, a task as unicode string and a project name as unicode
     string.
     """
     
     if task.strip() == "":
         return self.get_task_list()
     
     if not project:
         project = self.current_project
     
     # Just making sure strings are unicode form this point onward
     task = u'%s' %task
     project = u'%s' %project
     
     # Check if the project name is valid
     if project in self.projects:
         
         if do_later:
             temp = self.projects[project].pop()
             self.projects[project].append(task)
             self.projects[project].append(temp)
             return trans("task added for later", self.language, (task))
         
         self.projects[project].append(task)
         return trans("task added", self.language, (task))
         
     else:
         # Create new project
         self.projects.update({project:[]})
         self.projects[project].append(task)
         
         return trans("task added", self.language, (task))
示例#6
0
 def undo(self):
     """Uses previously saved data to undo last command"""
     function = self.undo_function
     arg = pickle.loads(self.undo_arg)
     
     try:
         response = function(arg)
         self.undo_arg = None
         self.undo_function = None
         
     except:
         response = trans("cannot undo", self.language)
     
     return response
示例#7
0
 def set_project(self, project):
     """Sets given project as current_project"""
     
     # Create a new project, if empty, reset to general
     if project not in self.projects:
         if project.strip() != '':
             self.projects.update({project:[]})
         else:
             project = "general"
         
     # save undo information
     self.set_undo(self.set_project, (self.current_project))
     
     self.current_project = project
     return trans("project set", self.language, project)
示例#8
0
    def get_task_list(self, project=None):
        """Returns a numberd list of tasks (as string) for specified project,
        defaults to current_project if none specified.
        """
        
        if not project:
            project = self.current_project

        
        # Check if project name is valid, else complain.
        if project not in self.projects:
            return trans("project not found", self.language, (project))
        
        # make a copy of the list as we are going to change its order.
        tasklist = self.projects[project][:]
        
        tasklist.reverse()

        # Build the response
        response = u""
        response = '\n'.join([u'%2d. %s' % (len(tasklist)-x, tasklist[len(tasklist)-x-1]) for x in range(len(tasklist))])
        return response