简体   繁体   English

python和gtk3剪贴板onChange

[英]python and gtk3 clipboard onChange

With PyGTK 2 I could attach a function to be executed when the contents of the clipboard was changed. 使用PyGTK 2,我可以附加一个功能,当剪贴板的内容更改时,该功能将被执行。 Browsing through the documentation of GTK3's python bindings I can not find any description of such an functionality. 浏览GTK3的python绑定文档时,我找不到关于此功能的任何描述。

Can anyone tell me the 'best practice' for this? 谁能告诉我“最佳实践”吗?

EDIT 编辑

With gtk2 the following works: 使用gtk2可以完成以下工作:

import gtk

def test(*args):
  print "Clipboard changed"

clip = gtk.Clipboard()
clip.connect('owner-change',test)

When adopting to Gtk3 当采用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 accepts the connection to the signal, but my function is never executed. Python接受与信号的连接,但是我的函数从未执行。

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()

works for me. 为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM