diff -r 8c5296fe3056 -r 8a68afaf1ba2 eric7/QScintilla/Editor.py --- a/eric7/QScintilla/Editor.py Wed Jun 15 09:44:07 2022 +0200 +++ b/eric7/QScintilla/Editor.py Thu Jun 16 18:28:59 2022 +0200 @@ -12,13 +12,14 @@ import contextlib import difflib import os +import pathlib import re import editorconfig from PyQt6.QtCore import ( - pyqtSignal, pyqtSlot, Qt, QDir, QTimer, QModelIndex, QFileInfo, - QCryptographicHash, QEvent, QDateTime, QPoint, QSize + pyqtSignal, pyqtSlot, Qt, QDir, QTimer, QModelIndex, QCryptographicHash, + QEvent, QDateTime, QPoint, QSize ) from PyQt6.QtGui import QPalette, QFont, QPixmap, QPainter, QActionGroup from PyQt6.QtWidgets import ( @@ -397,7 +398,7 @@ if editor is None: if self.fileName: if ( - (QFileInfo(self.fileName).size() // 1024) > + (pathlib.Path(self.fileName).stat().st_size // 1024) > Preferences.getEditor("WarnFilesize") ): res = EricMessageBox.yesNo( @@ -406,8 +407,10 @@ self.tr("""<p>The size of the file <b>{0}</b>""" """ is <b>{1} KB</b>.""" """ Do you really want to load it?</p>""") - .format(self.fileName, - QFileInfo(self.fileName).size() // 1024), + .format( + self.fileName, + pathlib.Path(self.fileName).stat().st_size // 1024 + ), icon=EricMessageBox.Warning) if not res: raise OSError() @@ -1968,7 +1971,7 @@ @param m modification status """ if not m and bool(self.fileName): - self.lastModified = QFileInfo(self.fileName).lastModified() + self.lastModified = pathlib.Path(self.fileName).stat().st_mtime self.modificationStatusChanged.emit(m, self) self.undoAvailable.emit(self.isUndoAvailable()) self.redoAvailable.emit(self.isRedoAvailable()) @@ -3230,7 +3233,7 @@ self.extractTasks() self.setModified(modified) - self.lastModified = QFileInfo(self.fileName).lastModified() + self.lastModified = pathlib.Path(self.fileName).stat().st_mtime def __convertTabs(self): """ @@ -3376,23 +3379,22 @@ if fn.endswith("."): fn = fn[:-1] - ext = QFileInfo(fn).suffix() - if not ext: + fpath = pathlib.Path(fn) + if not fpath.suffix: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: - fn += ex - if QFileInfo(fn).exists(): + fpath = fpath.with_suffix(ex) + if fpath.exists(): res = EricMessageBox.yesNo( self, self.tr("Save File"), self.tr("<p>The file <b>{0}</b> already exists." - " Overwrite it?</p>").format(fn), + " Overwrite it?</p>").format(str(fpath)), icon=EricMessageBox.Warning) if not res: return "" - fn = Utilities.toNativeSeparators(fn) - - return fn + + return str(fpath) def saveFileCopy(self, path=None): """ @@ -3482,7 +3484,7 @@ self.setLanguage(self.fileName) - self.lastModified = QFileInfo(self.fileName).lastModified() + self.lastModified = pathlib.Path(self.fileName).stat().st_mtime if newName is not None: self.vm.addToRecentList(newName) self.editorSaved.emit(self.fileName) @@ -3492,7 +3494,7 @@ self.__checkEncoding() return True else: - self.lastModified = QFileInfo(fn).lastModified() + self.lastModified = pathlib.Path(fn).stat().st_mtime return False def saveFileAs(self, path=None, toProject=False): @@ -3523,7 +3525,7 @@ if self.lexer_ is None: self.setLanguage(self.fileName) - self.lastModified = QFileInfo(self.fileName).lastModified() + self.lastModified = pathlib.Path(self.fileName).stat().st_mtime self.vm.setEditorName(self, self.fileName) self.__updateReadOnly(True) @@ -6875,24 +6877,23 @@ if not fname: return # user aborted - ext = QFileInfo(fname).suffix() - if not ext: + fpath = pathlib.Path(fname) + if not fpath.suffix: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: - fname += ex - if QFileInfo(fname).exists(): + fpath = fpath.with_suffix(ex) + if fpath.exists(): res = EricMessageBox.yesNo( self, self.tr("Save macro"), self.tr("<p>The macro file <b>{0}</b> already exists." - " Overwrite it?</p>").format(fname), + " Overwrite it?</p>").format(str(fpath)), icon=EricMessageBox.Warning) if not res: return - fname = Utilities.toNativeSeparators(fname) try: - with open(fname, "w", encoding="utf-8") as f: + with fpath.open("w", encoding="utf-8") as f: f.write("{0}{1}".format(name, "\n")) f.write(self.macros[name].save()) except OSError: @@ -6901,7 +6902,7 @@ self.tr("Error saving macro"), self.tr( "<p>The macro file <b>{0}</b> could not be written.</p>") - .format(fname)) + .format(str(fpath))) return def macroRecordingStart(self): @@ -7083,8 +7084,7 @@ if ( self.vm.editorsCheckFocusInEnabled() and not self.inReopenPrompt and self.fileName and - QFileInfo(self.fileName).lastModified().toString() != - self.lastModified.toString() + pathlib.Path(self.fileName).stat().st_mtime != self.lastModified ): self.inReopenPrompt = True if Preferences.getEditor("AutoReopen") and not self.isModified(): @@ -7109,7 +7109,9 @@ self.refresh() else: # do not prompt for this change again... - self.lastModified = QFileInfo(self.fileName).lastModified() + self.lastModified = ( + pathlib.Path(self.fileName).stat().st_mtime + ) self.inReopenPrompt = False self.setCursorFlashTime(QApplication.cursorFlashTime()) @@ -7299,7 +7301,7 @@ return readOnly = ( - not QFileInfo(self.fileName).isWritable() or + not os.access(self.fileName, os.W_OK) or self.isReadOnly() ) if not bForce and (readOnly == self.isReadOnly()): @@ -7445,7 +7447,7 @@ for url in event.mimeData().urls(): fname = url.toLocalFile() if fname: - if not QFileInfo(fname).isDir(): + if not pathlib.Path(fname).is_dir(): self.vm.openSourceFile(fname) else: EricMessageBox.information(