mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
Added OS X support for ImageGrab grabclipboard
This commit is contained in:
parent
90955e4953
commit
935ac523bf
|
@ -51,11 +51,31 @@ def grab(bbox=None):
|
||||||
|
|
||||||
def grabclipboard():
|
def grabclipboard():
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
raise NotImplementedError("Method is not implemented on OS X")
|
f, file = tempfile.mkstemp('.jpg')
|
||||||
debug = 0 # temporary interface
|
os.close(f)
|
||||||
data = Image.core.grabclipboard(debug)
|
commands = [
|
||||||
if isinstance(data, bytes):
|
"set theFile to (open for access POSIX file \""+file+"\" with write permission)",
|
||||||
from PIL import BmpImagePlugin
|
"try",
|
||||||
import io
|
"write (the clipboard as JPEG picture) to theFile",
|
||||||
return BmpImagePlugin.DibImageFile(io.BytesIO(data))
|
"end try",
|
||||||
return data
|
"close access theFile"
|
||||||
|
]
|
||||||
|
script = ["osascript"]
|
||||||
|
for command in commands:
|
||||||
|
script += ["-e", command]
|
||||||
|
subprocess.call(script)
|
||||||
|
|
||||||
|
im = None
|
||||||
|
if os.stat(file).st_size != 0:
|
||||||
|
im = Image.open(file)
|
||||||
|
im.load()
|
||||||
|
os.unlink(file)
|
||||||
|
return im
|
||||||
|
else:
|
||||||
|
debug = 0 # temporary interface
|
||||||
|
data = Image.core.grabclipboard(debug)
|
||||||
|
if isinstance(data, bytes):
|
||||||
|
from PIL import BmpImagePlugin
|
||||||
|
import io
|
||||||
|
return BmpImagePlugin.DibImageFile(io.BytesIO(data))
|
||||||
|
return data
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
The :py:mod:`ImageGrab` module can be used to copy the contents of the screen
|
The :py:mod:`ImageGrab` module can be used to copy the contents of the screen
|
||||||
or the clipboard to a PIL image memory.
|
or the clipboard to a PIL image memory.
|
||||||
|
|
||||||
.. note:: The current version works on OS X and Windows only. OS X support was added in 3.0.0.
|
.. note:: The current version works on OS X and Windows only.
|
||||||
|
|
||||||
.. versionadded:: 1.1.3
|
.. versionadded:: 1.1.3
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ or the clipboard to a PIL image memory.
|
||||||
returned as an "RGB" image on Windows or "RGBA" on OS X.
|
returned as an "RGB" image on Windows or "RGBA" on OS X.
|
||||||
If the bounding box is omitted, the entire screen is copied.
|
If the bounding box is omitted, the entire screen is copied.
|
||||||
|
|
||||||
.. versionadded:: 1.1.3
|
.. versionadded:: 1.1.3 (Windows), 3.0.0 (OS X)
|
||||||
|
|
||||||
:param bbox: What region to copy. Default is the entire screen.
|
:param bbox: What region to copy. Default is the entire screen.
|
||||||
:return: An image
|
:return: An image
|
||||||
|
@ -26,10 +26,11 @@ or the clipboard to a PIL image memory.
|
||||||
|
|
||||||
Take a snapshot of the clipboard image, if any.
|
Take a snapshot of the clipboard image, if any.
|
||||||
|
|
||||||
.. versionadded:: 1.1.4
|
.. versionadded:: 1.1.4 (Windows), 3.3.0 (OS X)
|
||||||
|
|
||||||
:return: On Windows, an image, a list of filenames,
|
:return: On Windows, an image, a list of filenames,
|
||||||
or None if the clipboard does not contain image data or filenames.
|
or None if the clipboard does not contain image data or filenames.
|
||||||
Note that if a list is returned, the filenames may not represent image files.
|
Note that if a list is returned, the filenames may not represent image files.
|
||||||
|
|
||||||
On Mac, this is not currently supported.
|
On Mac, an image,
|
||||||
|
or None if the clipboard does not contain image data.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user