--- a/eric6/Snapshot/SnapWidget.py Sat Oct 10 16:03:53 2020 +0200 +++ b/eric6/Snapshot/SnapWidget.py Sun Oct 11 17:54:52 2020 +0200 @@ -7,16 +7,16 @@ Module implementing the snapshot widget. """ - # # SnapWidget and its associated modules are PyQt5 ports of Ksnapshot. # import os +import re from PyQt5.QtCore import ( - pyqtSlot, QFile, QFileInfo, QTimer, QPoint, QMimeData, Qt, QRegExp, - QLocale, QStandardPaths + pyqtSlot, Qt, QFile, QFileInfo, QTimer, QPoint, QMimeData, QLocale, + QStandardPaths ) from PyQt5.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence from PyQt5.QtWidgets import QWidget, QApplication, QShortcut @@ -269,16 +269,18 @@ name = os.path.basename(self.__filename) # If the name contains a number, then increment it. - numSearch = QRegExp("(^|[^\\d])(\\d+)") + numSearch = re.compile("(^|[^\\d])(\\d+)") # We want to match as far left as possible, and when the number is # at the start of the name. # Does it have a number? - start = numSearch.lastIndexIn(name) - if start != -1: + matches = list(numSearch.finditer(name)) + if matches: # It has a number, increment it. - start = numSearch.pos(2) # Only the second group is of interest. - numAsStr = numSearch.capturedTexts()[2] + match = matches[-1] + start = match.start(2) + # Only the second group is of interest. + numAsStr = match.group(2) number = "{0:0{width}d}".format( int(numAsStr) + 1, width=len(numAsStr)) name = name[:start] + number + name[start + len(numAsStr):] @@ -287,10 +289,10 @@ start = name.rfind('.') if start != -1: # has a '.' somewhere, e.g. it has an extension - name = name[:start] + '1' + name[start:] + name = name[:start] + '-1' + name[start:] else: # no extension, just tack it on to the end - name += '1' + name += '-1' self.__filename = os.path.join(os.path.dirname(self.__filename), name) self.__updateCaption()