python和gtk3剪贴板onChange [英] python and gtk3 clipboard onChange
本文介绍了python和gtk3剪贴板onChange的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用PyGTK 2,我可以附加一个功能,当剪贴板的内容更改时,该功能将被执行。浏览GTK3的python绑定文档时,我找不到关于此功能的任何描述。
With PyGTK 2 I could attach a function to be executed when the contents of the clipboard was changed. Browsing through the documentation of GTK3's python bindings I can not find any description of such an functionality.
有人可以告诉我对此的最佳实践吗?
Can anyone tell me the 'best practice' for this?
编辑
使用gtk2可以进行以下工作:
With gtk2 the following works:
import gtk
def test(*args):
print "Clipboard changed"
clip = gtk.Clipboard()
clip.connect('owner-change',test)
从gi.repository导入Gtk接受
When adopting to Gtk3
from gi.repository import Gtk, Gdk
def test(*args):
print "Clipboard changed"
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.Connect('owner-change',test)
Python接受与信号的连接,但是我的函数从未执行。
Python accepts the connection to the signal, but my function is never executed.
推荐答案
from gi.repository import Gtk, Gdk
def test(*args):
print "Clipboard changed"
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
clip.connect('owner-change',test)
Gtk.main()
为我工作。
这篇关于python和gtk3剪贴板onChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文