python and gtk3 clipboard onChange

偶尔善良 提交于 2019-12-23 09:31:56

问题


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?

EDIT

With gtk2 the following works:

import gtk

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

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

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 accepts the connection to the signal, but my function is never executed.


回答1:


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.



来源:https://stackoverflow.com/questions/13062545/python-and-gtk3-clipboard-onchange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!