|
25 | 25 | 0.0.2 - add support for python 3 on Windows and GNU/Linux |
26 | 26 | 0.0.3 - remove PNG filters |
27 | 27 | - remove 'ext' argument, using only PNG |
| 28 | + - do not overwrite existing image files |
28 | 29 |
|
29 | 30 | You can always get the latest version of this module at: |
30 | 31 |
|
|
53 | 54 |
|
54 | 55 | from ctypes.util import find_library |
55 | 56 | from struct import pack |
| 57 | +from os.path import isfile |
56 | 58 | from platform import system |
57 | 59 | import sys |
58 | 60 | import zlib |
|
63 | 65 |
|
64 | 66 | elif system() == 'Linux': |
65 | 67 | from os import environ |
66 | | - from os.path import expanduser, isfile |
| 68 | + from os.path import expanduser |
67 | 69 | import xml.etree.ElementTree as ET |
68 | 70 | from ctypes import byref, cast, cdll |
69 | 71 | from ctypes import ( |
@@ -236,18 +238,21 @@ def save(self, output='mss', oneshot=False): |
236 | 238 | i += 1 |
237 | 239 | filename += '.png' |
238 | 240 |
|
239 | | - pixels = self.get_pixels(monitor) |
240 | | - if pixels is None: |
241 | | - raise ValueError('MSS: no data to process.') |
242 | | - |
243 | | - if hasattr(self, 'save_'): |
244 | | - img_out = self.save_(output=filename) |
| 241 | + if not isfile(filename): |
| 242 | + pixels = self.get_pixels(monitor) |
| 243 | + if pixels is None: |
| 244 | + raise ValueError('MSS: no data to process.') |
| 245 | + |
| 246 | + if hasattr(self, 'save_'): |
| 247 | + img_out = self.save_(output=filename) |
| 248 | + else: |
| 249 | + img = MSSImage(pixels, monitor[b'width'], monitor[b'height']) |
| 250 | + img_out = img.dump(filename) |
| 251 | + self.debug('save', 'img_out', img_out) |
| 252 | + if img_out is not None: |
| 253 | + yield img_out |
245 | 254 | else: |
246 | | - img = MSSImage(pixels, monitor[b'width'], monitor[b'height']) |
247 | | - img_out = img.dump(filename) |
248 | | - self.debug('save', 'img_out', img_out) |
249 | | - if img_out is not None: |
250 | | - yield img_out |
| 255 | + yield filename + ' (already exists)' |
251 | 256 |
|
252 | 257 | def enum_display_monitors(self): |
253 | 258 | ''' Get positions of all monitors. |
|
0 commit comments