mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 13:40:54 +03:00
Do not use temporary file when grabbing clipboard on Linux
This commit is contained in:
parent
9a560c78a8
commit
97bd53392c
|
@ -15,6 +15,7 @@
|
||||||
# See the README file for information on usage and redistribution.
|
# See the README file for information on usage and redistribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -128,8 +129,6 @@ def grabclipboard():
|
||||||
files = data[o:].decode("mbcs").split("\0")
|
files = data[o:].decode("mbcs").split("\0")
|
||||||
return files[: files.index("")]
|
return files[: files.index("")]
|
||||||
if isinstance(data, bytes):
|
if isinstance(data, bytes):
|
||||||
import io
|
|
||||||
|
|
||||||
data = io.BytesIO(data)
|
data = io.BytesIO(data)
|
||||||
if fmt == "png":
|
if fmt == "png":
|
||||||
from . import PngImagePlugin
|
from . import PngImagePlugin
|
||||||
|
@ -159,13 +158,12 @@ def grabclipboard():
|
||||||
else:
|
else:
|
||||||
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
fh, filepath = tempfile.mkstemp()
|
p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
err = subprocess.run(args, stdout=fh, stderr=subprocess.PIPE).stderr
|
err = p.stderr
|
||||||
os.close(fh)
|
|
||||||
if err:
|
if err:
|
||||||
msg = f"{args[0]} error: {err.strip().decode()}"
|
msg = f"{args[0]} error: {err.strip().decode()}"
|
||||||
raise ChildProcessError(msg)
|
raise ChildProcessError(msg)
|
||||||
im = Image.open(filepath)
|
data = io.BytesIO(p.stdout)
|
||||||
|
im = Image.open(data)
|
||||||
im.load()
|
im.load()
|
||||||
os.unlink(filepath)
|
|
||||||
return im
|
return im
|
||||||
|
|
Loading…
Reference in New Issue
Block a user