eric7/Project/ProjectFormsBrowser.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 9150
0eab9aafa3b2
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
9 9
10 import os 10 import os
11 import sys 11 import sys
12 import shutil 12 import shutil
13 import contextlib 13 import contextlib
14 14 import pathlib
15 from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess 15
16 from PyQt6.QtCore import QThread, pyqtSignal, QProcess
16 from PyQt6.QtWidgets import QDialog, QInputDialog, QApplication, QMenu 17 from PyQt6.QtWidgets import QDialog, QInputDialog, QApplication, QMenu
17 18
18 from EricWidgets.EricApplication import ericApp 19 from EricWidgets.EricApplication import ericApp
19 from EricWidgets import EricMessageBox, EricFileDialog 20 from EricWidgets import EricMessageBox, EricFileDialog
20 from EricWidgets.EricProgressDialog import EricProgressDialog 21 from EricWidgets.EricProgressDialog import EricProgressDialog
603 604
604 if not fname: 605 if not fname:
605 # user aborted or didn't enter a filename 606 # user aborted or didn't enter a filename
606 return 607 return
607 608
608 ext = QFileInfo(fname).suffix() 609 fpath = pathlib.Path(fname)
609 if not ext: 610 if not fpath.suffix:
610 ex = selectedFilter.split("(*")[1].split(")")[0] 611 ex = selectedFilter.split("(*")[1].split(")")[0]
611 if ex: 612 if ex:
612 fname += ex 613 fpath = fpath.with_suffix(ex)
613 614 if fpath.exists():
614 if os.path.exists(fname):
615 res = EricMessageBox.yesNo( 615 res = EricMessageBox.yesNo(
616 self, 616 self,
617 self.tr("New Form"), 617 self.tr("New Form"),
618 self.tr("The file already exists! Overwrite it?"), 618 self.tr("The file already exists! Overwrite it?"),
619 icon=EricMessageBox.Warning) 619 icon=EricMessageBox.Warning)
620 if not res: 620 if not res:
621 # user selected to not overwrite 621 # user selected to not overwrite
622 return 622 return
623 623
624 try: 624 try:
625 shutil.copy(templateFile, fname) 625 shutil.copy(templateFile, fpath)
626 except OSError as e: 626 except OSError as err:
627 EricMessageBox.critical( 627 EricMessageBox.critical(
628 self, 628 self,
629 self.tr("New Form"), 629 self.tr("New Form"),
630 self.tr( 630 self.tr(
631 "<p>The new form file <b>{0}</b> could not be created.<br>" 631 "<p>The new form file <b>{0}</b> could not be created.<br>"
632 "Problem: {1}</p>").format(fname, str(e))) 632 "Problem: {1}</p>").format(str(fpath), str(err)))
633 return 633 return
634 634
635 self.project.appendFile(fname) 635 self.project.appendFile(str(fpath))
636 self.designerFile.emit(fname) 636 self.designerFile.emit(str(fpath))
637 637
638 def __deleteFile(self): 638 def __deleteFile(self):
639 """ 639 """
640 Private method to delete a form file from the project. 640 Private method to delete a form file from the project.
641 """ 641 """

eric ide

mercurial