mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
If available, use xclip for grabclipboard() on Linux
This commit is contained in:
parent
ccac854077
commit
2ecf88eaa6
|
@ -68,8 +68,8 @@ $bmp = New-Object Drawing.Bitmap 200, 200
|
|||
with pytest.raises(NotImplementedError) as e:
|
||||
ImageGrab.grabclipboard()
|
||||
assert (
|
||||
str(e.value)
|
||||
== "wl-paste is required for ImageGrab.grabclipboard() on Linux"
|
||||
str(e.value) == "wl-paste or xclip is required"
|
||||
" for ImageGrab.grabclipboard() on Linux"
|
||||
)
|
||||
return
|
||||
|
||||
|
|
|
@ -132,12 +132,16 @@ def grabclipboard():
|
|||
return BmpImagePlugin.DibImageFile(data)
|
||||
return None
|
||||
else:
|
||||
if not shutil.which("wl-paste"):
|
||||
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 is required for ImageGrab.grabclipboard() on Linux"
|
||||
"wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
||||
)
|
||||
fh, filepath = tempfile.mkstemp()
|
||||
subprocess.call(["wl-paste"], stdout=fh)
|
||||
subprocess.call(args, stdout=fh)
|
||||
os.close(fh)
|
||||
im = Image.open(filepath)
|
||||
im.load()
|
||||
|
|
Loading…
Reference in New Issue
Block a user