Skip to content

Commit e98012e

Browse files
author
Mickaël Schoentgen
committed
PEP8, cleanup
1 parent 17728c4 commit e98012e

24 files changed

+166
-149
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ build/
22
.cache/
33
dist/
44
*.egg-info/
5+
.idea/
56
MANIFEST*
67
.DS_Store
78
*.orig

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ python:
55
- 3.4
66
- 3.5
77
- 3.6
8-
- nightly # currently points to 3.7-dev
8+
# - nightly # currently points to 3.7-dev
99

1010
addons:
1111
apt:

CHANGELOG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ History:
22

33
<see Git checkin messages for history>
44

5-
dev
5+
2.0.22 2017/04/29
6+
- new contributors: David Becker, redodo
67
- add an example to capture only a part of the screen
78
- better use of exception mechanism
89
- Linux: use of hasattr to prevent Exception on early exit
10+
- Mac: take into account extra black pixels added when screen with is not divisible by 16 (fix #14)
911

1012
2.0.18 2016/12/03
1113
- change license to MIT

CONTRIBUTORS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ bubulle [http://indexerror.net/user/bubulle]
1515
Condé 'Eownis' Titouan <[email protected]> <[email protected]> [https://titouan.co]
1616
- MacOS X tester
1717

18+
David Becker [https://davide.me] and redodo [https://github.com/redodo]
19+
- Mac: Take into account extra black pixels added when screen with is not divisible by 16
20+
1821
Jochen 'cycomanic' Schroeder [https://github.com/cycomanic]
1922
- GNU/Linux: use errcheck instead of deprecated restype with callable, for enum_display_monitors()
2023

examples/callback.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/usr/bin/env python
21
# coding: utf-8
3-
''' This is part of the MSS Python's module.
2+
""" This is part of the MSS Python's module.
43
Source: https://github.com/BoboTiG/python-mss
5-
'''
4+
"""
65

76
from os import rename
87
from os.path import isfile
@@ -13,13 +12,13 @@
1312

1413
def main():
1514
# type: () -> int
16-
''' Usage example. '''
15+
""" Usage example. """
1716

1817
def on_exists(fname):
1918
# type: (str) -> None
20-
''' Callback example when we try to overwrite an existing
19+
""" Callback example when we try to overwrite an existing
2120
screenshot.
22-
'''
21+
"""
2322

2423
if isfile(fname):
2524
newfile = fname + '.old'

examples/linux-display_keyword.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
#!/usr/bin/env python
21
# coding: utf-8
3-
''' This is part of the MSS Python's module.
2+
""" This is part of the MSS Python's module.
43
Source: https://github.com/BoboTiG/python-mss
5-
'''
4+
"""
65

76
from mss.exception import ScreenshotError
87
from mss.linux import MSS
98

109

1110
def main():
1211
# type: () -> int
13-
''' Usage example with a specific display. '''
12+
""" Usage example with a specific display. """
1413

1514
display = ':0.0'
1615
print('Screenshot of display "{0}"'.format(display))

examples/part-of-screen.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
#!/usr/bin/env python
21
# coding: utf-8
3-
''' This is part of the MSS Python's module.
2+
""" This is part of the MSS Python's module.
43
Source: https://github.com/BoboTiG/python-mss
5-
'''
4+
"""
65

76
from mss.exception import ScreenshotError
87
from mss import mss
98

109

1110
def main():
1211
# type: () -> int
13-
''' Example to capture part of the screen. '''
12+
""" Example to capture part of the screen. """
1413

1514
try:
1615
with mss() as sct:

examples/pil.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/usr/bin/env python
21
# coding: utf-8
3-
''' This is part of the MSS Python's module.
2+
""" This is part of the MSS Python's module.
43
Source: https://github.com/BoboTiG/python-mss
5-
'''
4+
"""
65

76
from mss.exception import ScreenshotError
87
from mss.factory import mss
@@ -11,7 +10,7 @@
1110

1211
def main():
1312
# type: () -> int
14-
''' PIL example using frombytes(). '''
13+
""" PIL example using frombytes(). """
1514

1615
try:
1716
with mss() as sct:

mss/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
#!/usr/bin/env python
21
# coding: utf-8
3-
''' An ultra fast cross-platform multiple screenshots module in pure python
2+
""" An ultra fast cross-platform multiple screenshots module in pure python
43
using ctypes.
54
65
This module is maintained by Mickaël Schoentgen <[email protected]>.
76
87
You can always get the latest version of this module at:
98
https://github.com/BoboTiG/python-mss
109
If that URL should fail, try contacting the author.
11-
'''
10+
"""
1211

1312
from .exception import ScreenshotError
1413
from .factory import mss
1514

16-
__version__ = '2.0.21'
15+
__version__ = '2.0.22'
1716
__author__ = "Mickaël 'Tiger-222' Schoentgen"
18-
__copyright__ = '''
17+
__copyright__ = """
1918
Copyright (c) 2013-2017, Mickaël 'Tiger-222' Schoentgen
2019
2120
Permission to use, copy, modify, and distribute this software and its
@@ -24,5 +23,5 @@
2423
and that both that copyright notice and this permission notice appear
2524
in supporting documentation or portions thereof, including
2625
modifications, that you make.
27-
'''
26+
"""
2827
__all__ = ['ScreenshotError', 'mss']

mss/__main__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding: utf-8
2+
""" This is part of the MSS Python's module.
3+
Source: https://github.com/BoboTiG/python-mss
4+
"""
5+
6+
from __future__ import print_function
7+
8+
from .factory import mss
9+
10+
11+
def main():
12+
""" Main logic. """
13+
14+
with mss() as sct:
15+
for file_name in sct.save():
16+
print(file_name)
17+
18+
19+
if __name__ == '__main__':
20+
exit(main())

mss/base.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/usr/bin/env python
21
# coding: utf-8
3-
''' This is part of the MSS Python's module.
2+
""" This is part of the MSS Python's module.
43
Source: https://github.com/BoboTiG/python-mss
5-
'''
4+
"""
65

76
from struct import pack
87
from zlib import compress, crc32
@@ -12,30 +11,30 @@
1211

1312
# C'est parti mon kiki !
1413
class MSSBase(object):
15-
''' This class will be overloaded by a system specific one. '''
14+
""" This class will be overloaded by a system specific one. """
1615

1716
monitors = []
1817
image = None
1918
width = 0
2019
height = 0
2120

2221
def __enter__(self):
23-
''' For the cool call `with MSS() as mss:`. '''
22+
""" For the cool call `with MSS() as mss:`. """
2423

2524
return self
2625

2726
def __exit__(self, *_):
28-
''' For the cool call `with MSS() as mss:`. '''
27+
""" For the cool call `with MSS() as mss:`. """
2928

3029
def bgra_to_rgb(self, raw):
31-
''' Converts pixels values from BGRA to RGB. '''
30+
""" Converts pixels values from BGRA to RGB. """
3231

3332
image = bytearray(self.height * self.width * 3)
3433
image[0::3], image[1::3], image[2::3] = raw[2::4], raw[1::4], raw[0::4]
3534
return bytes(image)
3635

3736
def enum_display_monitors(self, force=False):
38-
''' Get positions of one or more monitors.
37+
""" Get positions of one or more monitors.
3938
If the monitor has rotation, you have to deal with it
4039
inside this method.
4140
@@ -51,12 +50,12 @@ def enum_display_monitors(self, force=False):
5150
'width': the width,
5251
'height': the height
5352
}
54-
'''
53+
"""
5554

5655
raise NotImplementedError('Subclasses need to implement this!')
5756

5857
def get_pixels(self, monitor):
59-
''' Retrieve screen pixels for a given monitor.
58+
""" Retrieve screen pixels for a given monitor.
6059
6160
This method has to define self.width and self.height.
6261
@@ -67,12 +66,12 @@ def get_pixels(self, monitor):
6766
'width': the width,
6867
'heigth': the height
6968
}
70-
'''
69+
"""
7170

7271
raise NotImplementedError('Subclasses need to implement this!')
7372

7473
def save(self, mon=0, output='monitor-%d.png', callback=None):
75-
''' Grab a screenshot and save it to a file.
74+
""" Grab a screenshot and save it to a file.
7675
7776
mon (integer, default: 0)
7877
-1: grab one screenshot of all monitors
@@ -88,7 +87,7 @@ def save(self, mon=0, output='monitor-%d.png', callback=None):
8887
Take the 'output' argument as parameter.
8988
9089
This is a generator which returns created files.
91-
'''
90+
"""
9291

9392
self.enum_display_monitors()
9493
if not self.monitors:
@@ -121,10 +120,10 @@ def save(self, mon=0, output='monitor-%d.png', callback=None):
121120
yield output
122121

123122
def to_png(self, data, output):
124-
''' Dump data to the image file. Data is bytes(RGBRGB...RGB).
123+
""" Dump data to the image file. Data is bytes(RGBRGB...RGB).
125124
Pure python PNG implementation.
126125
http://inaps.org/journal/comment-fonctionne-le-png
127-
'''
126+
"""
128127

129128
p__ = pack
130129
line = self.width * 3

0 commit comments

Comments
 (0)