eric7/Project/ProjectFormsBrowser.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 9150
0eab9aafa3b2
child 9153
506e35e424d5
--- a/eric7/Project/ProjectFormsBrowser.py	Wed Jun 15 09:44:07 2022 +0200
+++ b/eric7/Project/ProjectFormsBrowser.py	Thu Jun 16 18:28:59 2022 +0200
@@ -11,8 +11,9 @@
 import sys
 import shutil
 import contextlib
+import pathlib
 
-from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess
+from PyQt6.QtCore import QThread, pyqtSignal, QProcess
 from PyQt6.QtWidgets import QDialog, QInputDialog, QApplication, QMenu
 
 from EricWidgets.EricApplication import ericApp
@@ -605,13 +606,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 Form"),
@@ -622,18 +622,18 @@
                 return
         
         try:
-            shutil.copy(templateFile, fname)
-        except OSError as e:
+            shutil.copy(templateFile, fpath)
+        except OSError as err:
             EricMessageBox.critical(
                 self,
                 self.tr("New Form"),
                 self.tr(
                     "<p>The new form file <b>{0}</b> could not be created.<br>"
-                    "Problem: {1}</p>").format(fname, str(e)))
+                    "Problem: {1}</p>").format(str(fpath), str(err)))
             return
         
-        self.project.appendFile(fname)
-        self.designerFile.emit(fname)
+        self.project.appendFile(str(fpath))
+        self.designerFile.emit(str(fpath))
         
     def __deleteFile(self):
         """

eric ide

mercurial