mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +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:
|
with pytest.raises(NotImplementedError) as e:
|
||||||
ImageGrab.grabclipboard()
|
ImageGrab.grabclipboard()
|
||||||
assert (
|
assert (
|
||||||
str(e.value)
|
str(e.value) == "wl-paste or xclip is required"
|
||||||
== "wl-paste is required for ImageGrab.grabclipboard() on Linux"
|
" for ImageGrab.grabclipboard() on Linux"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -132,12 +132,16 @@ def grabclipboard():
|
||||||
return BmpImagePlugin.DibImageFile(data)
|
return BmpImagePlugin.DibImageFile(data)
|
||||||
return None
|
return None
|
||||||
else:
|
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(
|
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()
|
fh, filepath = tempfile.mkstemp()
|
||||||
subprocess.call(["wl-paste"], stdout=fh)
|
subprocess.call(args, stdout=fh)
|
||||||
os.close(fh)
|
os.close(fh)
|
||||||
im = Image.open(filepath)
|
im = Image.open(filepath)
|
||||||
im.load()
|
im.load()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user