How do I set the clipboard with a Texture in Gdk4 using Python?

93 Views Asked by At

nautilus-image-copypaste is a Nautilus extension that allows users to set the clipboard from image files and to create image files from the clipboard. Reading the clipboard works, however I can't figure out how to set the clipboard at line 108.

The Python Gdk4 bindings do not have the set_texture method, which would have been the obvious choice.

The set method, which is available in the bindings, requires a GType (GDK_TYPE_TEXTURE), but I've been unable find that in the bindings.

1

There are 1 best solutions below

0
icyrock.com On

This should work:

texture = Gdk.Texture.new_from_filename('/path/to/image.jpg')
png_bytes = texture.save_to_png_bytes()
content_provider = Gdk.ContentProvider.new_for_bytes('image/png', png_bytes)
Gdk.Display.get_default().get_clipboard().set_content(content_provider)