Skip to content

Commit 92a4089

Browse files
author
BoboTiG
committed
Remove init(). DEBUG had to be setted as mss_class.DEBUG = True
1 parent cf85f2f commit 92a4089

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

mss.py

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ class MSS(object):
114114

115115
DEBUG = False
116116

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-
124117
def debug(self, method='', scalar=None, value=None):
125118
''' Simple debug output. '''
126119

@@ -131,10 +124,6 @@ def debug(self, method='', scalar=None, value=None):
131124
print('{}() {} {} {}'.format(method, scalar,
132125
type(value).__name__, value))
133126

134-
def init(self):
135-
''' OS dependent initialiations. '''
136-
pass
137-
138127
def enum_display_monitors(self):
139128
''' Get positions of all monitors.
140129
@@ -253,10 +242,6 @@ class MSSMac(MSS):
253242
It uses intensively the Quartz.
254243
'''
255244

256-
def init(self):
257-
''' Mac OSX initialisations '''
258-
self.debug('init')
259-
260245
def enum_display_monitors(self, screen=0):
261246
''' Get positions of one or more monitors.
262247
Returns a dict with minimal requirements (see MSS class).
@@ -301,11 +286,11 @@ def get_pixels(self, monitor):
301286
width, height = monitor[b'width'], monitor[b'height']
302287
left, top = monitor[b'left'], monitor[b'top']
303288
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:
307292
raise ScreenshotError('MSS: CGWindowListCreateImage() failed.')
308-
return image
293+
return self.image
309294

310295
def save_img(self, data, width, height, output):
311296
''' Use my own save_img() method. Because I'm Mac! '''
@@ -333,10 +318,10 @@ def __del__(self):
333318
if self.display:
334319
self.xlib.XCloseDisplay(self.display)
335320

336-
def init(self):
321+
def __init__(self):
337322
''' GNU/Linux initialisations '''
338323

339-
self.debug('init')
324+
self.debug('__init__')
340325

341326
x11 = find_library('X11')
342327
if not x11:
@@ -478,7 +463,7 @@ def get_pixels(self, monitor):
478463
ximage = self.xlib.XGetImage(self.display, root, left, top, width,
479464
height, allplanes, ZPixmap)
480465
if not ximage:
481-
raise ScreenshotError('XGetImage() failed.')
466+
raise ScreenshotError('MSS: XGetImage() failed.')
482467

483468
def pix(pixel, _resultats={}, b=pack):
484469
''' Apply shifts to a pixel to get the RGB values.
@@ -495,16 +480,17 @@ def pix(pixel, _resultats={}, b=pack):
495480
for y in range(height) for x in range(width)]
496481

497482
self.xlib.XFree(ximage)
498-
return b''.join(pixels)
483+
self.image = b''.join(pixels)
484+
return self.image
499485

500486

501487
class MSSWindows(MSS):
502488
''' Mutli-screen shot implementation for Microsoft Windows. '''
503489

504-
def init(self):
490+
def __init__(self):
505491
''' Windows initialisations '''
506492

507-
self.debug('init')
493+
self.debug('__init__')
508494

509495
self._set_argtypes()
510496
self._set_restypes()
@@ -677,20 +663,23 @@ def pix(pixel, _resultats={}, b=pack):
677663
return b''.join(scanlines)
678664

679665

680-
def main(argv=[]):
666+
def main():
681667
''' Usage example. '''
682668

683669
systems = {'Darwin': MSSMac, 'Linux': MSSLinux, 'Windows': MSSWindows}
684-
mss = systems[system()](debug='--debug' in argv)
670+
mss = systems[system()]()
671+
#mss.DEBUG = True
685672

686673
def on_exists(fname):
687674
''' Callback example when we try to overwrite an existing
688675
screen shot.
689676
'''
690677
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)
694683
return True
695684

696685
try:
@@ -718,4 +707,4 @@ def on_exists(fname):
718707

719708

720709
if __name__ == '__main__':
721-
sys.exit(main(sys.argv))
710+
sys.exit(main())

0 commit comments

Comments
 (0)