mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
If available, use wl-paste for grabclipboard() on Linux
This commit is contained in:
parent
2ea9497f8c
commit
ccac854077
|
@ -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(NotImplementedError) as e:
|
||||||
assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only"
|
ImageGrab.grabclipboard()
|
||||||
|
assert (
|
||||||
|
str(e.value)
|
||||||
|
== "wl-paste is required for ImageGrab.grabclipboard() on Linux"
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
ImageGrab.grabclipboard()
|
ImageGrab.grabclipboard()
|
||||||
|
|
|
@ -132,4 +132,14 @@ 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 not shutil.which("wl-paste"):
|
||||||
|
raise NotImplementedError(
|
||||||
|
"wl-paste is required for ImageGrab.grabclipboard() on Linux"
|
||||||
|
)
|
||||||
|
fh, filepath = tempfile.mkstemp()
|
||||||
|
subprocess.call(["wl-paste"], stdout=fh)
|
||||||
|
os.close(fh)
|
||||||
|
im = Image.open(filepath)
|
||||||
|
im.load()
|
||||||
|
os.unlink(filepath)
|
||||||
|
return im
|
||||||
|
|
Loading…
Reference in New Issue
Block a user