Affichage des articles dont le libellé est dbus. Afficher tous les articles
Affichage des articles dont le libellé est dbus. Afficher tous les articles

jeudi 15 janvier 2009

Tomboy and python, using dbus

Tomboy expose a bunch of methods on the dbus interface.

Dbus is a kind of component-oriented middleware comunicating by messages.

Here http://arstechnica.com/journals/linux.ars/2007/09/26/using-the-tomboy-d-bus-interface
I found a description of the dbus interface that tomboy propose to the programmer, so I gave it a try in order to implement a few scripts :

  • showAllNotes

  • showNotebook myNbkName




The previously cited blog article on arstechnica cites this deeper plugin example.




showAllNotes



#!/usr/bin/env python

## In Tomboy, display all the notes.

## Licence : GPL
## Date : 2009-01-14

# This uses the tomboy dbus interface and the methods exposed by tomboy

import sys, 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")

# Show every note
for n in tomboy.ListAllNotes(): tomboy.DisplayNote(n)




showNotebook



#!/usr/bin/env python

## In Tomboy, display all the notes labeled under a given "Notebook"

## Licence : GPL
## Date : 2009-01-14

# This is based on the underliying Tomboy tag mechanism (unused)
# knowing that a given notebook "mynotebookname" will be under the
# tag : "system:notebook:mynotebookname"
# (Thanks to irc.gnome.org#tomboy:sandy for the hint)


import sys, 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")

if len(sys.argv) > 1:
for note in tomboy.GetAllNotesWithTag("system:notebook:" + "".join(sys.argv[1:])):
tomboy.DisplayNote(note)
else : sys.stderr.write("Notebook name not specified. Exiting.\n")