Vizible’s Blog

Tomboy and DBus

Posted in Python by wearetherock on January 31, 2009

tomboy_service.py

import socket
import dbus

def show_message(title, message):
	bus = dbus.SessionBus()
	object = bus.get_object("org.gnome.Tomboy", "/org/gnome/Tomboy/RemoteControl")
	tomboy = dbus.Interface(object, "org.gnome.Tomboy.RemoteControl")

	#note = tomboy.CreateNote()
	note = tomboy.CreateNamedNote(title)
	tomboy.SetNoteContents(note , message)
	tomboy.AddTagToNote(note,title)
	tomboy.DisplayNote(note)

def main():
	my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	my_socket.bind(('',8881))
	my_socket.listen(5)

	print 'start service ...'

	while True :
		client, address = my_socket.accept()
		message = client.recv(1024)
		client.close()

		print 'message (%s) from : %s' % ( str(message), address[0])

		show_message('message from :'+ str(address[0]) , message)

if __name__ == "__main__" :
	main()

|

tomboy_client.py

import socket
import sys

def main(message) :
	my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	my_socket.connect(('localhost', 8881))
	my_socket.send(message)
	my_socket.close()

if len(sys.argv) < 2 :
	print 'use: python tomboy_client.py "message"'
else :
	main(sys.argv[1])

|

Advertisements
Tagged with: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: