Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/grabclipboard
Browse files Browse the repository at this point in the history
Rearranged code
  • Loading branch information
nik012003 committed Jan 27, 2024
2 parents cd640e5 + d2d9240 commit 1522b3f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,21 @@ def grabclipboard():
raise NotImplementedError(msg)

p = subprocess.run(args, capture_output=True)
err = p.stderr.decode()
if p.returncode != 0:
allowed_errors = [
"Nothing is copied", # wl-paste, when the clipboard is empty
"not available", # wl-paste/debian xclip, when an image isn't available
"cannot convert", # xclip, when an image isn't available
"There is no owner", # xclip, when the clipboard isn't initialized
# wl-paste, when the clipboard is empty
b"Nothing is copied",
# wl-paste/debian xclip, when an image isn't available
b"not available",
# xclip, when an image isn't available
b"cannot convert",
# xclip, when the clipboard isn't initialized
b"There is no owner",
]
err = p.stderr
if any(e in err for e in allowed_errors):
return None
msg = f"{args[0]} error: {err.strip() if err else 'Unknown error'}"
msg = f"{args[0]} error: {err.strip().decode() if err else 'Unknown error'}"
raise ChildProcessError(msg)

data = io.BytesIO(p.stdout)
Expand Down

0 comments on commit 1522b3f

Please sign in to comment.