@@ -113,18 +113,6 @@ class BITMAPINFO(Structure):
113
113
class MSS (object ):
114
114
''' This class will be overloaded by a system specific one. '''
115
115
116
- DEBUG = False
117
-
118
- def debug (self , method = '' , scalar = None , value = None ):
119
- ''' Simple debug output. '''
120
-
121
- if self .DEBUG :
122
- if scalar is None :
123
- print (':: {0}()' .format (method ))
124
- else :
125
- print ('{0}() {1} {2} {3}' .format (method , scalar ,
126
- type (value ).__name__ , value ))
127
-
128
116
def enum_display_monitors (self , screen = 0 ):
129
117
''' Get positions of one or more monitors.
130
118
@@ -182,18 +170,12 @@ def save(self,
182
170
This is a generator which returns created files.
183
171
'''
184
172
185
- self .debug ('save' )
186
- self .debug ('save' , 'screen' , screen )
187
- self .debug ('save' , 'output' , output )
188
-
189
173
# Monitors screen shots!
190
174
for i , monitor in enumerate (self .enum_display_monitors (screen )):
191
- self .debug ('save' , 'monitor' , monitor )
192
175
if screen <= 0 or (screen > 0 and i + 1 == screen ):
193
176
fname = output
194
177
if '%d' in output :
195
178
fname = output .replace ('%d' , str (i + 1 ))
196
- self .debug ('save' , 'fname' , fname )
197
179
callback (fname )
198
180
self .save_img (data = self .get_pixels (monitor ),
199
181
width = monitor [b'width' ],
@@ -252,11 +234,8 @@ def enum_display_monitors(self, screen=0):
252
234
Returns a dict with minimal requirements (see MSS class).
253
235
'''
254
236
255
- self .debug ('enum_display_monitors' )
256
-
257
237
if screen == - 1 :
258
238
rect = CGRectInfinite
259
- self .debug ('enum_display_monitors' , 'rect' , rect )
260
239
yield ({
261
240
b'left' : int (rect .origin .x ),
262
241
b'top' : int (rect .origin .y ),
@@ -267,14 +246,11 @@ def enum_display_monitors(self, screen=0):
267
246
max_displays = 32 # Could be augmented, if needed ...
268
247
rotations = {0.0 : 'normal' , 90.0 : 'right' , - 90.0 : 'left' }
269
248
_ , ids , _ = CGGetActiveDisplayList (max_displays , None , None )
270
- self .debug ('enum_display_monitors' , 'ids' , ids )
271
249
for display in ids :
272
250
rect = CGRectStandardize (CGDisplayBounds (display ))
273
- self .debug ('enum_display_monitors' , 'rect' , rect )
274
251
left , top = rect .origin .x , rect .origin .y
275
252
width , height = rect .size .width , rect .size .height
276
253
rot = CGDisplayRotation (display )
277
- self .debug ('enum_display_monitors' , 'rot' , rot )
278
254
if rotations [rot ] in ['left' , 'right' ]:
279
255
width , height = height , width
280
256
yield ({
@@ -288,34 +264,22 @@ def get_pixels(self, monitor):
288
264
''' Retrieve all pixels from a monitor. Pixels have to be RGB.
289
265
'''
290
266
291
- self .debug ('get_pixels' )
292
-
293
267
width , height = monitor [b'width' ], monitor [b'height' ]
294
268
left , top = monitor [b'left' ], monitor [b'top' ]
295
269
rect = CGRect ((left , top ), (width , height ))
296
270
options = kCGWindowListOptionOnScreenOnly
297
271
winid = kCGNullWindowID
298
272
default = kCGWindowImageDefault
299
273
self .image = CGWindowListCreateImage (rect , options , winid , default )
300
-
301
- self .debug ('get_pixels' , 'rect' , rect )
302
- self .debug ('get_pixels' , 'options' , options )
303
- self .debug ('get_pixels' , 'winid' , winid )
304
- self .debug ('get_pixels' , 'default' , default )
305
-
306
274
if not self .image :
307
275
raise ScreenshotError ('MSS: CGWindowListCreateImage() failed.' )
308
276
return self .image
309
277
310
278
def save_img (self , data , width , height , output ):
311
279
''' Use my own save_img() method. Because I'm a Mac! '''
312
280
313
- self .debug ('save_img' )
314
-
315
281
url = NSURL .fileURLWithPath_ (output )
316
282
dest = CGImageDestinationCreateWithURL (url , kUTTypePNG , 1 , None )
317
- self .debug ('save_img' , 'url' , url )
318
- self .debug ('save_img' , 'dest' , dest )
319
283
if not dest :
320
284
err = 'MSS: CGImageDestinationCreateWithURL() failed.'
321
285
raise ScreenshotError (err )
@@ -333,8 +297,6 @@ class MSSLinux(MSS):
333
297
def __del__ (self ):
334
298
''' Disconnect from X server. '''
335
299
336
- self .debug ('__del__' )
337
-
338
300
try :
339
301
if self .display :
340
302
self .xlib .XCloseDisplay (self .display )
@@ -344,19 +306,15 @@ def __del__(self):
344
306
def __init__ (self ):
345
307
''' GNU/Linux initialisations '''
346
308
347
- self .debug ('__init__' )
348
-
349
309
x11 = find_library ('X11' )
350
310
if not x11 :
351
311
raise ScreenshotError ('MSS: no X11 library found.' )
352
312
self .xlib = cdll .LoadLibrary (x11 )
353
- self .debug ('__init__' , 'self.xlib' , self .xlib )
354
313
355
314
xrandr = find_library ('Xrandr' )
356
315
if not xrandr :
357
316
raise ScreenshotError ('MSS: no Xrandr library found.' )
358
317
self .xrandr = cdll .LoadLibrary (xrandr )
359
- self .debug ('__init__' , 'self.xrandr' , self .xrandr )
360
318
361
319
self ._set_argtypes ()
362
320
self ._set_restypes ()
@@ -371,22 +329,16 @@ def __init__(self):
371
329
except KeyError :
372
330
err = 'MSS: $DISPLAY not set. Stopping to prevent segfault.'
373
331
raise ScreenshotError (err )
374
- self .debug ('__init__' , '$DISPLAY' , disp )
375
332
376
333
# At this point, if there is no running server, it could end on
377
334
# a segmentation fault. And we cannot catch it.
378
335
self .display = self .xlib .XOpenDisplay (disp )
379
- self .debug ('__init__' , 'self.display' , self .display )
380
336
self .screen = self .xlib .XDefaultScreen (self .display )
381
- self .debug ('__init__' , 'self.screen' , self .screen )
382
337
self .root = self .xlib .XDefaultRootWindow (self .display , self .screen )
383
- self .debug ('__init__' , 'self.root' , self .root )
384
338
385
339
def _set_argtypes (self ):
386
340
''' Functions arguments. '''
387
341
388
- self .debug ('_set_argtypes' )
389
-
390
342
self .xlib .XOpenDisplay .argtypes = [c_char_p ]
391
343
self .xlib .XDefaultScreen .argtypes = [POINTER (Display )]
392
344
self .xlib .XDefaultRootWindow .argtypes = [POINTER (Display ), c_int ]
@@ -413,8 +365,6 @@ def _set_argtypes(self):
413
365
def _set_restypes (self ):
414
366
''' Functions return type. '''
415
367
416
- self .debug ('_set_restypes' )
417
-
418
368
self .xlib .XOpenDisplay .restype = POINTER (Display )
419
369
self .xlib .XDefaultScreen .restype = c_int
420
370
self .xlib .XGetWindowAttributes .restype = c_int
@@ -434,12 +384,9 @@ def enum_display_monitors(self, screen=0):
434
384
Returns a dict with minimal requirements (see MSS class).
435
385
'''
436
386
437
- self .debug ('enum_display_monitors' )
438
-
439
387
if screen == - 1 :
440
388
gwa = XWindowAttributes ()
441
389
self .xlib .XGetWindowAttributes (self .display , self .root , byref (gwa ))
442
- self .debug ('enum_display_monitors' , 'gwa' , gwa )
443
390
yield ({
444
391
b'left' : int (gwa .x ),
445
392
b'top' : int (gwa .y ),
@@ -451,42 +398,32 @@ def enum_display_monitors(self, screen=0):
451
398
# expected LP_Display instance instead of LP_XWindowAttributes
452
399
root = cast (self .root , POINTER (Display ))
453
400
mon = self .xrandr .XRRGetScreenResources (self .display , root )
454
- self .debug ('enum_display_monitors' , 'root' , root )
455
- self .debug ('enum_display_monitors' , 'mon' , mon )
456
- self .debug ('enum_display_monitors' , 'number of monitors' ,
457
- mon .contents .ncrtc )
458
401
for num in range (mon .contents .ncrtc ):
459
- crtc_info = self .xrandr .XRRGetCrtcInfo (self .display , mon ,
460
- mon .contents .crtcs [num ])
402
+ crtc = self .xrandr .XRRGetCrtcInfo (self .display , mon ,
403
+ mon .contents .crtcs [num ])
461
404
yield ({
462
- b'left' : int (crtc_info .contents .x ),
463
- b'top' : int (crtc_info .contents .y ),
464
- b'width' : int (crtc_info .contents .width ),
465
- b'height' : int (crtc_info .contents .height )
405
+ b'left' : int (crtc .contents .x ),
406
+ b'top' : int (crtc .contents .y ),
407
+ b'width' : int (crtc .contents .width ),
408
+ b'height' : int (crtc .contents .height )
466
409
})
467
- self .xrandr .XRRFreeCrtcInfo (crtc_info )
410
+ self .xrandr .XRRFreeCrtcInfo (crtc )
468
411
self .xrandr .XRRFreeScreenResources (mon )
469
412
470
413
def get_pixels (self , monitor ):
471
414
''' Retrieve all pixels from a monitor. Pixels have to be RGB. '''
472
415
473
- self .debug ('get_pixels' )
474
-
475
416
width , height = monitor [b'width' ], monitor [b'height' ]
476
417
left , top = monitor [b'left' ], monitor [b'top' ]
477
418
ZPixmap = 2
478
-
479
419
allplanes = self .xlib .XAllPlanes ()
480
- self .debug ('get_pixels' , 'allplanes' , allplanes )
481
420
482
421
# Fix for XGetImage:
483
422
# expected LP_Display instance instead of LP_XWindowAttributes
484
423
root = cast (self .root , POINTER (Display ))
485
- self .debug ('get_pixels' , 'root' , root )
486
424
487
425
ximage = self .xlib .XGetImage (self .display , root , left , top , width ,
488
426
height , allplanes , ZPixmap )
489
- self .debug ('get_pixels' , 'ximage' , ximage )
490
427
if not ximage :
491
428
raise ScreenshotError ('MSS: XGetImage() failed.' )
492
429
@@ -512,9 +449,6 @@ def pix(pixel, _resultats={}, b=pack):
512
449
gmask = ximage .contents .green_mask
513
450
bmask = ximage .contents .blue_mask
514
451
bpl = ximage .contents .bytes_per_line
515
- self .debug ('get_pixels' , 'rmask' , rmask )
516
- self .debug ('get_pixels' , 'gmask' , gmask )
517
- self .debug ('get_pixels' , 'bmask' , bmask )
518
452
xrange = getattr (__builtins__ , 'xrange' , range )
519
453
pixels = [pix (data [idx ])
520
454
for idx in xrange (0 , (width * height ) - 2 , 3 )]
@@ -529,16 +463,12 @@ class MSSWindows(MSS):
529
463
def __init__ (self ):
530
464
''' Windows initialisations. '''
531
465
532
- self .debug ('__init__' )
533
-
534
466
self ._set_argtypes ()
535
467
self ._set_restypes ()
536
468
537
469
def _set_argtypes (self ):
538
470
''' Functions arguments. '''
539
471
540
- self .debug ('_set_argtypes' )
541
-
542
472
self .MONITORENUMPROC = WINFUNCTYPE (INT , DWORD , DWORD , POINTER (RECT ),
543
473
DOUBLE )
544
474
windll .user32 .GetSystemMetrics .argtypes = [INT ]
@@ -558,8 +488,6 @@ def _set_argtypes(self):
558
488
def _set_restypes (self ):
559
489
''' Functions return type. '''
560
490
561
- self .debug ('_set_restypes' )
562
-
563
491
windll .user32 .GetSystemMetrics .restypes = INT
564
492
windll .user32 .EnumDisplayMonitors .restypes = BOOL
565
493
windll .user32 .GetWindowDC .restypes = HDC
@@ -575,8 +503,6 @@ def enum_display_monitors(self, screen=-1):
575
503
Returns a dict with minimal requirements (see MSS class).
576
504
'''
577
505
578
- self .debug ('enum_display_monitors' )
579
-
580
506
if screen == - 1 :
581
507
SM_XVIRTUALSCREEN , SM_YVIRTUALSCREEN = 76 , 77
582
508
SM_CXVIRTUALSCREEN , SM_CYVIRTUALSCREEN = 78 , 79
@@ -621,8 +547,6 @@ def get_pixels(self, monitor):
621
547
https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
622
548
'''
623
549
624
- self .debug ('get_pixels' )
625
-
626
550
width , height = monitor [b'width' ], monitor [b'height' ]
627
551
left , top = monitor [b'left' ], monitor [b'top' ]
628
552
SRCCOPY = 0xCC0020
@@ -647,14 +571,6 @@ def get_pixels(self, monitor):
647
571
SRCCOPY )
648
572
bits = windll .gdi32 .GetDIBits (memdc , bmp , 0 , height , self .image ,
649
573
bmi , DIB_RGB_COLORS )
650
-
651
- self .debug ('get_pixels' , 'srcdc' , srcdc )
652
- self .debug ('get_pixels' , 'memdc' , memdc )
653
- self .debug ('get_pixels' , 'bmp' , bmp )
654
- self .debug ('get_pixels' , 'buffer_len' , buffer_len )
655
- self .debug ('get_pixels' , 'len(self.image)' , len (self .image ))
656
- self .debug ('get_pixels' , 'bits' , bits )
657
-
658
574
if bits != height :
659
575
raise ScreenshotError ('MSS: GetDIBits() failed.' )
660
576
finally :
0 commit comments