@@ -144,57 +144,96 @@ A screenshot to grab them all:
144144print (next (screenshotter.save(mon = - 1 , output = ' fullscreen.png' )))
145145```
146146
147-
148- API: version 2
149- ==============
147+ Example into the Python's console
148+ ---
150149
151150``` python
152- enum_display_monitors(force = False )
151+ >> > from mss import mss
152+ >> > sct = mss(display = b ' :0' )
153+
154+ # Retrieve monitors informations
155+ >> > displays = sct.enum_display_monitors()
156+ >> > displays
157+ [{' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }, {' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }]
158+ # You can access monitors list via `monitors`:
159+ >> > sct.monitors
160+ [{' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }, {' width' : 1920 , ' top' : 0 , ' height' : 1080 , ' left' : 0 }]
161+
162+ # Retrieve pixels from the first monitor
163+ >> > pixels = sct.get_pixels(displays[1 ])
164+ >> > pixels
165+ < ctypes.c_char_Array_6220800 object at 0x 7fe82e9007a0>
166+ # You can access pixels data via `image`:
167+ >> > sct.image
168+ < ctypes.c_char_Array_6220800 object at 0x 7fe82e9007a0>
169+
170+ # Save pixels to a PNG file: option 1
171+ >> > files = sct.save(mon = 1 )
172+ >> > next (files)
173+ ' monitor-1.png'
174+ >> > next (files)
175+ Traceback (most recent call last):
176+ File " <stdin>" , line 1 , in < module>
177+ StopIteration
178+
179+ # Save pixels to a PNG file: option 2
180+ >> > mon = displays[1 ]
181+ >> > sct.to_png(data = pixels, width = mon[b ' width' ], height = mon[b ' height' ], output = ' monitor-1.png' )
153182```
154183
155- Get positions and dimensions of monitors. If ` force ` is set to ` True ` , it will rescan for monitors informations.
184+ ---
156185
157- It stocks monitors informations into ` monitors ` and returns it.
186+ API
187+ ===
158188
159- ---
189+ ** enum_display_monitors ** => list of dicts
160190
161191``` python
162- get_pixels(monitor)
192+ >> > enum_display_monitors(force = False )
193+ ''' Get positions and dimensions of monitors.
194+ If `force` is set to `True`, it will rescan for monitors informations.
195+ It stocks monitors informations into `monitors` and returns it.
196+ `monitors[0]` is a dict of all monitors together
197+ `monitors[N]` is a dict of the monitor N (with N > 0)
198+ '''
163199```
164200
165- Retrieve screen pixels for a given monitor. ` monitor ` is a dict generated by ` enum_display_monitors() ` .
201+ ** get_pixels ** => array of ctypes.c_char
166202
167- It stocks pixels data into ` image ` (RGB) and returns it.
203+ ``` python
204+ >> > get_pixels(monitor)
205+ ''' Retrieve screen pixels for a given monitor.
206+ `monitor` is a dict generated by `enum_display_monitors()`.
207+ It stocks pixels data into `image` (RGB) and returns it.
208+ '''
209+ ```
168210
169- ---
211+ ** save ** => generator
170212
171213``` python
172- save(mon = 0 , output = ' monitor-%d ' , callback = lambda * x : True )
173- ```
214+ >> > save(mon = 0 , output = ' monitor-%d ' , callback = lambda * x : True )
215+ ''' Grab a screenshot and save it to a file.
174216
175- Grab a screenshot and save it to a file. Parameters:
217+ `mon` is an integer:
218+ -1: grab one screenshot of all monitors
219+ 0: grab one screenshot by monitor
220+ N: grab the screenshot of the monitor N
176221
177- ```
178- mon
179- -1: grab one screenshot of all monitors
180- 0: grab one screenshot by monitor
181- N: grab the screenshot of the monitor N
182-
183- output
184- The output filename.
185- %d, if presents, will be replaced by the monitor number.
186-
187- callback
188- Callback called before saving the screenshot to a file.
189- Take the 'output' argument as parameter.
190- ```
222+ `output` is a string:
223+ The output filename.
224+ %d, if presents, will be replaced by the monitor number.
191225
192- This is a generator which returns created files.
226+ `callback` is a method:
227+ Callback called before saving the screenshot to a file.
228+ Takes `output` argument as parameter.
193229
194- ---
230+ This is a generator which returns created files.
231+ '''
232+ ```
233+
234+ ** to_png**
195235
196236``` python
197- to_png(data, width, height, output)
237+ >> > to_png(data, width, height, output)
238+ ''' Dump raw `data` into PNG `output` file. '''
198239```
199-
200- Dump raw ` data ` into ` output ` file.
0 commit comments