mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Merge pull request #6783 from radarhere/grabclipboard
If available, use wl-paste or xclip for grabclipboard() on Linux
This commit is contained in:
commit
e107af41a9
|
@ -64,9 +64,13 @@ $bmp = New-Object Drawing.Bitmap 200, 200
|
||||||
)
|
)
|
||||||
p.communicate()
|
p.communicate()
|
||||||
else:
|
else:
|
||||||
with pytest.raises(NotImplementedError) as e:
|
if not shutil.which("wl-paste"):
|
||||||
ImageGrab.grabclipboard()
|
with pytest.raises(
|
||||||
assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only"
|
NotImplementedError,
|
||||||
|
match="wl-paste or xclip is required for"
|
||||||
|
r" ImageGrab.grabclipboard\(\) on Linux",
|
||||||
|
):
|
||||||
|
ImageGrab.grabclipboard()
|
||||||
return
|
return
|
||||||
|
|
||||||
ImageGrab.grabclipboard()
|
ImageGrab.grabclipboard()
|
||||||
|
|
|
@ -132,4 +132,18 @@ def grabclipboard():
|
||||||
return BmpImagePlugin.DibImageFile(data)
|
return BmpImagePlugin.DibImageFile(data)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("ImageGrab.grabclipboard() is macOS and Windows only")
|
if shutil.which("wl-paste"):
|
||||||
|
args = ["wl-paste"]
|
||||||
|
elif shutil.which("xclip"):
|
||||||
|
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(
|
||||||
|
"wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
||||||
|
)
|
||||||
|
fh, filepath = tempfile.mkstemp()
|
||||||
|
subprocess.call(args, stdout=fh)
|
||||||
|
os.close(fh)
|
||||||
|
im = Image.open(filepath)
|
||||||
|
im.load()
|
||||||
|
os.unlink(filepath)
|
||||||
|
return im
|
||||||
|
|
Loading…
Reference in New Issue
Block a user