ProposedPluginArch: std_PluginTodo.py

from os.path import join

WIKIDPAD_PLUGIN = (("hooks", 1),)

def startup(wikidPad):
    """
    Called when application starts
    """

    pass

def newWiki(wikidPad, wikiName, wikiDir):
    """
    Called when a new wiki is about to be created.

    wikiName -- name of the wiki (already checked to be a proper CamelCase word)
    wikiDir -- directory to create the wiki in (more precisely the .wiki config
           file). This directory may already exist
    """
    pass

def createdWiki(wikidPad, wikiName, wikiDir):
    """
    Called when creation of a new wiki was done successfully.

    The home wiki word (equals name of the wiki) is not yet loaded.

    wikiName -- name of the wiki
    wikiDir -- directory the wiki was created in
    """
    pass

def openWiki(wikidPad, wikiConfig):
    """
    Called when an existing wiki is about to be opened.

    wikiConfig -- path to the .wiki config file
    """
    pass

def openedWiki(wikidPad, wikiName, wikiConfig):
    """
    Called when an existing wiki was opened successfully

    wikiName -- name of the wiki
    wikiConfig -- path to the .wiki config file
    """
    pass
    
def openWikiWord(wikidPad, wikiWord):
    """
    Called when a new or existing wiki word is about to be opened.
    The previous active page is already saved, new one is not yet loaded.

    wikiWord -- name of the wiki word to open
    """
    pass

def newWikiWord(wikidPad, wikiWord):
    """
    Called when a new wiki word is about to be created.
    The wikidPad.currentWikiPage of the new word is already available

    wikiWord -- name of the wiki word to create
    """
    pass

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":
        return

    # 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')]
    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]

    for todo in todos:
        allTodo = todo[1].split(":")
        words = allTodo[0].split(".")
        for word in words[1:]:
            if not word in checkTags:
                tags.append( (word,"Tagged "+word) )
                tags.append( ("_spec.SPACER","") )
                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    


def savingWikiWord(wikidPad, wikiWord):
    """
    Called when a new or existing wiki word is about to be saved

    wikiWord -- name of the wiki word to create
    """
    pass

def savedWikiWord(wikidPad, wikiWord):
    """
    Called when a wiki word was saved successfully

    wikiWord -- name of the wiki word to create
    """
    pass

def renamedWikiWord(wikidPad, fromWord, toWord):
    """
    Called when a wiki word was renamed successfully.

    The changed data is already saved in the fileset,
    the GUI is not updated yet, the renamed page is not yet loaded.

    fromWord -- name of the wiki word before renaming
    toWord -- name of the wiki word after renaming
    """
    pass

def deletedWikiWord(wikidPad, wikiWord):
    """
    Called when a wiki word was deleted successfully.

    The changed data is already saved in the fileset,
    the GUI is not updated yet, another page (normally
    the last in history before the deleted one) is not yet loaded.

    wikiWord -- name of the deleted wiki word
    """
    pass

def exit(wikidPad):
    """
    Called when the application is about to exit.

    The global and the wiki configuration (if any) are saved already,
    the current wiki page (if any) is saved already.
    """
    pass