fix docs compliance for CF_HDROP

This commit is contained in:
nulano 2020-05-09 10:40:10 +02:00
parent 5728662c7f
commit 1656edaf41
3 changed files with 15 additions and 30 deletions

View File

@ -1,3 +1,4 @@
import os
import subprocess import subprocess
import sys import sys
@ -79,7 +80,8 @@ $bmp = New-Object Drawing.Bitmap 200, 200
p.communicate() p.communicate()
im = ImageGrab.grabclipboard() im = ImageGrab.grabclipboard()
assert_image_equal_tofile(im, "Tests/images/hopper.gif") assert len(im) == 1
assert os.path.samefile(im[0], "Tests/images/hopper.gif")
@pytest.mark.skipif(sys.platform != "win32", reason="Windows only") @pytest.mark.skipif(sys.platform != "win32", reason="Windows only")
def test_grabclipboard_png(self): def test_grabclipboard_png(self):

View File

@ -93,15 +93,20 @@ def grabclipboard():
os.unlink(filepath) os.unlink(filepath)
return im return im
elif sys.platform == "win32": elif sys.platform == "win32":
import io
fmt, data = Image.core.grabclipboard_win32() fmt, data = Image.core.grabclipboard_win32()
if isinstance(data, str): if fmt == "file": # CF_HDROP
if fmt == "file": import struct
with open(data, "rb") as f:
im = Image.open(io.BytesIO(f.read())) o = struct.unpack_from("I", data)[0]
return im if data[16] != 0:
files = data[o:].decode("utf-16le").split("\0")
return files[: files.index("")]
else:
files = data[o:].decode("mbcs").split("\0")
return files[: files.index("")]
if isinstance(data, bytes): if isinstance(data, bytes):
import io
data = io.BytesIO(data) data = io.BytesIO(data)
if fmt == "png": if fmt == "png":
from . import PngImagePlugin from . import PngImagePlugin

View File

@ -32,7 +32,6 @@
#ifdef _WIN32 #ifdef _WIN32
#include <Shlobj.h>
#include "ImDib.h" #include "ImDib.h"
#if SIZEOF_VOID_P == 8 #if SIZEOF_VOID_P == 8
@ -504,27 +503,6 @@ PyImaging_GrabClipboardWin32(PyObject* self, PyObject* args)
return Py_BuildValue("zO", NULL, Py_None); return Py_BuildValue("zO", NULL, Py_None);
} }
if (formats[format] == CF_HDROP) {
LPDROPFILES files = (LPDROPFILES)GlobalLock(handle);
size = GlobalSize(handle);
if (files->fWide) {
LPCWSTR filename = (LPCWSTR)(((char*)files) + files->pFiles);
size = wcsnlen(filename, (size - files->pFiles) / 2);
result = Py_BuildValue("zu#", "file", filename, size);
}
else {
LPCSTR filename = (LPCSTR)(((char*)files) + files->pFiles);
size = strnlen(filename, size - files->pFiles);
result = Py_BuildValue("zs#", "file", filename, size);
}
GlobalUnlock(handle);
CloseClipboard();
return result;
}
data = GlobalLock(handle); data = GlobalLock(handle);
size = GlobalSize(handle); size = GlobalSize(handle);