@@ -6,259 +6,12 @@ It could be easily embedded into games and other softwares which require fast an
66
77**MSS ** stands for Multiple ScreenShots.
88
9- It's under MIT license.
9+ It's under MIT license and there is a ` beautiful documentation < http://python-mss.readthedocs.io/ >`_ :) .
1010
1111
1212Installation
13- ============
13+ ------------
1414
15- You can install it with pip:
15+ You can install it with pip::
1616
17- .. code :: shell
18-
19- $ pip install --upgrade mss
20-
21-
22- Support
23- =======
24-
25- Legend:
26-
27- * \: star: fully functional (latest stable version of Python)
28- * \: star2: fully functional (old version of Python)
29- * \: question: no machine to test (reports _ needed :smiley: )
30-
31- .. _reports : https://github.com/BoboTiG/python-mss/issues
32-
33- +----------+-----------+-------------+-----------+
34- | Python | GNU/Linux | MacOS X | Windows |
35- +==========+===========+=============+===========+
36- | **3.5 ** | \: star: | \: star: | \: star: |
37- +----------+-----------+-------------+-----------+
38- | 3.4 | \: star2: | \: star2: | \: star2: |
39- +----------+-----------+-------------+-----------+
40- | 3.3 | \: star2: | \: question: | \: star2: |
41- +----------+-----------+-------------+-----------+
42- | 3.2 | \: star2: | \: question: | \: star2: |
43- +----------+-----------+-------------+-----------+
44- | 3.1 | \: star2: | \: question: | \: star2: |
45- +----------+-----------+-------------+-----------+
46- | 3.0 | \: star2: | \: question: | \: star2: |
47- +----------+-----------+-------------+-----------+
48- | **2.7 ** | \: star: | \: star: | \: star: |
49- +----------+-----------+-------------+-----------+
50- | 2.6 | \: star2: | \: star2: | \: star2: |
51- +----------+-----------+-------------+-----------+
52-
53- Feel free to try MSS on a system we had not tested, and let report us by creating an issue _.
54-
55- .. _issue : htps://github.com/BoboTiG/python-mss/issues
56-
57-
58- Testing
59- -------
60-
61- You can try the MSS module directly from the console:
62-
63- .. code :: shell
64-
65- $ python tests.py
66-
67-
68- Instance the good class
69- =======================
70-
71- So MSS can be used as simply as:
72-
73- .. code :: python
74-
75- from mss import mss
76-
77-
78- # Then ...
79- with mss() as screenshotter:
80- # ...
81-
82-
83- Or import the good one (choose one):
84-
85- .. code :: python
86-
87- # MacOS X
88- from mss.darwin import MSS
89-
90- # GNU/Linux
91- from mss.linux import MSS
92-
93- # Microsoft Windows
94- from mss.windows import MSS
95-
96-
97- # Then ...
98- with MSS() as screenshotter:
99- # ...
100-
101-
102- Of course, you can use it the old way:
103-
104- .. code :: python
105-
106- from mss import mss
107- # or from mss.linux import MSS as mss
108-
109-
110- # Then ...
111- screenshotter = mss()
112- # ...
113-
114-
115- Errors
116- ======
117-
118- If an error occures, the `ScreenshotError ` exception is raised.
119-
120-
121- Examples
122- ========
123-
124- One screenshot per monitor:
125-
126- .. code :: python
127-
128- for filename in screenshotter.save():
129- print (filename)
130-
131-
132- Screenshot of the monitor 1:
133-
134- .. code :: python
135-
136- print (next (screenshotter.save(mon = 1 )))
137-
138-
139- Screenshot of the monitor 1, with callback:
140-
141- .. code :: python
142-
143- def on_exists (fname ):
144- ''' Callback example when we try to overwrite an existing
145- screenshot.
146- '''
147-
148- from os import rename
149- from os.path import isfile
150-
151- if isfile(fname):
152- newfile = fname + ' .old'
153- print (' {0} -> {1} ' .format(fname, newfile))
154- rename(fname, newfile)
155- return True
156-
157- print (next (screenshotter.save(mon = 1 , callback = on_exists)))
158-
159-
160- A screenshot to grab them all:
161-
162- .. code :: python
163-
164- print (next (screenshotter.save(mon = - 1 , output = ' fullscreen.png' )))
165-
166-
167- Example into the Python's console
168- ---
169-
170- .. code :: python
171-
172- >> > from mss import mss
173- >> > sct = mss(display = b ' :0' )
174-
175- # Retrieve monitors informations
176- >> > displays = sct.enum_display_monitors()
177- >> > displays
178- [{' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }, {' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }]
179- # You can access monitors list via `monitors`:
180- >> > sct.monitors
181- [{' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }, {' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }]
182-
183- # Retrieve pixels from the first monitor
184- >> > pixels = sct.get_pixels(displays[1 ])
185- >> > pixels
186- < ctypes.c_char_Array_6220800 object at 0x 7fe82e9007a0>
187- # You can access pixels data via `image`:
188- >> > sct.image
189- < ctypes.c_char_Array_6220800 object at 0x 7fe82e9007a0>
190-
191- # Save pixels to a PNG file: option 1
192- >> > files = sct.save(mon = 1 )
193- >> > next (files)
194- ' monitor-1.png'
195- >> > next (files)
196- Traceback (most recent call last):
197- File " <stdin>" , line 1 , in < module>
198- StopIteration
199-
200- # Save pixels to a PNG file: option 2
201- >> > mon = displays[1 ]
202- >> > sct.to_png(data = pixels, width = mon[b ' width' ], height = mon[b ' height' ], output = ' monitor-1.png' )
203-
204-
205- ----
206-
207- API
208- ===
209-
210- **enum_display_monitors ** => list of dicts
211-
212- .. code :: python
213-
214- >> > enum_display_monitors(force = False )
215- ''' Get positions and dimensions of monitors.
216- If `force` is set to `True`, it will rescan for monitors informations.
217- It stocks monitors informations into `monitors` and returns it.
218- `monitors[0]` is a dict of all monitors together
219- `monitors[N]` is a dict of the monitor N (with N > 0)
220- '''
221-
222-
223- **get_pixels ** => array of ctypes.c_char
224-
225- .. code :: python
226-
227- >> > get_pixels(monitor)
228- ''' Retrieve screen pixels for a given monitor.
229- `monitor` is a dict generated by `enum_display_monitors()`.
230- This method has to define `width` and `height`.
231- It stocks pixels data into `image` (RGB) and returns it.
232- '''
233-
234-
235- **save ** => generator
236-
237- .. code :: python
238-
239- >> > save(mon = 0 , output = ' monitor-%d ' , callback = lambda * x : True )
240- ''' Grab a screenshot and save it to a file.
241-
242- `mon` is an integer:
243- -1: grab one screenshot of all monitors
244- 0: grab one screenshot by monitor
245- N: grab the screenshot of the monitor N
246-
247- `output` is a string:
248- The output filename.
249- %d, if presents, will be replaced by the monitor number.
250-
251- `callback` is a method:
252- Callback called before saving the screenshot to a file.
253- Takes `output` argument as parameter.
254-
255- This is a generator which returns created files.
256- '''
257-
258-
259- **to_png **
260-
261- .. code :: python
262-
263- >> > to_png(data, width, height, output)
264- ''' Dump raw `data` into PNG `output` file. `data` is bytes(RGBRGB...RGB). '''
17+ pip install --upgrade mss
0 commit comments