views:

244

answers:

2

For example, I open a pdf file or a web page in gnome, use mouse double click some text, so a word is selected, how can I get this word in a background running daemon written with python-dbus?

Some simple but working piece of script is appreciated greatly.

Thanks!

A: 

Gnome Do has a few plug-ins that use the selected text. I'm not sure how it is implemented (and if it uses DBus), but the code should reveal all. :)

Walter
+4  A: 

You don't need D-Bus, simply listen to changes for the middle-click (Selection) clipboard with for example Gtk:

import gtk

def _clipboard_changed(clipboard, event):
    text = clipboard.wait_for_text()

clip = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY)
clip.connect("owner-change", _clipboard_changed)
kaizer.se
WOW, awesome! Works great! Just need an extra line: gtk.main()to let the program keep running.I want to implement something like the usual translation software. I guess I can open up a new window and place it around the mouse.And only if I can insert dynamic annotate to the pdf files being read, perfect.
chenz