1

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.

Reece
  • 7,616
  • 4
  • 30
  • 46

1 Answers1

0

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)
icyrock.com
  • 27,952
  • 4
  • 66
  • 85