11 import contextlib |
11 import contextlib |
12 |
12 |
13 from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess |
13 from PyQt6.QtCore import QThread, QFileInfo, pyqtSignal, QProcess |
14 from PyQt6.QtWidgets import QDialog, QApplication, QMenu |
14 from PyQt6.QtWidgets import QDialog, QApplication, QMenu |
15 |
15 |
16 from E5Gui.E5Application import e5App |
16 from E5Gui.EricApplication import ericApp |
17 from E5Gui import E5MessageBox, E5FileDialog |
17 from E5Gui import EricMessageBox, EricFileDialog |
18 from E5Gui.E5ProgressDialog import E5ProgressDialog |
18 from E5Gui.EricProgressDialog import EricProgressDialog |
19 |
19 |
20 from .ProjectBrowserModel import ( |
20 from .ProjectBrowserModel import ( |
21 ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem, |
21 ProjectBrowserFileItem, ProjectBrowserSimpleDirectoryItem, |
22 ProjectBrowserDirectoryItem, ProjectBrowserResourceType |
22 ProjectBrowserDirectoryItem, ProjectBrowserResourceType |
23 ) |
23 ) |
463 path = os.path.join(self.project.ppath, itm.data(0)) |
463 path = os.path.join(self.project.ppath, itm.data(0)) |
464 |
464 |
465 if self.hooks["newResource"] is not None: |
465 if self.hooks["newResource"] is not None: |
466 self.hooks["newResource"](path) |
466 self.hooks["newResource"](path) |
467 else: |
467 else: |
468 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( |
468 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( |
469 self, |
469 self, |
470 self.tr("New Resource"), |
470 self.tr("New Resource"), |
471 path, |
471 path, |
472 self.tr("Qt Resource Files (*.qrc)"), |
472 self.tr("Qt Resource Files (*.qrc)"), |
473 "", |
473 "", |
474 E5FileDialog.DontConfirmOverwrite) |
474 EricFileDialog.DontConfirmOverwrite) |
475 |
475 |
476 if not fname: |
476 if not fname: |
477 # user aborted or didn't enter a filename |
477 # user aborted or didn't enter a filename |
478 return |
478 return |
479 |
479 |
482 ex = selectedFilter.split("(*")[1].split(")")[0] |
482 ex = selectedFilter.split("(*")[1].split(")")[0] |
483 if ex: |
483 if ex: |
484 fname += ex |
484 fname += ex |
485 |
485 |
486 if os.path.exists(fname): |
486 if os.path.exists(fname): |
487 res = E5MessageBox.yesNo( |
487 res = EricMessageBox.yesNo( |
488 self, |
488 self, |
489 self.tr("New Resource"), |
489 self.tr("New Resource"), |
490 self.tr("The file already exists! Overwrite it?"), |
490 self.tr("The file already exists! Overwrite it?"), |
491 icon=E5MessageBox.Warning) |
491 icon=EricMessageBox.Warning) |
492 if not res: |
492 if not res: |
493 # user selected to not overwrite |
493 # user selected to not overwrite |
494 return |
494 return |
495 |
495 |
496 try: |
496 try: |
502 rcfile.write('<RCC version="1.0">\n') |
502 rcfile.write('<RCC version="1.0">\n') |
503 rcfile.write('<qresource>\n') |
503 rcfile.write('<qresource>\n') |
504 rcfile.write('</qresource>\n') |
504 rcfile.write('</qresource>\n') |
505 rcfile.write('</RCC>\n') |
505 rcfile.write('</RCC>\n') |
506 except OSError as e: |
506 except OSError as e: |
507 E5MessageBox.critical( |
507 EricMessageBox.critical( |
508 self, |
508 self, |
509 self.tr("New Resource"), |
509 self.tr("New Resource"), |
510 self.tr( |
510 self.tr( |
511 "<p>The new resource file <b>{0}</b> could not" |
511 "<p>The new resource file <b>{0}</b> could not" |
512 " be created.<br>Problem: {1}</p>") |
512 " be created.<br>Problem: {1}</p>") |
588 |
588 |
589 @param exitCode exit code of the process (integer) |
589 @param exitCode exit code of the process (integer) |
590 @param exitStatus exit status of the process (QProcess.ExitStatus) |
590 @param exitStatus exit status of the process (QProcess.ExitStatus) |
591 """ |
591 """ |
592 self.compileRunning = False |
592 self.compileRunning = False |
593 e5App().getObject("ViewManager").enableEditorsCheckFocusIn(True) |
593 ericApp().getObject("ViewManager").enableEditorsCheckFocusIn(True) |
594 ui = e5App().getObject("UserInterface") |
594 ui = ericApp().getObject("UserInterface") |
595 if ( |
595 if ( |
596 exitStatus == QProcess.ExitStatus.NormalExit and |
596 exitStatus == QProcess.ExitStatus.NormalExit and |
597 exitCode == 0 and |
597 exitCode == 0 and |
598 self.buf |
598 self.buf |
599 ): |
599 ): |
611 self.tr("Resource Compilation"), |
611 self.tr("Resource Compilation"), |
612 self.tr("The compilation of the resource file" |
612 self.tr("The compilation of the resource file" |
613 " was successful.")) |
613 " was successful.")) |
614 except OSError as msg: |
614 except OSError as msg: |
615 if not self.noDialog: |
615 if not self.noDialog: |
616 E5MessageBox.information( |
616 EricMessageBox.information( |
617 self, |
617 self, |
618 self.tr("Resource Compilation"), |
618 self.tr("Resource Compilation"), |
619 self.tr( |
619 self.tr( |
620 "<p>The compilation of the resource file" |
620 "<p>The compilation of the resource file" |
621 " failed.</p><p>Reason: {0}</p>").format(str(msg))) |
621 " failed.</p><p>Reason: {0}</p>").format(str(msg))) |
699 self.noDialog = noDialog |
699 self.noDialog = noDialog |
700 self.compileProc.start(rcc, args) |
700 self.compileProc.start(rcc, args) |
701 procStarted = self.compileProc.waitForStarted(5000) |
701 procStarted = self.compileProc.waitForStarted(5000) |
702 if procStarted: |
702 if procStarted: |
703 self.compileRunning = True |
703 self.compileRunning = True |
704 e5App().getObject("ViewManager").enableEditorsCheckFocusIn(False) |
704 ericApp().getObject("ViewManager").enableEditorsCheckFocusIn(False) |
705 return self.compileProc |
705 return self.compileProc |
706 else: |
706 else: |
707 self.compileRunning = False |
707 self.compileRunning = False |
708 if progress is not None: |
708 if progress is not None: |
709 progress.cancel() |
709 progress.cancel() |
710 E5MessageBox.critical( |
710 EricMessageBox.critical( |
711 self, |
711 self, |
712 self.tr('Process Generation Error'), |
712 self.tr('Process Generation Error'), |
713 self.tr( |
713 self.tr( |
714 'Could not start {0}.<br>' |
714 'Could not start {0}.<br>' |
715 'Ensure that it is in the search path.' |
715 'Ensure that it is in the search path.' |
734 """ |
734 """ |
735 if self.hooks["compileAllResources"] is not None: |
735 if self.hooks["compileAllResources"] is not None: |
736 self.hooks["compileAllResources"](self.project.pdata["RESOURCES"]) |
736 self.hooks["compileAllResources"](self.project.pdata["RESOURCES"]) |
737 else: |
737 else: |
738 numResources = len(self.project.pdata["RESOURCES"]) |
738 numResources = len(self.project.pdata["RESOURCES"]) |
739 progress = E5ProgressDialog( |
739 progress = EricProgressDialog( |
740 self.tr("Compiling resources..."), |
740 self.tr("Compiling resources..."), |
741 self.tr("Abort"), 0, numResources, |
741 self.tr("Abort"), 0, numResources, |
742 self.tr("%v/%m Resources"), self) |
742 self.tr("%v/%m Resources"), self) |
743 progress.setModal(True) |
743 progress.setModal(True) |
744 progress.setMinimumDuration(0) |
744 progress.setMinimumDuration(0) |
768 |
768 |
769 if self.hooks["compileSelectedResources"] is not None: |
769 if self.hooks["compileSelectedResources"] is not None: |
770 self.hooks["compileSelectedResources"](files) |
770 self.hooks["compileSelectedResources"](files) |
771 else: |
771 else: |
772 numResources = len(files) |
772 numResources = len(files) |
773 progress = E5ProgressDialog( |
773 progress = EricProgressDialog( |
774 self.tr("Compiling resources..."), |
774 self.tr("Compiling resources..."), |
775 self.tr("Abort"), 0, numResources, |
775 self.tr("Abort"), 0, numResources, |
776 self.tr("%v/%m Resources"), self) |
776 self.tr("%v/%m Resources"), self) |
777 progress.setModal(True) |
777 progress.setModal(True) |
778 progress.setMinimumDuration(0) |
778 progress.setMinimumDuration(0) |
839 """ |
839 """ |
840 if self.hooks["compileChangedResources"] is not None: |
840 if self.hooks["compileChangedResources"] is not None: |
841 self.hooks["compileChangedResources"]( |
841 self.hooks["compileChangedResources"]( |
842 self.project.pdata["RESOURCES"]) |
842 self.project.pdata["RESOURCES"]) |
843 else: |
843 else: |
844 progress = E5ProgressDialog( |
844 progress = EricProgressDialog( |
845 self.tr("Determining changed resources..."), |
845 self.tr("Determining changed resources..."), |
846 self.tr("Abort"), 0, 100, self.tr("%v/%m Resources")) |
846 self.tr("Abort"), 0, 100, self.tr("%v/%m Resources")) |
847 progress.setMinimumDuration(0) |
847 progress.setMinimumDuration(0) |
848 progress.setWindowTitle(self.tr("Resources")) |
848 progress.setWindowTitle(self.tr("Resources")) |
849 |
849 |