SortedTodos: Todos.py

File Todos.py, 5.2 kB (added by chriz, 8 years ago)

added by JaysenNaidoo? on Tue Aug 9 18:08:12 2005

Line 
1""" Functions, Constants, and utilities for WikidPad.WikiData.Todos
2
3    Function genTodos(WikidPad, WikiWord) :
4    - Opening a page called ToDo -> generates a list of ALL Todos with 'todo' in it
5    - Opening a page called TodoWikidPad -> generates a list of all Todos with strings 'todo' AND 'WikidPad' in the text
6    - Opening a page called TodoNEXT -> will generate a list of all Todos with strings 'todo' AND 'NEXT' in the text (including "todo.NEXT:")
7
8    - The Todos are then sorted according to further categories if they contain any of a defined set of Tag Words like 'URGENT' , 'ASAP' , 'NEXT', etc.
9    - Tag Words can be customised in the code (look for TAG LIST in todos.py)
10    - Todos that have more than one Tag Word in it are displayed in the category that comes first in the TAG LIST, and not duplicated
11      (although this can be easily changed)
12
13"""
14
15
16# TAGLIST:
17# tags contains the a list of 'tags', special text that you can add to todo text to sort them into categories
18# .. when dynamically inserting the list of todos, they can then be sorted by category
19# .. and  and displayed seperately under seperate TagHeaders.
20#
21# CUSTOMIZE:
22# Modify this list to change the names of tags that you use, the headers you want for them, and order that the tag categories are displayed
23#   tags is a List of tag items where each tag item is of the form:
24#       ('TAG','TAGHEADER')
25#       where TAG is the text searched for as a tag,
26#       and TAGHEADER is the title displayed for that Tag Category
27#   The order of items in the list is the order that they will be displayed on the dynamic page
28#
29# SPECIAL TAGS:
30# Currently, tag '_spec.SPACER' in the tag list will add a spacer instead of a tag category
31# to the dynamically generated page.
32# Also, tag '_spec.NOTAGS' will indicate the position at which to include all todos with no tags.
33
34
35tags = [('_spec.SPACER',''),
36        ('HIGH','Tagged HIGH ! '),
37        ('URGENT','Tagged URGENT ! '),
38        ('_spec.SPACER',''),
39        ('NEXT','Tagged Next'),
40        ('_spec.SPACER',''),
41        ('ASAP','Tagged ASAP'),
42        ('SOON','Tagged Soon'),
43        ('ThisWeek','Tagged for This Week'),
44        ('_spec.SPACER',''),
45        ('MEDIUM','Tagged as Medium'),
46        ('WhenPossible','Tagged for When Possible'),
47        ('_spec.SPACER',''),
48        ('_spec.NOTAGS','UNTAGGED Todos'),
49        ('_spec.SPACER',''),
50        ('TimeToTime','Tagged for from time to time'),
51        ('SOMEDAY','Tagged for Someday'),
52        ('_spec.SPACER',''),
53        ('LOW','Tagged as LOW'),
54        ('VeryLow','Tagged as Very LOW') ]
55
56
57
58def genTodos(wikidPad, wikiWord):
59    """ Dynamically generates list of Todos (or other keywords) on openedWikiWord,
60        .. where wikiWord is of the form ToDoSEARCHSTRING (SEARCHSTRING can be any text that you are looking for).
61        Displays all todos containing 'todo' and the value of SEARCHSTRING.
62        The Generated display is seperated into categories determined by the presence of Tags in the todo text.
63        These Tags can be defined and ordered in the TAGS LIST above.
64    """
65
66    srchstr = wikiWord[4:]
67   
68    # get all todos with 'todo' and SearchString in them to seperate list to be used here:
69    todosFull = wikidPad.wikiData.getTodos()
70    todos = [todo for todo in todosFull if ('todo' in todo[1] and srchstr in todo[1])]
71
72    # clean the page
73    editor = wikidPad.editor
74    editor.GotoLine(linesToSkip)
75    editor.SetSelectionEnd(editor.GetLength())
76    editor.ReplaceSelection("")
77
78    # handle the page by displaying all keywords with srchstr:
79    tagAdded = True    #used to stop two spacers in a row
80   
81    for tag in tags:
82        wroteHeader = False   #used to make sure that header is written only once - in a non-empty category
83       
84        # handle special tag '_spec.SPACER' by writing SPACERs in the tag list:
85        if tag[0] == '_spec.SPACER' and tagAdded:
86            editor.AddText('\n' + ('-'*70) + '\n')
87            tagAdded = False
88
89        # handle special NOTAG in the tag list
90        # This displays all untagged todos   :
91        elif tag[0] == '_spec.NOTAGS':
92            for todo in todos:
93                foundTag = False
94                for t in tags:
95                    if t[0] in todo[1]:
96                        foundTag = True
97                        break
98                   
99                if not foundTag and todo[0] != 'DEL':
100                    if not wroteHeader:
101                        editor.AddText('\n++ ' + tag[1] + ' :\n')
102                        wroteHeader = True
103                    editor.AddText(' * '+ str(todo[1])+'\n')
104                    todos[todos.index(todo)] = ('DEL','DEL') #marks that todo to be ignored
105                    tagAdded = True
106
107        # handle normal Tags - write the todos for that tag:
108        else:
109            for todo in todos:
110                if (tag[0] in todo[1]):
111                    if not wroteHeader:
112                        editor.AddText('\n++ ' + tag[1] + ' :\n')
113                        wroteHeader = True
114                    editor.AddText(' * '+ str(todo[1])+'\n')
115                    todos[todos.index(todo)] = ('DEL','DEL') #marks that todo to be ignored
116                    tagAdded = True
117