Skip to content

Commit 843e903

Browse files
author
BoboTiG
committed
Add support table
1 parent 4f46f75 commit 843e903

File tree

4 files changed

+88
-55
lines changed

4 files changed

+88
-55
lines changed

README.rst

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,39 @@ A cross-platform multi-screen shot module in pure python using ctypes
44

55
Very basic, it will grab one screen shot by monitor or a screen shot of all monitors and save it to a PNG file, Python 2.6/3.5 compatible & PEP8 compliant.
66

7-
So, while you can `pip install --upgrade mss`, you may just drop it in your project and forget about it.
8-
9-
MSS stands for Multi-Screen Shot.
7+
MSS stands for Multiple ScreenShots.
108

119
It's under zlib licence.
1210

1311

12+
Installation
13+
============
14+
15+
You can install it with pip::
16+
17+
pip install --upgrade mss
18+
19+
Or you may just drop it in your project and forget about it.
20+
21+
Support
22+
-------
23+
24+
========= ========= ======== =======
25+
Python GNU/linux Mac OS X Windows
26+
========= ========= ======== =======
27+
3.5.0a3 True True True
28+
**3.4.3** **True** **True** **True**
29+
3.3.6 True True True
30+
3.2.6 True True True
31+
3.1.5 True True True
32+
3.0.1 True True True
33+
**2.7.9** **True** **True** **True**
34+
2.6.9 True True True
35+
========= ========= ======== =======
36+
37+
Feel free to try MSS on a system we had not tested, and let report us by creating an [issue](https://github.com/BoboTiG/python-mss/issues).
38+
39+
1440
Testing
1541
=======
1642

@@ -22,35 +48,29 @@ You can try the MSS module directly from the console::
2248
Instance the good class
2349
=======================
2450

25-
You can determine automatically which class to use::
26-
27-
from platform import system
28-
import mss
51+
So MSS can be used as simply as::
2952

30-
systems = {
31-
'Darwin': mss.MSSMac,
32-
'Linux': mss.MSSLinux,
33-
'Windows': mss.MSSWindows
34-
}
35-
mss_class = systems[system()]()
53+
from mss import mss
54+
screenshotter = mss()
3655

37-
Or simply import the good one::
56+
Or import the good one::
3857

39-
from mss import MSSLinux as mss_class
58+
from mss import MSSLinux as mss
59+
screenshotter = mss()
4060

4161

4262
save(output, screen, callback)
4363
------------------------------
4464

45-
For each monitor, grab a screen shot and save it to a file.
65+
For each monitor, grab a screenshot and save it to a file.
4666

4767
Parameters::
4868

4969
output - string - the output filename. It can contain '%d' which
5070
will be replaced by the monitor number.
51-
screen - integer - grab one screen shot of all monitors (screen=-1)
52-
grab one screen shot by monitor (screen=0)
53-
grab the screen shot of the monitor N (screen=N)
71+
screen - integer - grab one screenshot of all monitors (screen=-1)
72+
grab one screenshot by monitor (screen=0)
73+
grab the screenshot of the monitor N (screen=N)
5474
callback - function - in case where output already exists, call
5575
the defined callback function with output
5676
as parameter. If it returns True, then
@@ -63,21 +83,21 @@ This is a generator which returns created files.
6383
Examples
6484
========
6585

66-
One screen shot per monitor::
86+
One screenshot per monitor::
6787

68-
for filename in mss.save():
88+
for filename in screenshotter.save():
6989
print(filename)
7090

71-
Screen shot of the monitor 1::
91+
Screenshot of the monitor 1::
7292

73-
for filename in mss.save(screen=1):
93+
for filename in screenshotter.save(screen=1):
7494
print(filename)
7595

76-
Screen shot of the monitor 1, with callback::
96+
Screenshot of the monitor 1, with callback::
7797

7898
def on_exists(fname):
7999
''' Callback example when we try to overwrite an existing
80-
screen shot.
100+
screenshot.
81101
'''
82102
from os import rename
83103
from os.path import isfile
@@ -87,10 +107,10 @@ Screen shot of the monitor 1, with callback::
87107
rename(fname, newfile)
88108
return True
89109

90-
for filename in mss.save(screen=1, callback=on_exists):
110+
for filename in screenshotter.save(screen=1, callback=on_exists):
91111
print(filename)
92112

93-
A shot to grab them all (fullscreen shot)::
113+
A screenshot to grab them all::
94114

95-
for filename in mss.save(output='fullscreen-shot.png', screen=-1):
115+
for filename in screenshotter.save(output='fullscreen-shot.png', screen=-1):
96116
print(filename)

doc/TESTING

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The current MSS version was succesfully tested on these Python version.
1+
The current MSS version was successfully tested on these Python version.
22
You have another version to add or a patch to support a new one? Let us know, open a pull-request on GitHub :)
33

