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 wor开发者_运维百科king piece of script is appreciated greatly.
Thanks!
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)
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. :)
精彩评论