Skip to content

Commit c20d95d

Browse files
authored
linux: several fixes, and tests (#234)
* test: Linux with cursor * refactor!: trying to improve Linux issues * doc + more private stuff * doc
1 parent f928310 commit c20d95d

25 files changed

+543
-403
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ jobs:
7979
run: |
8080
python -m pip install -U pip wheel
8181
python -m pip install -r dev-requirements.txt
82-
- name: Tests on GNU/Linux
82+
- name: Install Xvfb
83+
if: matrix.os.emoji == '🐧'
84+
run: sudo apt install xvfb
85+
- name: Tests (GNU/Linux)
8386
if: matrix.os.emoji == '🐧'
8487
run: |
8588
export DISPLAY=:99
8689
sudo Xvfb -ac ${DISPLAY} -screen 0 1280x1024x24 > /dev/null 2>&1 &
8790
python -m pytest
88-
- name: Tests on other platforms
91+
- name: Tests (macOS, Windows)
8992
if: matrix.os.emoji != '🐧'
9093
run: python -m pytest

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
disable = locally-disabled, too-few-public-methods, too-many-instance-attributes, duplicate-code
33

44
[REPORTS]
5+
max-line-length = 120
56
output-format = colorized
67
reports = no

CHANGELOG

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ History:
33
<see Git checking messages for history>
44

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

1214
7.0.1 2022/10/27
1315
- fixed the wheel package

CHANGES.rst

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,74 @@
1+
8.0.0 (2023-xx-xx)
2+
==================
3+
4+
base.py
5+
-------
6+
- Added ``compression_level=6`` keyword argument to ``MSS.__init__()``
7+
- Added ``display=None`` keyword argument to ``MSS.__init__()``
8+
- Added ``max_displays=32`` keyword argument to ``MSS.__init__()``
9+
- Added ``with_cursor=False`` keyword argument to ``MSS.__init__()``
10+
- Added ``MSS.with_cursor`` attribute
11+
12+
linux.py
13+
--------
14+
- Added ``MSS.close()``
15+
- Moved ``MSS.__init__()`` keyword arguments handling to the base class
16+
- Renamed ``error_handler()`` function to ``__error_handler()``
17+
- Renamed ``_validate()`` function to ``___validate()``
18+
- Renamed ``MSS.has_extension()`` method to ``_is_extension_enabled()``
19+
- Removed ``ERROR`` namespace
20+
- Removed ``MSS.drawable`` attribute
21+
- Removed ``MSS.root`` attribute
22+
- Removed ``MSS.get_error_details()`` method. Use ``ScreenShotError.details`` attribute instead.
23+
24+
125
6.1.0 (2020-10-31)
226
==================
327

428
darwin.py
529
---------
6-
- Added ``CFUNCTIONS``
30+
- Added ``CFUNCTIONS``
731

832
linux.py
933
--------
10-
- Added ``CFUNCTIONS``
34+
- Added ``CFUNCTIONS``
1135

1236
windows.py
1337
----------
14-
- Added ``CFUNCTIONS``
15-
- Added ``MONITORNUMPROC``
16-
- Removed ``MSS.monitorenumproc``. Use ``MONITORNUMPROC`` instead.
38+
- Added ``CFUNCTIONS``
39+
- Added ``MONITORNUMPROC``
40+
- Removed ``MSS.monitorenumproc``. Use ``MONITORNUMPROC`` instead.
1741

1842

1943
6.0.0 (2020-06-30)
2044
==================
2145

2246
base.py
2347
-------
24-
- Added ``lock``
25-
- Added ``MSS._grab_impl()`` (abstract method)
26-
- Added ``MSS._monitors_impl()`` (abstract method)
27-
- ``MSS.grab()`` is no more an abstract method
28-
- ``MSS.monitors`` is no more an abstract property
48+
- Added ``lock``
49+
- Added ``MSS._grab_impl()`` (abstract method)
50+
- Added ``MSS._monitors_impl()`` (abstract method)
51+
- ``MSS.grab()`` is no more an abstract method
52+
- ``MSS.monitors`` is no more an abstract property
2953

3054
darwin.py
3155
---------
32-
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
33-
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
56+
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
57+
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
3458

3559
linux.py
3660
--------
37-
- Added ``MSS.has_extension()``
38-
- Removed ``MSS.display``
39-
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
40-
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
61+
- Added ``MSS.has_extension()``
62+
- Removed ``MSS.display``
63+
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
64+
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
4165

4266
windows.py
4367
----------
44-
- Removed ``MSS._lock``
45-
- Renamed ``MSS.srcdc_dict`` to ``MSS._srcdc_dict``
46-
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
47-
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
68+
- Removed ``MSS._lock``
69+
- Renamed ``MSS.srcdc_dict`` to ``MSS._srcdc_dict``
70+
- Renamed ``MSS.grab()`` to ``MSS._grab_impl()``
71+
- Renamed ``MSS.monitors`` to ``MSS._monitors_impl()``
4872

4973

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

6084
windows.py
6185
----------
62-
- Replaced ``MSS.srcdc`` with ``MSS.srcdc_dict``
86+
- Replaced ``MSS.srcdc`` with ``MSS.srcdc_dict``
6387

6488

6589
5.0.0 (2019-12-31)
6690
==================
6791

6892
darwin.py
6993
---------
70-
- Added `MSS.__slots__`
94+
- Added ``MSS.__slots__``
7195

7296
linux.py
7397
--------
74-
- Added `MSS.__slots__`
75-
- Deleted `MSS.close()`
98+
- Added ``MSS.__slots__``
99+
- Deleted ``MSS.close()``
76100
- Deleted ``LAST_ERROR`` constant. Use ``ERROR`` namespace instead, specially the ``ERROR.details`` attribute.
77101

78102
models.py
@@ -92,8 +116,8 @@ screenshot.py
92116

93117
windows.py
94118
----------
95-
- Added `MSS.__slots__`
96-
- Deleted `MSS.close()`
119+
- Added ``MSS.__slots__``
120+
- Deleted ``MSS.close()``
97121

98122

99123
4.0.1 (2019-01-26)
@@ -149,15 +173,15 @@ windows.py
149173

150174
base.py
151175
-------
152-
- Added ``MSSBase.compression_level`` to control the PNG compression level
176+
- Added ``MSSBase.compression_level`` attribute
153177

154178
linux.py
155179
--------
156-
- Added ``MSS.drawable`` to speed-up grabbing.
180+
- Added ``MSS.drawable`` attribute
157181

158182
screenshot.py
159183
-------------
160-
- Added ``Screenshot.bgra`` to get BGRA bytes.
184+
- Added ``Screenshot.bgra`` attribute
161185

162186
tools.py
163187
--------
@@ -181,19 +205,19 @@ __main__.py
181205

182206
base.py
183207
-------
184-
- Moved ``ScreenShot`` class to screenshot.py
208+
- Moved ``ScreenShot`` class to ``screenshot.py``
185209

186210
darwin.py
187211
---------
188-
- Added ``CGPoint.__repr__()``
189-
- Added ``CGRect.__repr__()``
190-
- Added ``CGSize.__repr__()``
212+
- Added ``CGPoint.__repr__()`` function
213+
- Added ``CGRect.__repr__()`` function
214+
- Added ``CGSize.__repr__()`` function
191215
- Removed ``get_infinity()`` function
192216

193217
windows.py
194218
----------
195-
- Added ``scale()`` method to ``MSS`` class
196-
- Added ``scale_factor`` property to ``MSS`` class
219+
- Added ``MSS.scale()`` method
220+
- Added ``MSS.scale_factor`` property
197221

198222

199223
3.0.0 (2017-07-06)

check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Small script to ensure quality checks pass before submitting a commit/PR.
44
#
55
python -m isort docs mss
6-
python -m black docs mss
6+
python -m black --line-length=120 docs mss
77
python -m flake8 docs mss
88
python -m pylint mss
99
# "--platform win32" to not fail on ctypes.windll (it does not affect the overall check on other OSes)

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ pylint
1313
sphinx
1414
twine
1515
wheel
16+
xvfbwrapper; sys_platform == "linux"

docs/source/api.rst

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,60 @@ macOS
1212

1313
.. attribute:: CFUNCTIONS
1414

15+
.. versionadded:: 6.1.0
16+
17+
.. function:: cgfloat
18+
19+
.. class:: CGPoint
20+
21+
.. class:: CGSize
22+
23+
.. class:: CGRect
24+
25+
.. class:: MSS
26+
27+
.. attribute:: core
28+
29+
.. attribute:: max_displays
30+
1531
GNU/Linux
1632
---------
1733

1834
.. module:: mss.linux
1935

2036
.. attribute:: CFUNCTIONS
2137

38+
.. versionadded:: 6.1.0
39+
2240
.. attribute:: PLAINMASK
2341

2442
.. attribute:: ZPIXMAP
2543

26-
.. class:: MSS
44+
.. class:: Display
2745

28-
.. method:: __init__([display=None, with_cursor=False])
46+
.. class:: Event
2947

30-
:type display: str or None
31-
:param display: The display to use.
32-
:param with_cursor: Include the mouse cursor in screenshots.
48+
.. class:: XFixesCursorImage
3349

34-
GNU/Linux initializations.
50+
.. class:: XWindowAttributes
3551

36-
.. versionadded:: 8.0.0
37-
`with_cursor` keyword argument.
52+
.. class:: XImage
3853

39-
.. method:: grab(monitor)
54+
.. class:: XRRModeInfo
4055

41-
:rtype: :class:`~mss.base.ScreenShot`
42-
:raises ScreenShotError: When color depth is not 32 (rare).
56+
.. class:: XRRScreenResources
4357

44-
See :meth:`~mss.base.MSSBase.grab()` for details.
58+
.. class:: XRRCrtcInfo
4559

46-
.. function:: error_handler(display, event)
60+
.. class:: MSS
4761

48-
:type display: ctypes.POINTER(Display)
49-
:param display: The display impacted by the error.
50-
:type event: ctypes.POINTER(Event)
51-
:param event: XError details.
52-
:return int: Always ``0``.
62+
.. attribute:: core
5363

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

57-
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.
66+
Clean-up method.
5867

59-
.. versionadded:: 3.3.0
68+
.. versionadded:: 8.0.0
6069

6170
Windows
6271
-------
@@ -67,28 +76,70 @@ Windows
6776

6877
.. attribute:: CFUNCTIONS
6978

79+
.. versionadded:: 6.1.0
80+
7081
.. attribute:: DIB_RGB_COLORS
7182

7283
.. attribute:: SRCCOPY
7384

85+
.. class:: BITMAPINFOHEADER
86+
87+
.. class:: BITMAPINFO
88+
89+
.. attribute:: MONITORNUMPROC
90+
91+
.. versionadded:: 6.1.0
92+
93+
.. class:: MSS
94+
95+
.. attribute:: gdi32
96+
97+
.. attribute:: user32
98+
7499
Methods
75100
=======
76101

77102
.. module:: mss.base
78103

104+
.. attribute:: lock
105+
106+
.. versionadded:: 6.0.0
107+
79108
.. class:: MSSBase
80109

81110
The parent's class for every OS implementation.
82111

112+
.. attribute:: cls_image
113+
83114
.. attribute:: compression_level
84115

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

87118
.. versionadded:: 3.2.0
88119

120+
.. attribute:: with_cursor
121+
122+
Include the mouse cursor in screenshots.
123+
124+
.. versionadded:: 8.0.0
125+
126+
.. method:: __init__(compression_level=6, display=None, max_displays=32, with_cursor=False)
127+
128+
:type compression_level: int
129+
:param compression_level: PNG compression level.
130+
:type display: bytes, str or None
131+
:param display: The display to use. Only effective on GNU/Linux.
132+
:type max_displays: int
133+
:param max_displays: Maximum number of displays. Only effective on macOS.
134+
:type with_cursor: bool
135+
:param with_cursor: Include the mouse cursor in screenshots.
136+
137+
.. versionadded:: 8.0.0
138+
``compression_level``, ``display``, ``max_displays``, and ``with_cursor``, keyword arguments.
139+
89140
.. method:: close()
90141

91-
Clean-up method. Does nothing by default.
142+
Clean-up method.
92143

93144
.. versionadded:: 4.0.0
94145

0 commit comments

Comments
 (0)