mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +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()
|
||||
else:
|
||||
with pytest.raises(NotImplementedError) as e:
|
||||
ImageGrab.grabclipboard()
|
||||
assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only"
|
||||
if not shutil.which("wl-paste"):
|
||||
with pytest.raises(NotImplementedError) as e:
|
||||
ImageGrab.grabclipboard()
|
||||
assert (
|
||||
str(e.value)
|
||||
== "wl-paste is required for ImageGrab.grabclipboard() on Linux"
|
||||
)
|
||||
return
|
||||
|
||||
ImageGrab.grabclipboard()
|
||||
|
|
|
@ -132,4 +132,14 @@ def grabclipboard():
|
|||
return BmpImagePlugin.DibImageFile(data)
|
||||
return None
|
||||
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