Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing a file in the clipboard in python

Is there a way to use the win32clipboard module to store a reference to a file in the windows clipboard in python. My goal is to paste an image in a way that allows transparency. If I drag and drop a 'png' file into OneNote or I copy the file and then paste it into OneNote, this seems to preserve transparency. As far as I can tell, the clipboard can't store transparent images which is why it has to be a reference to a file.

My research suggests that it might involve the win32clipboard.CF_HDrop attribute but I'm not sure.

So, just to summarize, my goal is to have a bit of python code which I can click and which uses a specific file on my Desktop named 'img.png' for instance. The result is that 'img.png' gets stored in the clipboard and can be pasted into other programs. Essentially, the same behavior as if I selected the file on the Desktop myself, right-clicked and selected 'Copy'.

EDIT: This page seems to suggest there is a way using win32clipboard.CF_HDrop somehow: http://timgolden.me.uk/pywin32-docs/win32clipboard__GetClipboardData_meth.html

It says "CF_HDROP" is associated with "a tuple of Unicode filenames"

like image 308
Henry B. Avatar asked Jun 13 '12 04:06

Henry B.


1 Answers

from PythonMagick import Image
Image("img.png").write("clipboard:") 

Grab the windows binaries for PythonMagick

like image 72
Burhan Khalid Avatar answered Oct 05 '22 01:10

Burhan Khalid