mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Fix ImageGrab with wl-paste
This commit is contained in:
parent
8740e32619
commit
099d696dc7
|
@ -98,3 +98,22 @@ $ms = new-object System.IO.MemoryStream(, $bytes)
|
|||
|
||||
im = ImageGrab.grabclipboard()
|
||||
assert_image_equal_tofile(im, "Tests/images/hopper.png")
|
||||
|
||||
@pytest.mark.skipif(
|
||||
(
|
||||
sys.platform != "linux"
|
||||
or not all(shutil.which(cmd) for cmd in ["wl-paste", "wl-copy"])
|
||||
),
|
||||
reason="Linux with wl-clipboard only",
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"image_path", ["Tests/images/hopper.gif", "Tests/images/hopper.png"]
|
||||
)
|
||||
def test_grabclipboard_wl_clipboard(self, image_path):
|
||||
with open(image_path, mode="rb") as raw_image:
|
||||
try:
|
||||
subprocess.call(["wl-copy"], stdin=raw_image)
|
||||
im = ImageGrab.grabclipboard()
|
||||
assert_image_equal_tofile(im, image_path)
|
||||
except OSError as e:
|
||||
pytest.skip(str(e))
|
||||
|
|
|
@ -135,6 +135,12 @@ def grabclipboard():
|
|||
else:
|
||||
if shutil.which("wl-paste"):
|
||||
args = ["wl-paste"]
|
||||
output = subprocess.check_output(["wl-paste", "-l"]).decode()
|
||||
mime_types = output.splitlines()
|
||||
for image_type in ["image/gif", "image/png"]:
|
||||
if image_type in mime_types:
|
||||
args.extend(["-t", image_type])
|
||||
break
|
||||
elif shutil.which("xclip"):
|
||||
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user