eric6/Snapshot/SnapWidget.py

changeset 7775
4a1db75550bd
parent 7771
787a6b3f8c9f
child 7923
91e843545d9a
equal deleted inserted replaced
7774:9eed155411f0 7775:4a1db75550bd
5 5
6 """ 6 """
7 Module implementing the snapshot widget. 7 Module implementing the snapshot widget.
8 """ 8 """
9 9
10
11 # 10 #
12 # SnapWidget and its associated modules are PyQt5 ports of Ksnapshot. 11 # SnapWidget and its associated modules are PyQt5 ports of Ksnapshot.
13 # 12 #
14 13
15 import os 14 import os
15 import re
16 16
17 from PyQt5.QtCore import ( 17 from PyQt5.QtCore import (
18 pyqtSlot, QFile, QFileInfo, QTimer, QPoint, QMimeData, Qt, QRegExp, 18 pyqtSlot, Qt, QFile, QFileInfo, QTimer, QPoint, QMimeData, QLocale,
19 QLocale, QStandardPaths 19 QStandardPaths
20 ) 20 )
21 from PyQt5.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence 21 from PyQt5.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence
22 from PyQt5.QtWidgets import QWidget, QApplication, QShortcut 22 from PyQt5.QtWidgets import QWidget, QApplication, QShortcut
23 23
24 from E5Gui import E5FileDialog, E5MessageBox 24 from E5Gui import E5FileDialog, E5MessageBox
267 """ 267 """
268 # Extract the file name 268 # Extract the file name
269 name = os.path.basename(self.__filename) 269 name = os.path.basename(self.__filename)
270 270
271 # If the name contains a number, then increment it. 271 # If the name contains a number, then increment it.
272 numSearch = QRegExp("(^|[^\\d])(\\d+)") 272 numSearch = re.compile("(^|[^\\d])(\\d+)")
273 # We want to match as far left as possible, and when the number is 273 # We want to match as far left as possible, and when the number is
274 # at the start of the name. 274 # at the start of the name.
275 275
276 # Does it have a number? 276 # Does it have a number?
277 start = numSearch.lastIndexIn(name) 277 matches = list(numSearch.finditer(name))
278 if start != -1: 278 if matches:
279 # It has a number, increment it. 279 # It has a number, increment it.
280 start = numSearch.pos(2) # Only the second group is of interest. 280 match = matches[-1]
281 numAsStr = numSearch.capturedTexts()[2] 281 start = match.start(2)
282 # Only the second group is of interest.
283 numAsStr = match.group(2)
282 number = "{0:0{width}d}".format( 284 number = "{0:0{width}d}".format(
283 int(numAsStr) + 1, width=len(numAsStr)) 285 int(numAsStr) + 1, width=len(numAsStr))
284 name = name[:start] + number + name[start + len(numAsStr):] 286 name = name[:start] + number + name[start + len(numAsStr):]
285 else: 287 else:
286 # no number 288 # no number
287 start = name.rfind('.') 289 start = name.rfind('.')
288 if start != -1: 290 if start != -1:
289 # has a '.' somewhere, e.g. it has an extension 291 # has a '.' somewhere, e.g. it has an extension
290 name = name[:start] + '1' + name[start:] 292 name = name[:start] + '-1' + name[start:]
291 else: 293 else:
292 # no extension, just tack it on to the end 294 # no extension, just tack it on to the end
293 name += '1' 295 name += '-1'
294 296
295 self.__filename = os.path.join(os.path.dirname(self.__filename), name) 297 self.__filename = os.path.join(os.path.dirname(self.__filename), name)
296 self.__updateCaption() 298 self.__updateCaption()
297 299
298 @pyqtSlot() 300 @pyqtSlot()

eric ide

mercurial