--- a/eric6/Snapshot/SnapshotWaylandGrabber.py Wed Apr 14 19:38:19 2021 +0200 +++ b/eric6/Snapshot/SnapshotWaylandGrabber.py Wed Apr 14 19:59:16 2021 +0200 @@ -9,6 +9,7 @@ import os import uuid +import contextlib from PyQt5.QtCore import pyqtSignal, QObject, QTimer from PyQt5.QtGui import QPixmap, QCursor @@ -141,11 +142,8 @@ filename = reply.arguments()[0] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass elif Globals.isGnomeDesktop(): path = self.__temporaryFilename() interface = QDBusInterface( @@ -163,11 +161,8 @@ filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass self.grabbed.emit(snapshot) @@ -200,11 +195,8 @@ filename = reply.arguments()[0] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass elif Globals.isGnomeDesktop(): # Step 1: grab entire desktop path = self.__temporaryFilename() @@ -224,11 +216,8 @@ filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass # Step 2: extract the area of the screen containing # the cursor @@ -264,11 +253,8 @@ filename = reply.arguments()[0] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass elif Globals.isGnomeDesktop(): path = self.__temporaryFilename() interface = QDBusInterface( @@ -287,11 +273,8 @@ filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass self.grabbed.emit(snapshot) @@ -324,11 +307,8 @@ filename = reply.arguments()[1] if filename: snapshot = QPixmap(filename) - try: + with contextlib.suppress(OSError): os.remove(filename) - except OSError: - # just ignore it - pass self.grabbed.emit(snapshot)