Storage file on clipboard in python

Is there a way to use the win32clipboard module to store a link to a file on the Windows clipboard in python. My goal is to insert an image in such a way as to provide transparency. If I drag the “png” file into OneNote or copy the file and then paste it into OneNote, this seems to preserve transparency. As far as I can tell, the clipboard cannot store transparent images, so it should be a link to the file.

My research shows that it may include the win32clipboard.CF_HDrop attribute, but I'm not sure.

So, just to summarize, my goal is to have some python code that I can click, and which, for example, uses a specific file on my desktop called "img.png". As a result, "img.png" is saved in the clipboard and can be pasted into other programs. In fact, the same behavior as if I myself selected a file on the desktop, right-clicked and chose Copy.

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

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

+5
source share
2
from PythonMagick import Image
Image("img.png").write("clipboard:") 

Windows PythonMagick

0

, , , .

script:

import win32clipboard as clp, win32api

clp.OpenClipboard(None)

rc= clp.EnumClipboardFormats(0)
while rc:
    try: format_name= clp.GetClipboardFormatName(rc)
    except win32api.error: format_name= "?"
    print "format", rc, format_name
    rc= clp.EnumClipboardFormats(rc)

clp.CloseClipboard()

; script :

format 49161 DataObject
format 49268 Shell IDList Array
format 15 ?
format 49519 DataObjectAttributes
format 49292 Preferred DropEffect
format 49329 Shell Object Offsets
format 49158 FileName
format 49159 FileNameW
format 49171 Ole Private Data

" DropEffect" , Windows. FileNameW, ( OneNote, ). , , , "utf-16-le" (.. '\0\0') .

+1

All Articles