-
Notifications
You must be signed in to change notification settings - Fork 5
SortedTodos
The scripts shown here use the DynamicTodoList script as found in Erik Neumann 's GettingThingsDone script, but changed to add functionality which sorts the page according to TAG words or todo.TYPE.
there's a few versions here, starting with...
it works with all WikiWords starting with ToDo / TODO / Todo:
- Opening a page called ToDo -> generates a list of ALL Todos with 'todo' in it
- Opening any page starting with Todo - for example Opening a page called TodoNEXT -> will generate a list of all Todos with strings 'todo' AND 'NEXT' in the text (including "todo.NEXT:")
The Todos are then sorted according to further categories that can be customised in the code (look for TAG LIST in the code below or in attachment todos.py)
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 (although this can be easily changed) ...
'''How To Use This Script :'''
- Create '''user_extensions''' directory under your WikidPad directory
- Copy there "WikidPadHooks.py" and "WikiSyntax.py" from '''extensions''' directory
- Never edit original files in '''extensions''', only copies in '''user_extensions''' directory
- Edit '''WikidPadHooks.py''' file: add following script into '''openedWikiWord''' function
- '''CLOSE AND RESTART''' WikidPad to activate the changes
#!python def openedWikiWord(wikidPad, wikiWord): if (wikiWord[:4].upper() == "TODO"): # tags contains the (Tag, TagHeader) pairs - customize the list of sort categories here: # TagHeaders are the descriptive headings that will be shown for each category. tags = [('HIGH','Tagged HIGH !'), ('_spec.SPACER',''), ('NEXT','Next Actions'), ('ThisWeek','Tagged for This Week'), ('_spec.SPACER',''), ('_spec.NOTAGS','Untagged Todos'), ('_spec.SPACER',''), ('SomeDay','SomeDay / Maybe'), ('_spec.SPACER',''), ('TimeToTime','Tagged for from time to time'), ('_spec.SPACER',''), ('LOW','Tagged as LOW'), ('_spec.SPACER',''), ('VeryLow','Tagged as Very LOW')] srchstr = wikiWord[4:] # get all todos with 'todo' in them to seperate list to be used here: todosFull = wikidPad.wikiData.getTodos() todos = [todo for todo in todosFull if ('todo' in todo[1] and srchstr in todo[1]) ] #clean the page code - and insert the harvested todos after placemark = '++ auto-harvested todos:' editor = wikidPad.editor st = editor.FindText(0, editor.GetLength(), "++ auto-harvested todos:", 0) st = editor.PositionFromLine(1+editor.LineFromPosition(st)) editor.SetSelection(st, editor.GetLength()) editor.ReplaceSelection("\n") # handle the page by displaying all keywords with srchstr -> list all todos : tagAdded = True #used to stop two spacers in a row for tag in tags: wroteHeader = False #used to make sure that header is written only once - in a non-empty category # handle special tag '_spec.SPACER' by writing SPACERs in the tag list: if tag[0] == '_spec.SPACER' and tagAdded: editor.AddText('\n' + ('-'*70) + '\n') tagAdded = False # handle special NOTAG in the tag list # This displays all untagged todos : elif tag[0] == '_spec.NOTAGS': for todo in todos: foundTag = False for t in tags: if t[0] in todo[1]: foundTag = True break if not foundTag and todo[0] != 'DEL': if not wroteHeader: editor.AddText('\n++ ' + tag[1] + ' :\n') wroteHeader = True s = str(todo[1]) editor.AddText(' * '+ str(todo[0]) + ': '+ s[s.find(':')+1:] + '\n') todos[todos.index(todo)] = ('DEL','DEL') #marks that todo to be ignored tagAdded = True # handle normal Tags - write the todos for that tag: else: for todo in todos: if (tag[0] in todo[1]): if not wroteHeader: editor.AddText('\n++ ' + tag[1] + ' :\n') wroteHeader = True s = str(todo[1]) editor.AddText(' * '+ str(todo[0]) + ': '+ s[s.find(':')+1:] + '\n') todos[todos.index(todo)] = ('DEL','DEL') #marks that todo to be ignored tagAdded = True
'''Alternative using todos.py :'''
- save Todos.py (attached to this wiki page) in \user_extensions folder
- change WikidPadHooks.py is as follows :
- add the following to use todo.py (i'm not sure if this is the best or only way to do this)..
#!python from sys import path path.append("C:\Program Files\WikidPad\user_extensions") # replace this with the location of your Todos.py file import Todos
- added the following to openedWikiWord hook:
#!python def openedWikiWord(wikidPad, wikiWord): if (wikiWord[:4].upper() == "TODO"): Todos.genTodos(wikidPad, wikiWord)
For the 1.6Beta4, I needed to change the line
editor = wikidPad.editor
to
editor = wikidPad.activeEditor
It would be cleaner to use
editor = wikidPad.getActiveEditor()
instead.
Email me at mike at mikeandkellycrowe dot com
I wanted my list to have dynamic tags, rather than the pre-defined tags always being hard-coded. Added code to scan todos for unknown tags, append them with description of "Tagged (tag)": ''Notes'':
- For dumb people like me, make sure you put it in __openedWikiWord__ and not ''openWikiWord''. Big Difference ;)
- This is compatible with 1.7a.
- In your main page, enter a link of ![Todo] to activate Code:
#!python def openedWikiWord(wikidPad, wikiWord): """ Called when a new or existing wiki word was opened successfully. wikiWord -- name of the wiki word to create """ if (wikiWord[:4].upper() == "TODO"): # tags contains the (Tag, TagHeader) pairs - customize the list of sort categories here: # TagHeaders are the descriptive headings that will be shown for each category. tags = [('High','Tagged HIGH !'), ('_spec.SPACER',''), ('Next','Next Actions'), ('ThisWeek','Tagged for This Week'), ('_spec.SPACER',''), ('SomeDay','SomeDay / Maybe'), ('_spec.SPACER',''), ('TimeToTime','Tagged for from time to time'), ('_spec.SPACER',''), ('Low','Tagged as LOW'), ('_spec.SPACER',''), ('VeryLow','Tagged as Very LOW')] # MikeCrowe -- Untagged always at end of list tagEnd = [ ('_spec.SPACER',''), ('_spec.NOTAGS','Untagged Todos')] srchstr = wikiWord[4:] # get all todos with 'todo' in them to seperate list to be used here: todosFull = wikidPad.wikiData.getTodos() todos = [todo for todo in todosFull if ('todo' in todo[1]) ] # and srchstr in todo[1]) ] #clean the page code - and insert the harvested todos after placemark = '++ auto-harvested todos:' editor = wikidPad.getActiveEditor() st = editor.FindText(0, editor.GetLength(), "++ auto-harvested todos:", 0) st = editor.PositionFromLine(1+editor.LineFromPosition(st)) editor.SetSelection(st, editor.GetLength()) editor.ReplaceSelection("\n") # handle the page by displaying all keywords with srchstr -> list all todos : tagAdded = True #used to stop two spacers in a row checkTags = [tag[0] for tag in tags] # MikeCrowe -- code to search for tags not in above list and automatically add for todo in todos: allTodo = todo[1].split(":") words = allTodo[0].split(".") for word in words[1:]: if not word in checkTags: tags.append( ("_spec.SPACER","") ) tags.append( (word,"Tagged "+word) ) checkTags.append(word) tags = tags + tagEnd for tag in tags: wroteHeader = False #used to make sure that header is written only once - in a non-empty category # handle special tag '_spec.SPACER' by writing SPACERs in the tag list: if tag[0] == '_spec.SPACER' and tagAdded: editor.AddText('\n' + ('-'*70) + '\n') tagAdded = False # handle special NOTAG in the tag list # This displays all untagged todos : elif tag[0] != '_spec.NOTAGS': for todo in todos: if (tag[0] in todo[1]): if not wroteHeader: editor.AddText('\n++ ' + tag[1] + ' :\n') wroteHeader = True s = str(todo[1]) editor.AddText(' * '+ str(todo[0]) + ': '+ s[s.find(':')+1:] + '\n') todos[todos.index(todo)] = ('DEL','DEL') #marks that todo to be ignored tagAdded = True # handle normal Tags - write the todos for that tag: else: for todo in todos: foundTag = False for t in tags: if t[0] in todo[1]: foundTag = True break if not foundTag and todo[0] != 'DEL': if not wroteHeader: editor.AddText('\n++ ' + tag[1] + ' :\n') wroteHeader = True s = str(todo[1]) editor.AddText(' * '+ str(todo[0]) + ': '+ s[s.find(':')+1:] + '\n') todos[todos.index(todo)] = ('DEL','DEL') #marks that todo to be ignored tagAdded = True
Loosely based on the above and GettingThingsDone I wrote my own version.
Due to handling issues I stored it on my site and not here in the wiki. Probably I'll change that later.
Here is the address: http://www.ziemski.net/wikidpad/
Christian