8

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.

user1773242
  • 194
  • 6
  • What signal was that in PyGTK? I don't know of it. – ptomato Oct 25 '12 at 07:31
  • I could use the signal 'owner-change'. clipboard.connect accepts the signal even in GTK3, but the function I attach is never called. – user1773242 Oct 25 '12 at 08:40
  • The documentation of that signal says it is fired when the owner of the clipboard selection is changed. Not when the contents are changed. If you're going to rely on undocumented behavior, then you have to expect it to break. – ptomato Oct 25 '12 at 09:51
  • I realise that, which is why I asked for the 'best practice' to get this functionality. – user1773242 Oct 25 '12 at 10:31
  • Interesting question. The "owner-change" is obviously the wrong signal but I couldn't say what the right solution is. – Micah Carrick Nov 14 '12 at 00:40

1 Answers1

3
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.

Martin von Wittich
  • 350
  • 1
  • 5
  • 19
  • Strange! It works now, I must have had some kind of strange setup in my environment. However, Is the 'Owner-change' signal intended for this? – user1773242 Nov 26 '12 at 10:23