@@ -114,13 +114,6 @@ class MSS(object):
114
114
115
115
DEBUG = False
116
116
117
- def __init__ (self , debug = False ):
118
- ''' Global vars and class overload. '''
119
-
120
- self .DEBUG = debug in [True , 1 , 'on' 'yes' , 'oui' ]
121
- self .debug ('__init__' , 'DEBUG' , self .DEBUG )
122
- self .init ()
123
-
124
117
def debug (self , method = '' , scalar = None , value = None ):
125
118
''' Simple debug output. '''
126
119
@@ -131,10 +124,6 @@ def debug(self, method='', scalar=None, value=None):
131
124
print ('{}() {} {} {}' .format (method , scalar ,
132
125
type (value ).__name__ , value ))
133
126
134
- def init (self ):
135
- ''' OS dependent initialiations. '''
136
- pass
137
-
138
127
def enum_display_monitors (self ):
139
128
''' Get positions of all monitors.
140
129
@@ -253,10 +242,6 @@ class MSSMac(MSS):
253
242
It uses intensively the Quartz.
254
243
'''
255
244
256
- def init (self ):
257
- ''' Mac OSX initialisations '''
258
- self .debug ('init' )
259
-
260
245
def enum_display_monitors (self , screen = 0 ):
261
246
''' Get positions of one or more monitors.
262
247
Returns a dict with minimal requirements (see MSS class).
@@ -301,11 +286,11 @@ def get_pixels(self, monitor):
301
286
width , height = monitor [b'width' ], monitor [b'height' ]
302
287
left , top = monitor [b'left' ], monitor [b'top' ]
303
288
rect = CGRect ((left , top ), (width , height ))
304
- image = CGWindowListCreateImage (rect , kCGWindowListOptionOnScreenOnly ,
305
- kCGNullWindowID , kCGWindowImageDefault )
306
- if not image :
289
+ self . image = CGWindowListCreateImage (rect , kCGWindowListOptionOnScreenOnly ,
290
+ kCGNullWindowID , kCGWindowImageDefault )
291
+ if not self . image :
307
292
raise ScreenshotError ('MSS: CGWindowListCreateImage() failed.' )
308
- return image
293
+ return self . image
309
294
310
295
def save_img (self , data , width , height , output ):
311
296
''' Use my own save_img() method. Because I'm Mac! '''
@@ -333,10 +318,10 @@ def __del__(self):
333
318
if self .display :
334
319
self .xlib .XCloseDisplay (self .display )
335
320
336
- def init (self ):
321
+ def __init__ (self ):
337
322
''' GNU/Linux initialisations '''
338
323
339
- self .debug ('init ' )
324
+ self .debug ('__init__ ' )
340
325
341
326
x11 = find_library ('X11' )
342
327
if not x11 :
@@ -478,7 +463,7 @@ def get_pixels(self, monitor):
478
463
ximage = self .xlib .XGetImage (self .display , root , left , top , width ,
479
464
height , allplanes , ZPixmap )
480
465
if not ximage :
481
- raise ScreenshotError ('XGetImage() failed.' )
466
+ raise ScreenshotError ('MSS: XGetImage() failed.' )
482
467
483
468
def pix (pixel , _resultats = {}, b = pack ):
484
469
''' Apply shifts to a pixel to get the RGB values.
@@ -495,16 +480,17 @@ def pix(pixel, _resultats={}, b=pack):
495
480
for y in range (height ) for x in range (width )]
496
481
497
482
self .xlib .XFree (ximage )
498
- return b'' .join (pixels )
483
+ self .image = b'' .join (pixels )
484
+ return self .image
499
485
500
486
501
487
class MSSWindows (MSS ):
502
488
''' Mutli-screen shot implementation for Microsoft Windows. '''
503
489
504
- def init (self ):
490
+ def __init__ (self ):
505
491
''' Windows initialisations '''
506
492
507
- self .debug ('init ' )
493
+ self .debug ('__init__ ' )
508
494
509
495
self ._set_argtypes ()
510
496
self ._set_restypes ()
@@ -677,20 +663,23 @@ def pix(pixel, _resultats={}, b=pack):
677
663
return b'' .join (scanlines )
678
664
679
665
680
- def main (argv = [] ):
666
+ def main ():
681
667
''' Usage example. '''
682
668
683
669
systems = {'Darwin' : MSSMac , 'Linux' : MSSLinux , 'Windows' : MSSWindows }
684
- mss = systems [system ()](debug = '--debug' in argv )
670
+ mss = systems [system ()]()
671
+ #mss.DEBUG = True
685
672
686
673
def on_exists (fname ):
687
674
''' Callback example when we try to overwrite an existing
688
675
screen shot.
689
676
'''
690
677
from os import rename
691
- newfile = fname + '.old'
692
- print ('{} -> {}' .format (fname , newfile ))
693
- rename (fname , newfile )
678
+ from os .path import isfile
679
+ if isfile (fname ):
680
+ newfile = fname + '.old'
681
+ print ('{} -> {}' .format (fname , newfile ))
682
+ rename (fname , newfile )
694
683
return True
695
684
696
685
try :
@@ -718,4 +707,4 @@ def on_exists(fname):
718
707
719
708
720
709
if __name__ == '__main__' :
721
- sys .exit (main (sys . argv ))
710
+ sys .exit (main ())
0 commit comments