开发者

How do I get the selected text in desktop application using python-dbus?

开发者 https://www.devze.com 2022-12-11 19:06 出处:网络
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?

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. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号