wiki:ImportTomboy

This plugin allows WikidPad to import notes from TomBoy?. You probably need to have TomBoy? open before.

# -*- coding: utf-8 -*-

"""ImportTomboy.py
	Allows WikidPad to import notes from TomBoy.
	You probably need to have TomBoy open before.
	v0.1 by Carles F. Julià, 18 Nov 2010
"""

WIKIDPAD_PLUGIN = (("MenuFunctions",1),)

def describeMenuItems(wiki):
	#return function, label, statustext
	return ((importTomboyNotes, "Import from Tomboy Notes\t", "Import from Tomboy Notes"),)
	
	
	
def importTomboyNotes(pwiki, evt):
    wd = pwiki.getWikiDocument()
    
    import dbus, gobject, dbus.glib

    # Get the D-Bus session bus
    bus = dbus.SessionBus()
    # Access the Tomboy D-Bus object
    obj = bus.get_object("org.gnome.Tomboy", "/org/gnome/Tomboy/RemoteControl")
    # Access the Tomboy remote control interface
    tomboy = dbus.Interface(obj, "org.gnome.Tomboy.RemoteControl")

    tomboynotetitles = [str(tomboy.GetNoteTitle(n)) for n in tomboy.ListAllNotes()]
    tomboynotecontents = [str(tomboy.GetNoteContents(n)) for n in tomboy.ListAllNotes()]
    originaltitles = tomboynotetitles;
    #creating links in notes' contents

    for l in range(len(tomboynotecontents)):
        for nn,n in enumerate(tomboynotetitles):
            if nn != l:
                tomboynotecontents[l]= tomboynotecontents[l].replace(n,"["+n+"]")

    
    for n,t in enumerate(tomboynotetitles):
        nt = t
        i = 1
        #checking exisitng notes
        while wd.isDefinedWikiLink(nt):
            wikipage = wd.getWikiPage(nt)
            if u"source" in wikipage.getProperties() and  u"TomBoy" in wikipage.getProperties()[u"source"]:
                break;
            nt = t+str(i)
            i+=1
        if nt != t:
            #we cange the name everywhere
            for l in range(len(tomboynotecontents)):
                tomboynotecontents[l]= tomboynotecontents[l].replace("["+t+"]","["+nt+"]")
            tomboynotetitles[n] = nt
            
    for n,t in enumerate(tomboynotetitles):
        wikipage = wd.getWikiPageNoError(t)
        content = "++ "+tomboynotecontents[n]+"\n\n"
        content+="[source: TomBoy]\n"
        content+="[TomBoyTitle: %s]\n" % originaltitles[n]
        wikipage.replaceLiveText(unicode(content))
Last modified 7 years ago Last modified on Nov 5, 2010 6:14:58 PM