eric7/Project/ProjectResourcesBrowser.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 9150
0eab9aafa3b2
child 9153
506e35e424d5
--- a/eric7/Project/ProjectResourcesBrowser.py	Wed Jun 15 09:44:07 2022 +0200
+++ b/eric7/Project/ProjectResourcesBrowser.py	Thu Jun 16 18:28:59 2022 +0200
@@ -9,8 +9,9 @@
 
 import os
 import contextlib
+import pathlib
 
-from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess
+from PyQt6.QtCore import QThread, pyqtSignal, QProcess
 from PyQt6.QtWidgets import QDialog, QApplication, QMenu
 
 from EricWidgets.EricApplication import ericApp
@@ -477,13 +478,12 @@
                 # user aborted or didn't enter a filename
                 return
             
-            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 os.path.exists(fname):
+                    fpath = fpath.with_suffix(ex)
+            if fpath.exists():
                 res = EricMessageBox.yesNo(
                     self,
                     self.tr("New Resource"),
@@ -496,8 +496,8 @@
             try:
                 newline = (None if self.project.useSystemEol()
                            else self.project.getEolString())
-                with open(fname, 'w', encoding="utf-8",
-                          newline=newline) as rcfile:
+                with fpath.open('w', encoding="utf-8",
+                                newline=newline) as rcfile:
                     rcfile.write('<!DOCTYPE RCC>\n')
                     rcfile.write('<RCC version="1.0">\n')
                     rcfile.write('<qresource>\n')
@@ -510,11 +510,11 @@
                     self.tr(
                         "<p>The new resource file <b>{0}</b> could not"
                         " be created.<br>Problem: {1}</p>")
-                    .format(fname, str(e)))
+                    .format(str(fpath), str(e)))
                 return
             
-            self.project.appendFile(fname)
-            self.sourceFile.emit(fname)
+            self.project.appendFile(str(fpath))
+            self.sourceFile.emit(str(fpath))
         
     def __deleteFile(self):
         """

eric ide

mercurial