44
Python:
@@ -13,7 +13,7 @@ Python:
1313

1414

1515
---
16-
The current MSS version was succesfully tested on these OS.
16+
The current MSS version was successfully tested on these OS.
1717
You have another OS to add? Let us know, open a ticket on GitHub :)
1818

1919
GNU/Linux:
@@ -27,6 +27,8 @@ GNU/Linux:
2727
Mac OS X:
2828
OS X 10.7 (Lion)
2929
OS X 10.8 (Mountain Lion)
30+
OS X 10.9 (Mavericks)
31+
OS X 10.10 (Yosemite)
3032

3133
Microsoft Windows:
3234
Windows XP

mss.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
# coding: utf-8
3-
''' A cross-platform multi-screen shot module in pure python using ctypes.
3+
''' A cross-platform multiple screenshots module in pure python using ctypes.
44
55
This module is maintained by Mickaël Schoentgen <[email protected]>.
66
@@ -125,15 +125,18 @@ def debug(self, method='', scalar=None, value=None):
125125
print('{0}() {1} {2} {3}'.format(method, scalar,
126126
type(value).__name__, value))
127127

128-
def enum_display_monitors(self):
129-
''' Get positions of all monitors.
128+
def enum_display_monitors(self, screen=0):
129+
''' Get positions of one or more monitors.
130130
131-
If self.oneshot is True, this function has to return a dict
132-
with dimensions of all monitors at the same time.
133-
If the monitor has rotation, you have to deal with inside
134-
this method.
131+
If the monitor has rotation, you have to deal with it
132+
inside this method.
133+
134+
Parameters:
135+
- screen - int - grab one screenshot of all monitors (screen=-1)
136+
grab one screenshot by monitor (screen=0)
137+
grab the screenshot of the monitor N (screen=N)
135138
136-
Must returns a dict with:
139+
Returns a dict:
137140
{
138141
'left': the x-coordinate of the upper-left corner,
139142
'top': the y-coordinate of the upper-left corner,
@@ -143,33 +146,33 @@ def enum_display_monitors(self):
143146
'''
144147
raise NotImplementedError('MSS: subclasses need to implement this!')
145148

146-
def get_pixels(self, monitor_infos):
149+
def get_pixels(self, monitor):
147150
''' Retrieve screen pixels for a given monitor.
148151
149-
monitor_infos should contain at least:
152+
`monitor` is a dict with:
150153
{
151154
'left': the x-coordinate of the upper-left corner,
152155
'top': the y-coordinate of the upper-left corner,
153156
'width': the width,
154157
'heigth': the height
155158
}
156159
157-
Returns a dict with pixels.
160+
Returns a dict of pixels.
158161
'''
159162
raise NotImplementedError('MSS: subclasses need to implement this!')
160163

161164
def save(self,
162165
output='screenshot-%d.png',
163166
screen=0,
164167
callback=lambda *x: True):
165-
''' For each monitor, grab a screen shot and save it to a file.
168+
''' Grab a screenshot and save it to a file.
166169
167170
Parameters:
168171
- output - string - the output filename. It can contain '%d' which
169172
will be replaced by the monitor number.
170-
- screen - int - grab one screen shot of all monitors (screen=-1)
171-
grab one screen shot by monitor (screen=0)
172-
grab the screen shot of the monitor N (screen=N)
173+
- screen - int - grab one screenshot of all monitors (screen=-1)
174+
grab one screenshot by monitor (screen=0)
175+
grab the screenshot of the monitor N (screen=N)
173176
- callback - function - in case where output already exists, call
174177
the defined callback function with output
175178
as parameter. If it returns True, then
@@ -240,7 +243,7 @@ def save_img(self, data, width, height, output):
240243

241244

242245
class MSSMac(MSS):
243-
''' Mutli-screen shot implementation for Mac OSX.
246+
''' Mutliple ScreenShots implementation for Mac OS X.
244247
It uses intensively the Quartz.
245248
'''
246249

@@ -323,7 +326,7 @@ def save_img(self, data, width, height, output):
323326

324327

325328
class MSSLinux(MSS):
326-
''' Mutli-screen shot implementation for GNU/Linux.
329+
''' Mutliple ScreenShots implementation for GNU/Linux.
327330
It uses intensively the Xlib and Xrandr.
328331
'''
329332

@@ -487,33 +490,41 @@ def get_pixels(self, monitor):
487490
if not ximage:
488491
raise ScreenshotError('MSS: XGetImage() failed.')
489492

493+
from ctypes import c_ubyte, c_char
494+
bpl = ximage.contents.bytes_per_line
495+
data = cast(ximage.contents.data, POINTER(width * height * c_ubyte)).contents
496+
490497
# @TODO: this part takes most of the time. Need a better solution.
491498
def pix(pixel, _resultats={}, b=pack):
492499
''' Apply shifts to a pixel to get the RGB values.
493500
This method uses of memoization.
494501
'''
495502
if pixel not in _resultats:
496-
_resultats[pixel] = b(b'<B', (pixel & rmask) >> 16) + \
497-
b(b'<B', (pixel & gmask) >> 8) + b(b'<B', pixel & bmask)
503+
_resultats[pixel] = b(b'<B', pixel >> 24) + \
504+
b(b'<B', pixel>> 16) + b(b'<B', pixel)
498505
return _resultats[pixel]
499506

500507
# http://cgit.freedesktop.org/xorg/lib/libX11/tree/src/ImUtil.c#n444
501-
get_pix = self.xlib.XGetPixel
508+
#~ get_pix = self.xlib.XGetPixel
509+
#~ def get_pix(x, y):
510+
502511
rmask = ximage.contents.red_mask
503512
gmask = ximage.contents.green_mask
504513
bmask = ximage.contents.blue_mask
514+
bpl = ximage.contents.bytes_per_line
505515
self.debug('get_pixels', 'rmask', rmask)
506516
self.debug('get_pixels', 'gmask', gmask)
507517
self.debug('get_pixels', 'bmask', bmask)
508-
pixels = [pix(get_pix(ximage, x, y))
509-
for y in range(height) for x in range(width)]
518+
xrange = getattr(__builtins__, 'xrange', range)
519+
pixels = [pix(data[idx])
520+
for idx in xrange(0, (width * height) - 2, 3)]
510521
self.xlib.XDestroyImage(ximage)
511522
self.image = b''.join(pixels)
512523
return self.image
513524

514525

515526
class MSSWindows(MSS):
516-
''' Mutli-screen shot implementation for Microsoft Windows. '''
527+
''' Mutliple ScreenShots implementation for Microsoft Windows. '''
517528

518529
def __init__(self):
519530
''' Windows initialisations. '''
@@ -671,7 +682,7 @@ def main():
671682

672683
def on_exists(fname):
673684
''' Callback example when we try to overwrite an existing
674-
screen shot.
685+
screenshot.
675686
'''
676687
from os import rename
677688
from os.path import isfile

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
author='Tiger-222',
1818
py_modules=['mss'],
1919
author_email='[email protected]',
20-
description='A cross-platform multi-screen shot module in pure python using ctypes',
20+
description='A cross-platform multiple screenshots module in pure python using ctypes',
2121
long_description=open('README.rst').read(),
2222
classifiers=[
2323
'Development Status :: 5 - Production/Stable',

0 commit comments

Comments
 (0)