mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 03:21:44 +03:00
xcb screengrab docs and fixes
This commit is contained in:
parent
f9c74825a6
commit
0bcc7be89b
|
@ -46,9 +46,6 @@ class TestImageGrab:
|
||||||
assert isinstance(exception, IOError)
|
assert isinstance(exception, IOError)
|
||||||
assert str(exception).startswith("X connection failed")
|
assert str(exception).startswith("X connection failed")
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
|
||||||
sys.platform not in ("win32", "darwin"), reason="requires Windows or macOS"
|
|
||||||
)
|
|
||||||
def test_grabclipboard(self):
|
def test_grabclipboard(self):
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
subprocess.call(["screencapture", "-cx"])
|
subprocess.call(["screencapture", "-cx"])
|
||||||
|
@ -62,7 +59,15 @@ $bmp = New-Object Drawing.Bitmap 200, 200
|
||||||
)
|
)
|
||||||
p.communicate()
|
p.communicate()
|
||||||
else:
|
else:
|
||||||
pytest.skip("ImageGrab.grabclipboard() is macOS and Windows only")
|
exception = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
ImageGrab.grabclipboard()
|
||||||
|
except IOError as e:
|
||||||
|
exception = e
|
||||||
|
|
||||||
|
assert isinstance(exception, IOError)
|
||||||
|
assert str(exception) == "ImageGrab.grabclipboard() is macOS and Windows only"
|
||||||
return
|
return
|
||||||
|
|
||||||
im = ImageGrab.grabclipboard()
|
im = ImageGrab.grabclipboard()
|
||||||
|
|
|
@ -11,13 +11,13 @@ or the clipboard to a PIL image memory.
|
||||||
|
|
||||||
.. versionadded:: 1.1.3
|
.. versionadded:: 1.1.3
|
||||||
|
|
||||||
.. py:function:: PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False)
|
.. py:function:: PIL.ImageGrab.grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None)
|
||||||
|
|
||||||
Take a snapshot of the screen. The pixels inside the bounding box are
|
Take a snapshot of the screen. The pixels inside the bounding box are
|
||||||
returned as an "RGB" image on Windows or "RGBA" on macOS.
|
returned as an "RGB" image on Windows or "RGBA" on macOS.
|
||||||
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 (Windows), 3.0.0 (macOS)
|
.. versionadded:: 1.1.3 (Windows), 3.0.0 (macOS), 7.0.0 (Linux (X11))
|
||||||
|
|
||||||
:param bbox: What region to copy. Default is the entire screen.
|
:param bbox: What region to copy. Default is the entire screen.
|
||||||
Note that on Windows OS, the top-left point may be negative if ``all_screens=True`` is used.
|
Note that on Windows OS, the top-left point may be negative if ``all_screens=True`` is used.
|
||||||
|
@ -27,6 +27,11 @@ or the clipboard to a PIL image memory.
|
||||||
:param all_screens: Capture all monitors. Windows OS only.
|
:param all_screens: Capture all monitors. Windows OS only.
|
||||||
|
|
||||||
.. versionadded:: 6.2.0
|
.. versionadded:: 6.2.0
|
||||||
|
|
||||||
|
:param xdisplay: X11 Display address. Pass ``None`` to grab the default system screen.
|
||||||
|
Pass ``""`` to grab the default X11 screen on Windows or macOS.
|
||||||
|
|
||||||
|
.. versionadded:: 7.0.0
|
||||||
:return: An image
|
:return: An image
|
||||||
|
|
||||||
.. py:function:: PIL.ImageGrab.grabclipboard()
|
.. py:function:: PIL.ImageGrab.grabclipboard()
|
||||||
|
|
|
@ -15,10 +15,7 @@
|
||||||
# See the README file for information on usage and redistribution.
|
# See the README file for information on usage and redistribution.
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
|
||||||
import subprocess
|
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
|
|
||||||
|
@ -26,10 +23,6 @@ if sys.platform == "darwin":
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
elif sys.platform == "win32":
|
|
||||||
pass
|
|
||||||
elif not Image.core.HAVE_XCB:
|
|
||||||
raise ImportError("ImageGrab requires Windows, macOS, or the XCB library")
|
|
||||||
|
|
||||||
|
|
||||||
def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None):
|
def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=None):
|
||||||
|
@ -47,7 +40,9 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
|
||||||
return im_cropped
|
return im_cropped
|
||||||
return im
|
return im
|
||||||
elif sys.platform == "win32":
|
elif sys.platform == "win32":
|
||||||
offset, size, data = Image.core.grabscreen(include_layered_windows, all_screens)
|
offset, size, data = Image.core.grabscreen_win32(
|
||||||
|
include_layered_windows, all_screens
|
||||||
|
)
|
||||||
im = Image.frombytes(
|
im = Image.frombytes(
|
||||||
"RGB",
|
"RGB",
|
||||||
size,
|
size,
|
||||||
|
@ -65,7 +60,7 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
|
||||||
return im
|
return im
|
||||||
# use xdisplay=None for default display on non-win32/macOS systems
|
# use xdisplay=None for default display on non-win32/macOS systems
|
||||||
if not Image.core.HAVE_XCB:
|
if not Image.core.HAVE_XCB:
|
||||||
raise AttributeError("XCB support not present")
|
raise IOError("Pillow was built without XCB support")
|
||||||
size, data = Image.core.grabscreen_x11(xdisplay)
|
size, data = Image.core.grabscreen_x11(xdisplay)
|
||||||
im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
|
im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
|
||||||
if bbox:
|
if bbox:
|
||||||
|
@ -105,3 +100,5 @@ def grabclipboard():
|
||||||
|
|
||||||
return BmpImagePlugin.DibImageFile(io.BytesIO(data))
|
return BmpImagePlugin.DibImageFile(io.BytesIO(data))
|
||||||
return data
|
return data
|
||||||
|
else:
|
||||||
|
raise IOError("ImageGrab.grabclipboard() is macOS and Windows only")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user