views:

160

answers:

1

How do I paste HTML data from the X clipboard using PyGTK/GTK+?

I would need something like xclip, but with the ability to output clipboard data as HTML, not just as plain text. I'm using PyGTK, but I am not afraid of plain GTK+ in C.

I've read GtkClipboard and PyGTK's gtk.Clipboard references, and I've found this question, but I would need a small example to get me started.

A: 

Found it. I used something like this:

clipboard = gtk.Clipboard()
target = "text/html"
clipboard.wait_for_contents(target)
clipboard.request_contents(target, dump_clipboard_callback)

And then the callback function can simply extract the data:

def dump_clipboard_callback(clipboard, selection_data, data=None):
    print selection_data.data
Danilo Piazzalunga