eric7/Snapshot/SnapWidget.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9162
8b75b1668583
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
10 # 10 #
11 # SnapWidget and its associated modules are PyQt6 ports of Ksnapshot. 11 # SnapWidget and its associated modules are PyQt6 ports of Ksnapshot.
12 # 12 #
13 13
14 import os 14 import os
15 import pathlib
15 import re 16 import re
16 import contextlib 17 import contextlib
17 18
18 from PyQt6.QtCore import ( 19 from PyQt6.QtCore import (
19 pyqtSlot, Qt, QFile, QFileInfo, QTimer, QPoint, QMimeData, QLocale, 20 pyqtSlot, Qt, QFile, QTimer, QPoint, QMimeData, QLocale, QStandardPaths,
20 QStandardPaths, QIODevice 21 QIODevice
21 ) 22 )
22 from PyQt6.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence, QShortcut 23 from PyQt6.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence, QShortcut
23 from PyQt6.QtWidgets import QWidget, QApplication 24 from PyQt6.QtWidgets import QWidget, QApplication
24 25
25 from EricWidgets import EricFileDialog, EricMessageBox 26 from EricWidgets import EricFileDialog, EricMessageBox
208 self.__defaultFilter, 209 self.__defaultFilter,
209 EricFileDialog.DontConfirmOverwrite) 210 EricFileDialog.DontConfirmOverwrite)
210 if not fileName: 211 if not fileName:
211 return 212 return
212 213
213 ext = QFileInfo(fileName).suffix() 214 fpath = pathlib.Path(fileName)
214 if not ext: 215 if not fpath.suffix:
215 ex = selectedFilter.split("(*")[1].split(")")[0] 216 ex = selectedFilter.split("(*")[1].split(")")[0]
216 if ex: 217 if ex:
217 fileName += ex 218 fpath = fpath.with_suffix(ex)
218 219
219 if self.__saveImage(fileName): 220 if self.__saveImage(str(fpath)):
220 self.__modified = False 221 self.__modified = False
221 self.__filename = fileName 222 self.__filename = str(fpath)
222 self.__autoIncFilename() 223 self.__autoIncFilename()
223 self.__updateCaption() 224 self.__updateCaption()
224 225
225 def __saveImage(self, fileName): 226 def __saveImage(self, fileName):
226 """ 227 """
227 Private method to save the snapshot. 228 Private method to save the snapshot.
228 229
229 @param fileName name of the file to save to (string) 230 @param fileName name of the file to save to (string)
230 @return flag indicating success (boolean) 231 @return flag indicating success (boolean)
231 """ 232 """
232 if QFileInfo(fileName).exists(): 233 if pathlib.Path(fileName).exists():
233 res = EricMessageBox.yesNo( 234 res = EricMessageBox.yesNo(
234 self, 235 self,
235 self.tr("Save Snapshot"), 236 self.tr("Save Snapshot"),
236 self.tr("<p>The file <b>{0}</b> already exists." 237 self.tr("<p>The file <b>{0}</b> already exists."
237 " Overwrite it?</p>").format(fileName), 238 " Overwrite it?</p>").format(fileName),

eric ide

mercurial