Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python and gtk3 clipboard onChange

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.

like image 643
user1773242 Avatar asked Oct 25 '12 06:10

user1773242


1 Answers

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.

like image 58
Martin von Wittich Avatar answered Sep 28 '22 05:09

Martin von Wittich