13 import contextlib |
13 import contextlib |
14 |
14 |
15 from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess |
15 from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess |
16 from PyQt6.QtWidgets import QDialog, QInputDialog, QApplication, QMenu |
16 from PyQt6.QtWidgets import QDialog, QInputDialog, QApplication, QMenu |
17 |
17 |
18 from E5Gui.E5Application import e5App |
18 from E5Gui.EricApplication import ericApp |
19 from E5Gui import E5MessageBox, E5FileDialog |
19 from E5Gui import EricMessageBox, EricFileDialog |
20 from E5Gui.E5ProgressDialog import E5ProgressDialog |
20 from E5Gui.EricProgressDialog import EricProgressDialog |
21 |
21 |
22 from .ProjectBrowserModel import ( |
22 from .ProjectBrowserModel import ( |
23 ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem, |
23 ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem, |
24 ProjectBrowserDirectoryItem, ProjectBrowserFormType |
24 ProjectBrowserDirectoryItem, ProjectBrowserFormType |
25 ) |
25 ) |
591 |
591 |
592 templateIndex = self.templateTypes4.index(selectedForm) |
592 templateIndex = self.templateTypes4.index(selectedForm) |
593 templateFile = os.path.join( |
593 templateFile = os.path.join( |
594 getConfig('ericTemplatesDir'), self.templates4[templateIndex]) |
594 getConfig('ericTemplatesDir'), self.templates4[templateIndex]) |
595 |
595 |
596 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
596 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
597 self, |
597 self, |
598 self.tr("New Form"), |
598 self.tr("New Form"), |
599 path, |
599 path, |
600 self.tr("Qt User-Interface Files (*.ui);;All Files (*)"), |
600 self.tr("Qt User-Interface Files (*.ui);;All Files (*)"), |
601 "", |
601 "", |
602 E5FileDialog.DontConfirmOverwrite) |
602 EricFileDialog.DontConfirmOverwrite) |
603 |
603 |
604 if not fname: |
604 if not fname: |
605 # user aborted or didn't enter a filename |
605 # user aborted or didn't enter a filename |
606 return |
606 return |
607 |
607 |
610 ex = selectedFilter.split("(*")[1].split(")")[0] |
610 ex = selectedFilter.split("(*")[1].split(")")[0] |
611 if ex: |
611 if ex: |
612 fname += ex |
612 fname += ex |
613 |
613 |
614 if os.path.exists(fname): |
614 if os.path.exists(fname): |
615 res = E5MessageBox.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=E5MessageBox.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, fname) |
626 except OSError as e: |
626 except OSError as e: |
627 E5MessageBox.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(fname, str(e))) |
743 |
743 |
744 @param exitCode exit code of the process (integer) |
744 @param exitCode exit code of the process (integer) |
745 @param exitStatus exit status of the process (QProcess.ExitStatus) |
745 @param exitStatus exit status of the process (QProcess.ExitStatus) |
746 """ |
746 """ |
747 self.compileRunning = False |
747 self.compileRunning = False |
748 e5App().getObject("ViewManager").enableEditorsCheckFocusIn(True) |
748 ericApp().getObject("ViewManager").enableEditorsCheckFocusIn(True) |
749 ui = e5App().getObject("UserInterface") |
749 ui = ericApp().getObject("UserInterface") |
750 if ( |
750 if ( |
751 exitStatus == QProcess.ExitStatus.NormalExit and |
751 exitStatus == QProcess.ExitStatus.NormalExit and |
752 exitCode == 0 and |
752 exitCode == 0 and |
753 self.buf |
753 self.buf |
754 ): |
754 ): |
855 self.compileProc.setWorkingDirectory(self.project.getProjectPath()) |
855 self.compileProc.setWorkingDirectory(self.project.getProjectPath()) |
856 self.compileProc.start(uicompiler, args) |
856 self.compileProc.start(uicompiler, args) |
857 procStarted = self.compileProc.waitForStarted(5000) |
857 procStarted = self.compileProc.waitForStarted(5000) |
858 if procStarted: |
858 if procStarted: |
859 self.compileRunning = True |
859 self.compileRunning = True |
860 e5App().getObject("ViewManager").enableEditorsCheckFocusIn(False) |
860 ericApp().getObject("ViewManager").enableEditorsCheckFocusIn(False) |
861 return self.compileProc |
861 return self.compileProc |
862 else: |
862 else: |
863 self.compileRunning = False |
863 self.compileRunning = False |
864 if progress is not None: |
864 if progress is not None: |
865 progress.cancel() |
865 progress.cancel() |
866 E5MessageBox.critical( |
866 EricMessageBox.critical( |
867 self, |
867 self, |
868 self.tr('Process Generation Error'), |
868 self.tr('Process Generation Error'), |
869 self.tr( |
869 self.tr( |
870 'Could not start {0}.<br>' |
870 'Could not start {0}.<br>' |
871 'Ensure that it is in the search path.' |
871 'Ensure that it is in the search path.' |
915 """ |
915 """ |
916 if self.hooks["compileAllForms"] is not None: |
916 if self.hooks["compileAllForms"] is not None: |
917 self.hooks["compileAllForms"](self.project.pdata["FORMS"]) |
917 self.hooks["compileAllForms"](self.project.pdata["FORMS"]) |
918 else: |
918 else: |
919 numForms = len(self.project.pdata["FORMS"]) |
919 numForms = len(self.project.pdata["FORMS"]) |
920 progress = E5ProgressDialog( |
920 progress = EricProgressDialog( |
921 self.tr("Compiling forms..."), |
921 self.tr("Compiling forms..."), |
922 self.tr("Abort"), 0, numForms, |
922 self.tr("Abort"), 0, numForms, |
923 self.tr("%v/%m Forms"), self) |
923 self.tr("%v/%m Forms"), self) |
924 progress.setModal(True) |
924 progress.setModal(True) |
925 progress.setMinimumDuration(0) |
925 progress.setMinimumDuration(0) |
950 |
950 |
951 if self.hooks["compileSelectedForms"] is not None: |
951 if self.hooks["compileSelectedForms"] is not None: |
952 self.hooks["compileSelectedForms"](files) |
952 self.hooks["compileSelectedForms"](files) |
953 else: |
953 else: |
954 numForms = len(files) |
954 numForms = len(files) |
955 progress = E5ProgressDialog( |
955 progress = EricProgressDialog( |
956 self.tr("Compiling forms..."), |
956 self.tr("Compiling forms..."), |
957 self.tr("Abort"), 0, numForms, |
957 self.tr("Abort"), 0, numForms, |
958 self.tr("%v/%m Forms"), self) |
958 self.tr("%v/%m Forms"), self) |
959 progress.setModal(True) |
959 progress.setModal(True) |
960 progress.setMinimumDuration(0) |
960 progress.setMinimumDuration(0) |
986 "PyQt5", "PyQt6", "E7Plugin", "PySide2", "PySide6" |
986 "PyQt5", "PyQt6", "E7Plugin", "PySide2", "PySide6" |
987 ]: |
987 ]: |
988 # ignore the request for non Qt GUI projects |
988 # ignore the request for non Qt GUI projects |
989 return |
989 return |
990 |
990 |
991 progress = E5ProgressDialog( |
991 progress = EricProgressDialog( |
992 self.tr("Determining changed forms..."), |
992 self.tr("Determining changed forms..."), |
993 self.tr("Abort"), 0, 100, self.tr("%v/%m Forms")) |
993 self.tr("Abort"), 0, 100, self.tr("%v/%m Forms")) |
994 progress.setMinimumDuration(0) |
994 progress.setMinimumDuration(0) |
995 progress.setWindowTitle(self.tr("Forms")) |
995 progress.setWindowTitle(self.tr("Forms")) |
996 |
996 |