@@ -113,18 +113,6 @@ class BITMAPINFO(Structure):
113113class MSS (object ):
114114 ''' This class will be overloaded by a system specific one. '''
115115
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-
128116 def enum_display_monitors (self , screen = 0 ):
129117 ''' Get positions of one or more monitors.
130118
@@ -182,18 +170,12 @@ def save(self,
182170 This is a generator which returns created files.
183171 '''
184172
185- self .debug ('save' )
186- self .debug ('save' , 'screen' , screen )
187- self .debug ('save' , 'output' , output )
188-
189173 # Monitors screen shots!
190174 for i , monitor in enumerate (self .enum_display_monitors (screen )):
191- self .debug ('save' , 'monitor' , monitor )
192175 if screen <= 0 or (screen > 0 and i + 1 == screen ):
193176 fname = output
194177 if '%d' in output :
195178 fname = output .replace ('%d' , str (i + 1 ))
196- self .debug ('save' , 'fname' , fname )
197179 callback (fname )
198180 self .save_img (data = self .get_pixels (monitor ),
199181 width = monitor [b'width' ],
@@ -252,11 +234,8 @@ def enum_display_monitors(self, screen=0):
252234 Returns a dict with minimal requirements (see MSS class).
253235 '''
254236
255- self .debug ('enum_display_monitors' )
256-
257237 if screen == - 1 :
258238 rect = CGRectInfinite
259- self .debug ('enum_display_monitors' , 'rect' , rect )
260239 yield ({
261240 b'left' : int (rect .origin .x ),
262241 b'top' : int (rect .origin .y ),
@@ -267,14 +246,11 @@ def enum_display_monitors(self, screen=0):
267246 max_displays = 32 # Could be augmented, if needed ...
268247 rotations = {0.0 : 'normal' , 90.0 : 'right' , - 90.0 : 'left' }
269248 _ , ids , _ = CGGetActiveDisplayList (max_displays , None , None )
270- self .debug ('enum_display_monitors' , 'ids' , ids )
271249 for display in ids :
272250 rect = CGRectStandardize (CGDisplayBounds (display ))
273- self .debug ('enum_display_monitors' , 'rect' , rect )
274251 left , top = rect .origin .x , rect .origin .y
275252 width , height = rect .size .width , rect .size .height
276253 rot = CGDisplayRotation (display )
277- self .debug ('enum_display_monitors' , 'rot' , rot )
278254 if rotations [rot ] in ['left' , 'right' ]:
279255 width , height = height , width
280256 yield ({
@@ -288,34 +264,22 @@ def get_pixels(self, monitor):
288264 ''' Retrieve all pixels from a monitor. Pixels have to be RGB.
289265 '''
290266
291- self .debug ('get_pixels' )
292-
293267 width , height = monitor [b'width' ], monitor [b'height' ]
294268 left , top = monitor [b'left' ], monitor [b'top' ]
295269 rect = CGRect ((left , top ), (width , height ))
296270 options = kCGWindowListOptionOnScreenOnly
297271 winid = kCGNullWindowID
298272 default = kCGWindowImageDefault
299273 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-
306274 if not self .image :
307275 raise ScreenshotError ('MSS: CGWindowListCreateImage() failed.' )
308276 return self .image
309277
310278 def save_img (self , data , width , height , output ):
311279 ''' Use my own save_img() method. Because I'm a Mac! '''
312280
313- self .debug ('save_img' )
314-
315281 url = NSURL .fileURLWithPath_ (output )
316282 dest = CGImageDestinationCreateWithURL (url , kUTTypePNG , 1 , None )
317- self .debug ('save_img' , 'url' , url )
318- self .debug ('save_img' , 'dest' , dest )
319283 if not dest :
320284 err = 'MSS: CGImageDestinationCreateWithURL() failed.'
321285 raise ScreenshotError (err )
@@ -333,8 +297,6 @@ class MSSLinux(MSS):
333297 def __del__ (self ):
334298 ''' Disconnect from X server. '''
335299
336- self .debug ('__del__' )
337-
338300 try :
339301 if self .display :
340302 self .xlib .XCloseDisplay (self .display )
@@ -344,19 +306,15 @@ def __del__(self):
344306 def __init__ (self ):
345307 ''' GNU/Linux initialisations '''
346308
347- self .debug ('__init__' )
348-
349309 x11 = find_library ('X11' )
350310 if not x11 :
351311 raise ScreenshotError ('MSS: no X11 library found.' )
352312 self .xlib = cdll .LoadLibrary (x11 )
353- self .debug ('__init__' , 'self.xlib' , self .xlib )
354313
355314 xrandr = find_library ('Xrandr' )
356315 if not xrandr :
357316 raise ScreenshotError ('MSS: no Xrandr library found.' )
358317 self .xrandr = cdll .LoadLibrary (xrandr )
359- self .debug ('__init__' , 'self.xrandr' , self .xrandr )
360318
361319 self ._set_argtypes ()
362320 self ._set_restypes ()
@@ -371,22 +329,16 @@ def __init__(self):
371329 except KeyError :
372330 err = 'MSS: $DISPLAY not set. Stopping to prevent segfault.'
373331 raise ScreenshotError (err )
374- self .debug ('__init__' , '$DISPLAY' , disp )
375332
376333 # At this point, if there is no running server, it could end on
377334 # a segmentation fault. And we cannot catch it.
378335 self .display = self .xlib .XOpenDisplay (disp )
379- self .debug ('__init__' , 'self.display' , self .display )
380336 self .screen = self .xlib .XDefaultScreen (self .display )
381- self .debug ('__init__' , 'self.screen' , self .screen )
382337 self .root = self .xlib .XDefaultRootWindow (self .display , self .screen )
383- self .debug ('__init__' , 'self.root' , self .root )
384338
385339 def _set_argtypes (self ):
386340 ''' Functions arguments. '''
387341
388- self .debug ('_set_argtypes' )
389-
390342 self .xlib .XOpenDisplay .argtypes = [c_char_p ]
391343 self .xlib .XDefaultScreen .argtypes = [POINTER (Display )]
392344 self .xlib .XDefaultRootWindow .argtypes = [POINTER (Display ), c_int ]
@@ -413,8 +365,6 @@ def _set_argtypes(self):
413365 def _set_restypes (self ):
414366 ''' Functions return type. '''
415367
416- self .debug ('_set_restypes' )
417-
418368 self .xlib .XOpenDisplay .restype = POINTER (Display )
419369 self .xlib .XDefaultScreen .restype = c_int
420370 self .xlib .XGetWindowAttributes .restype = c_int
@@ -434,12 +384,9 @@ def enum_display_monitors(self, screen=0):
434384 Returns a dict with minimal requirements (see MSS class).
435385 '''
436386
437- self .debug ('enum_display_monitors' )
438-
439387 if screen == - 1 :
440388 gwa = XWindowAttributes ()
441389 self .xlib .XGetWindowAttributes (self .display , self .root , byref (gwa ))
442- self .debug ('enum_display_monitors' , 'gwa' , gwa )
443390 yield ({
444391 b'left' : int (gwa .x ),
445392 b'top' : int (gwa .y ),
@@ -451,42 +398,32 @@ def enum_display_monitors(self, screen=0):
451398 # expected LP_Display instance instead of LP_XWindowAttributes
452399 root = cast (self .root , POINTER (Display ))
453400 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 )
458401 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 ])
461404 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 )
466409 })
467- self .xrandr .XRRFreeCrtcInfo (crtc_info )
410+ self .xrandr .XRRFreeCrtcInfo (crtc )
468411 self .xrandr .XRRFreeScreenResources (mon )
469412
470413 def get_pixels (self , monitor ):
471414 ''' Retrieve all pixels from a monitor. Pixels have to be RGB. '''
472415
473- self .debug ('get_pixels' )
474-
475416 width , height = monitor [b'width' ], monitor [b'height' ]
476417 left , top = monitor [b'left' ], monitor [b'top' ]
477418 ZPixmap = 2
478-
479419 allplanes = self .xlib .XAllPlanes ()
480- self .debug ('get_pixels' , 'allplanes' , allplanes )
481420
482421 # Fix for XGetImage:
483422 # expected LP_Display instance instead of LP_XWindowAttributes
484423 root = cast (self .root , POINTER (Display ))
485- self .debug ('get_pixels' , 'root' , root )
486424
487425 ximage = self .xlib .XGetImage (self .display , root , left , top , width ,
488426 height , allplanes , ZPixmap )
489- self .debug ('get_pixels' , 'ximage' , ximage )
490427 if not ximage :
491428 raise ScreenshotError ('MSS: XGetImage() failed.' )
492429
@@ -512,9 +449,6 @@ def pix(pixel, _resultats={}, b=pack):
512449 gmask = ximage .contents .green_mask
513450 bmask = ximage .contents .blue_mask
514451 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 )
518452 xrange = getattr (__builtins__ , 'xrange' , range )
519453 pixels = [pix (data [idx ])
520454 for idx in xrange (0 , (width * height ) - 2 , 3 )]
@@ -529,16 +463,12 @@ class MSSWindows(MSS):
529463 def __init__ (self ):
530464 ''' Windows initialisations. '''
531465
532- self .debug ('__init__' )
533-
534466 self ._set_argtypes ()
535467 self ._set_restypes ()
536468
537469 def _set_argtypes (self ):
538470 ''' Functions arguments. '''
539471
540- self .debug ('_set_argtypes' )
541-
542472 self .MONITORENUMPROC = WINFUNCTYPE (INT , DWORD , DWORD , POINTER (RECT ),
543473 DOUBLE )
544474 windll .user32 .GetSystemMetrics .argtypes = [INT ]
@@ -558,8 +488,6 @@ def _set_argtypes(self):
558488 def _set_restypes (self ):
559489 ''' Functions return type. '''
560490
561- self .debug ('_set_restypes' )
562-
563491 windll .user32 .GetSystemMetrics .restypes = INT
564492 windll .user32 .EnumDisplayMonitors .restypes = BOOL
565493 windll .user32 .GetWindowDC .restypes = HDC
@@ -575,8 +503,6 @@ def enum_display_monitors(self, screen=-1):
575503 Returns a dict with minimal requirements (see MSS class).
576504 '''
577505
578- self .debug ('enum_display_monitors' )
579-
580506 if screen == - 1 :
581507 SM_XVIRTUALSCREEN , SM_YVIRTUALSCREEN = 76 , 77
582508 SM_CXVIRTUALSCREEN , SM_CYVIRTUALSCREEN = 78 , 79
@@ -621,8 +547,6 @@ def get_pixels(self, monitor):
621547 https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
622548 '''
623549
624- self .debug ('get_pixels' )
625-
626550 width , height = monitor [b'width' ], monitor [b'height' ]
627551 left , top = monitor [b'left' ], monitor [b'top' ]
628552 SRCCOPY = 0xCC0020
@@ -647,14 +571,6 @@ def get_pixels(self, monitor):
647571 SRCCOPY )
648572 bits = windll .gdi32 .GetDIBits (memdc , bmp , 0 , height , self .image ,
649573 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-
658574 if bits != height :
659575 raise ScreenshotError ('MSS: GetDIBits() failed.' )
660576 finally :
0 commit comments