@@ -103,7 +103,8 @@ class BITMAPINFOHEADER(Structure):
103
103
class BITMAPINFO (Structure ):
104
104
_fields_ = [('bmiHeader' , BITMAPINFOHEADER ), ('bmiColors' , DWORD * 3 )]
105
105
else :
106
- raise ScreenshotError ('MSS: system "{0}" not implemented.' .format (system ()))
106
+ err = 'MSS: system "{0}" not implemented.' .format (system ())
107
+ raise ScreenshotError (err )
107
108
108
109
109
110
# ----------------------------------------------------------------------
@@ -122,7 +123,7 @@ def debug(self, method='', scalar=None, value=None):
122
123
print (':: {0}()' .format (method ))
123
124
else :
124
125
print ('{0}() {1} {2} {3}' .format (method , scalar ,
125
- type (value ).__name__ , value ))
126
+ type (value ).__name__ , value ))
126
127
127
128
def enum_display_monitors (self ):
128
129
''' Get positions of all monitors.
@@ -234,7 +235,8 @@ def save_img(self, data, width, height, output):
234
235
fileh .write (
235
236
magic + b'' .join (ihdr ) + b'' .join (idat ) + b'' .join (iend ))
236
237
return
237
- raise ScreenshotError ('MSS: error writing data to "{0}".' .format (output ))
238
+ err = 'MSS: error writing data to "{0}".' .format (output )
239
+ raise ScreenshotError (err )
238
240
239
241
240
242
class MSSMac (MSS ):
@@ -284,8 +286,10 @@ def get_pixels(self, monitor):
284
286
width , height = monitor [b'width' ], monitor [b'height' ]
285
287
left , top = monitor [b'left' ], monitor [b'top' ]
286
288
rect = CGRect ((left , top ), (width , height ))
287
- self .image = CGWindowListCreateImage (rect , kCGWindowListOptionOnScreenOnly ,
288
- kCGNullWindowID , kCGWindowImageDefault )
289
+ options = kCGWindowListOptionOnScreenOnly
290
+ winid = kCGNullWindowID
291
+ default = kCGWindowImageDefault
292
+ self .image = CGWindowListCreateImage (rect , options , winid , default )
289
293
if not self .image :
290
294
raise ScreenshotError ('MSS: CGWindowListCreateImage() failed.' )
291
295
return self .image
@@ -300,7 +304,8 @@ def save_img(self, data, width, height, output):
300
304
CGImageDestinationAddImage (dest , data , None )
301
305
if CGImageDestinationFinalize (dest ):
302
306
return
303
- raise ScreenshotError ('MSS: error writing to file "{0}".' .format (output ))
307
+ err = 'MSS: error writing to file "{0}".' .format (output )
308
+ raise ScreenshotError (err )
304
309
305
310
306
311
class MSSLinux (MSS ):
@@ -574,8 +579,9 @@ def _callback(monitor, dc, rect, data):
574
579
def get_pixels (self , monitor ):
575
580
''' Retrieve all pixels from a monitor. Pixels have to be RGB.
576
581
577
- [1] A bottom-up DIB is specified by setting the height to a positive number,
578
- while a top-down DIB is specified by setting the height to a negative number.
582
+ [1] A bottom-up DIB is specified by setting the height to a
583
+ positive number, while a top-down DIB is specified by
584
+ setting the height to a negative number.
579
585
https://msdn.microsoft.com/en-us/library/ms787796.aspx
580
586
https://msdn.microsoft.com/en-us/library/dd144879%28v=vs.85%29.aspx
581
587
'''
@@ -595,7 +601,7 @@ def get_pixels(self, monitor):
595
601
bmi .bmiHeader .biHeight = - height # Why minus? See [1]
596
602
bmi .bmiHeader .biPlanes = 1 # Always 1
597
603
bmi .bmiHeader .biBitCount = 24
598
- bmi .bmiHeader .biCompression = BI_RGB ;
604
+ bmi .bmiHeader .biCompression = BI_RGB
599
605
buffer_len = height * width * 3
600
606
self .image = create_string_buffer (buffer_len )
601
607
srcdc = windll .user32 .GetWindowDC (0 )
@@ -628,7 +634,8 @@ def get_pixels(self, monitor):
628
634
# Replace pixels values: BGR to RGB
629
635
# @TODO: this part takes most of the time. Need a better solution.
630
636
for idx in range (0 , buffer_len - 2 , 3 ):
631
- self .image [idx + 2 ], self .image [idx ] = self .image [idx ], self .image [idx + 2 ]
637
+ self .image [idx + 2 ], self .image [idx ] = \
638
+ self .image [idx ], self .image [idx + 2 ]
632
639
return self .image
633
640
634
641
@@ -637,7 +644,7 @@ def main():
637
644
638
645
systems = {'Darwin' : MSSMac , 'Linux' : MSSLinux , 'Windows' : MSSWindows }
639
646
mss = systems [system ()]()
640
- #mss.DEBUG = True
647
+ # mss.DEBUG = True
641
648
642
649
def on_exists (fname ):
643
650
''' Callback example when we try to overwrite an existing
0 commit comments