Skip to content

Commit

Permalink
linux: several fixes, and tests (BoboTiG#234)
Browse files Browse the repository at this point in the history
* test: Linux with cursor

* refactor!: trying to improve Linux issues

* doc + more private stuff

* doc
  • Loading branch information
BoboTiG authored Apr 8, 2023
1 parent f928310 commit c20d95d
Show file tree
Hide file tree
Showing 25 changed files with 543 additions and 403 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ jobs:
run: |
python -m pip install -U pip wheel
python -m pip install -r dev-requirements.txt
- name: Tests on GNU/Linux
- name: Install Xvfb
if: matrix.os.emoji == '🐧'
run: sudo apt install xvfb
- name: Tests (GNU/Linux)
if: matrix.os.emoji == '🐧'
run: |
export DISPLAY=:99
sudo Xvfb -ac ${DISPLAY} -screen 0 1280x1024x24 > /dev/null 2>&1 &
python -m pytest
- name: Tests on other platforms
- name: Tests (macOS, Windows)
if: matrix.os.emoji != '🐧'
run: python -m pytest
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
disable = locally-disabled, too-few-public-methods, too-many-instance-attributes, duplicate-code

[REPORTS]
max-line-length = 120
output-format = colorized
reports = no
12 changes: 7 additions & 5 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ History:
<see Git checking messages for history>

8.0.0 2023/0x/xx
- Linux: added mouse support (partially fixes #55)
- Linux: removed get_error_details(), use the ScreenShotError details attribute instead
- dev: removed pre-commit
- tests: removed tox
- tests: added PyPy 3.9
- Linux: added mouse support (#232)
- Linux: refactored how internal handles are stored to fix issues with multiple X servers, and TKinter.
No more side effects, and when leaving the context manager, resources are all freed (#224, #234)
- ci: added PyPy 3.9 (#226)
- dev: removed pre-commit (#226)
- tests: removed tox (#226)
- tests: improved coverage (#234)

7.0.1 2022/10/27
- fixed the wheel package
Expand Down
94 changes: 59 additions & 35 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,50 +1,74 @@
8.0.0 (2023-xx-xx)
==================

base.py
-------
- Added ``compression_level=6`` keyword argument to ``MSS.__init__()``
- Added ``display=None`` keyword argument to ``MSS.__init__()``
- Added ``max_displays=32`` keyword argument to ``MSS.__init__()``
- Added ``with_cursor=False`` keyword argument to ``MSS.__init__()``
- Added ``MSS.with_cursor`` attribute

linux.py
--------
- Added ``MSS.close()``
- Moved ``MSS.__init__()`` keyword arguments handling to the base class
- Renamed ``error_handler()`` function to ``__error_handler()``
- Renamed ``_validate()`` function to ``___validate()``
- Renamed ``MSS.has_extension()`` method to ``_is_extension_enabled()``
- Removed ``ERROR`` namespace
- Removed ``MSS.drawable`` attribute
- Removed ``MSS.root`` attribute
- Removed ``MSS.get_error_details()`` method. Use ``ScreenShotError.details`` attribute instead.


6.1.0 (2020-10-31)
==================

darwin.py
---------
- Added ``CFUNCTIONS``
- Added ``CFUNCTIONS``

linux.py
--------
- Added ``CFUNCTIONS``
- Added ``CFUNCTIONS``

windows.py
----------
- Added ``CFUNCTIONS``
- Added ``MONITORNUMPROC``
- Removed ``MSS.monitorenumproc``. Use ``MONITORNUMPROC`` instead.
- Added ``CFUNCTIONS``
- Added ``MONITORNUMPROC``
- Removed ``MSS.monitorenumproc``. Use ``MONITORNUMPROC`` instead.


6.0.0 (2020-06-30)
==================

base.py
-------
- Added ``lock``
- Added ``MSS._grab_impl()`` (abstract method)
- Added ``MSS._monitors_impl()`` (abstract method)
- ``MSS.grab()`` is no more an abstract method
- ``MSS.monitors`` is no more an abstract property
- Added ``lock``
- Added ``MSS._grab_impl()`` (abstract method)
- Added ``MSS._monitors_impl()`` (abstract method)
- ``MSS.grab()`` is no more an abstract method
- ``MSS.monitors`` is no more an abstract property

darwin.py
---------
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``

linux.py
--------
- Added ``MSS.has_extension()``
- Removed ``MSS.display``
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
- Added ``MSS.has_extension()``
- Removed ``MSS.display``
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``

windows.py
----------
- Removed ``MSS._lock``
- Renamed ``MSS.srcdc_dict`` to ``MSS._srcdc_dict``
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
- Removed ``MSS._lock``
- Renamed ``MSS.srcdc_dict`` to ``MSS._srcdc_dict``
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``


5.1.0 (2020-04-30)
Expand All @@ -59,20 +83,20 @@ base.py

windows.py
----------
- Replaced ``MSS.srcdc`` with ``MSS.srcdc_dict``
- Replaced ``MSS.srcdc`` with ``MSS.srcdc_dict``


5.0.0 (2019-12-31)
==================

darwin.py
---------
- Added `MSS.__slots__`
- Added ``MSS.__slots__``

linux.py
--------
- Added `MSS.__slots__`
- Deleted `MSS.close()`
- Added ``MSS.__slots__``
- Deleted ``MSS.close()``
- Deleted ``LAST_ERROR`` constant. Use ``ERROR`` namespace instead, specially the ``ERROR.details`` attribute.

models.py
Expand All @@ -92,8 +116,8 @@ screenshot.py

windows.py
----------
- Added `MSS.__slots__`
- Deleted `MSS.close()`
- Added ``MSS.__slots__``
- Deleted ``MSS.close()``


4.0.1 (2019-01-26)
Expand Down Expand Up @@ -149,15 +173,15 @@ windows.py

base.py
-------
- Added ``MSSBase.compression_level`` to control the PNG compression level
- Added ``MSSBase.compression_level`` attribute

linux.py
--------
- Added ``MSS.drawable`` to speed-up grabbing.
- Added ``MSS.drawable`` attribute

screenshot.py
-------------
- Added ``Screenshot.bgra`` to get BGRA bytes.
- Added ``Screenshot.bgra`` attribute

tools.py
--------
Expand All @@ -181,19 +205,19 @@ __main__.py

base.py
-------
- Moved ``ScreenShot`` class to screenshot.py
- Moved ``ScreenShot`` class to ``screenshot.py``

darwin.py
---------
- Added ``CGPoint.__repr__()``
- Added ``CGRect.__repr__()``
- Added ``CGSize.__repr__()``
- Added ``CGPoint.__repr__()`` function
- Added ``CGRect.__repr__()`` function
- Added ``CGSize.__repr__()`` function
- Removed ``get_infinity()`` function

windows.py
----------
- Added ``scale()`` method to ``MSS`` class
- Added ``scale_factor`` property to ``MSS`` class
- Added ``MSS.scale()`` method
- Added ``MSS.scale_factor`` property


3.0.0 (2017-07-06)
Expand Down
2 changes: 1 addition & 1 deletion check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Small script to ensure quality checks pass before submitting a commit/PR.
#
python -m isort docs mss
python -m black docs mss
python -m black --line-length=120 docs mss
python -m flake8 docs mss
python -m pylint mss
# "--platform win32" to not fail on ctypes.windll (it does not affect the overall check on other OSes)
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pylint
sphinx
twine
wheel
xvfbwrapper; sys_platform == "linux"
97 changes: 74 additions & 23 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,60 @@ macOS

.. attribute:: CFUNCTIONS

.. versionadded:: 6.1.0

.. function:: cgfloat

.. class:: CGPoint

.. class:: CGSize

.. class:: CGRect

.. class:: MSS

.. attribute:: core

.. attribute:: max_displays

GNU/Linux
---------

.. module:: mss.linux

.. attribute:: CFUNCTIONS

.. versionadded:: 6.1.0

.. attribute:: PLAINMASK

.. attribute:: ZPIXMAP

.. class:: MSS
.. class:: Display

.. method:: __init__([display=None, with_cursor=False])
.. class:: Event

:type display: str or None
:param display: The display to use.
:param with_cursor: Include the mouse cursor in screenshots.
.. class:: XFixesCursorImage

GNU/Linux initializations.
.. class:: XWindowAttributes

.. versionadded:: 8.0.0
`with_cursor` keyword argument.
.. class:: XImage

.. method:: grab(monitor)
.. class:: XRRModeInfo

:rtype: :class:`~mss.base.ScreenShot`
:raises ScreenShotError: When color depth is not 32 (rare).
.. class:: XRRScreenResources

See :meth:`~mss.base.MSSBase.grab()` for details.
.. class:: XRRCrtcInfo

.. function:: error_handler(display, event)
.. class:: MSS

:type display: ctypes.POINTER(Display)
:param display: The display impacted by the error.
:type event: ctypes.POINTER(Event)
:param event: XError details.
:return int: Always ``0``.
.. attribute:: core

Error handler passed to `X11.XSetErrorHandler()` to catch any error that can happen when calling a X11 function.
This will prevent Python interpreter crashes.
.. method:: close()

When such an error happen, a :class:`~mss.exception.ScreenShotError` exception is raised and all `XError` information are added to the :attr:`~mss.exception.ScreenShotError.details` attribute.
Clean-up method.

.. versionadded:: 3.3.0
.. versionadded:: 8.0.0

Windows
-------
Expand All @@ -67,28 +76,70 @@ Windows

.. attribute:: CFUNCTIONS

.. versionadded:: 6.1.0

.. attribute:: DIB_RGB_COLORS

.. attribute:: SRCCOPY

.. class:: BITMAPINFOHEADER

.. class:: BITMAPINFO

.. attribute:: MONITORNUMPROC

.. versionadded:: 6.1.0

.. class:: MSS

.. attribute:: gdi32

.. attribute:: user32

Methods
=======

.. module:: mss.base

.. attribute:: lock

.. versionadded:: 6.0.0

.. class:: MSSBase

The parent's class for every OS implementation.

.. attribute:: cls_image

.. attribute:: compression_level

PNG compression level used when saving the screenshot data into a file (see :py:func:`zlib.compress()` for details).

.. versionadded:: 3.2.0

.. attribute:: with_cursor

Include the mouse cursor in screenshots.

.. versionadded:: 8.0.0

.. method:: __init__(compression_level=6, display=None, max_displays=32, with_cursor=False)

:type compression_level: int
:param compression_level: PNG compression level.
:type display: bytes, str or None
:param display: The display to use. Only effective on GNU/Linux.
:type max_displays: int
:param max_displays: Maximum number of displays. Only effective on macOS.
:type with_cursor: bool
:param with_cursor: Include the mouse cursor in screenshots.

.. versionadded:: 8.0.0
``compression_level``, ``display``, ``max_displays``, and ``with_cursor``, keyword arguments.

.. method:: close()

Clean-up method. Does nothing by default.
Clean-up method.

.. versionadded:: 4.0.0

Expand Down
Loading

0 comments on commit c20d95d

Please sign in to comment.