12 import shutil |
12 import shutil |
13 import fnmatch |
13 import fnmatch |
14 import functools |
14 import functools |
15 import contextlib |
15 import contextlib |
16 |
16 |
17 from PyQt6.QtCore import pyqtSignal, QProcess |
17 from PyQt6.QtCore import pyqtSignal, Qt, QProcess, QEventLoop |
|
18 from PyQt6.QtGui import QGuiApplication, QCursor |
18 from PyQt6.QtWidgets import QDialog, QMenu |
19 from PyQt6.QtWidgets import QDialog, QMenu |
|
20 |
|
21 from EricGui.EricOverrideCursor import EricOverridenCursor |
19 |
22 |
20 from EricWidgets import EricMessageBox |
23 from EricWidgets import EricMessageBox |
21 from EricWidgets.EricApplication import ericApp |
24 from EricWidgets.EricApplication import ericApp |
22 |
25 |
23 from .ProjectBrowserModel import ( |
26 from .ProjectBrowserModel import ( |
969 break |
972 break |
970 |
973 |
971 if not self.__pylupdateProcesses: |
974 if not self.__pylupdateProcesses: |
972 # all done |
975 # all done |
973 self.pylupdateProcRunning = False |
976 self.pylupdateProcRunning = False |
|
977 |
|
978 QGuiApplication.restoreOverrideCursor() |
|
979 QGuiApplication.processEvents( |
|
980 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) |
974 |
981 |
975 def __generateTSFile(self, noobsolete=False, generateAll=True): |
982 def __generateTSFile(self, noobsolete=False, generateAll=True): |
976 """ |
983 """ |
977 Private method used to run pylupdate5 / pylupdate6 / pyside2-lupdate / |
984 Private method used to run pylupdate5 / pylupdate6 / pyside2-lupdate / |
978 pyside6-lupdate to generate the .ts files. |
985 pyside6-lupdate to generate the .ts files. |
1013 # generate a minimal temporary project file suitable for pylupdate |
1020 # generate a minimal temporary project file suitable for pylupdate |
1014 self.__tmpProjects = [] |
1021 self.__tmpProjects = [] |
1015 if self.project.getProjectLanguage() in [ |
1022 if self.project.getProjectLanguage() in [ |
1016 "Python", "Python3" |
1023 "Python", "Python3" |
1017 ]: |
1024 ]: |
1018 if self.project.getProjectType() not in ["PyQt6", "PyQt6C"]: |
1025 if self.project.getProjectType() not in [ |
|
1026 "PyQt6", "PyQt6C", "E7Plugin" |
|
1027 ]: |
1019 ok = self.__writeTempProjectFile(langs, [".py"]) |
1028 ok = self.__writeTempProjectFile(langs, [".py"]) |
1020 if not ok: |
1029 if not ok: |
1021 return |
1030 return |
1022 else: |
1031 else: |
1023 return |
1032 return |
1034 'pyside6-lupdate', variant=6) |
1043 'pyside6-lupdate', variant=6) |
1035 else: |
1044 else: |
1036 return |
1045 return |
1037 |
1046 |
1038 self.__pylupdateProcesses = [] |
1047 self.__pylupdateProcesses = [] |
1039 if self.project.getProjectType() in ["PyQt6", "PyQt6C"]: |
1048 if self.project.getProjectType() in ["PyQt6", "PyQt6C", "E7Plugin"]: |
1040 if langs: |
1049 if langs: |
1041 langs = [self.project.getRelativePath(lang.fileName()) |
1050 langs = [self.project.getRelativePath(lang.fileName()) |
1042 for lang in langs if lang.fileName().endswith('.ts')] |
1051 for lang in langs if lang.fileName().endswith('.ts')] |
1043 else: |
1052 else: |
1044 try: |
1053 try: |
1054 EricMessageBox.warning( |
1063 EricMessageBox.warning( |
1055 self, |
1064 self, |
1056 self.tr("Translation file generation"), |
1065 self.tr("Translation file generation"), |
1057 self.tr("""No translation files (*.ts) selected.""")) |
1066 self.tr("""No translation files (*.ts) selected.""")) |
1058 return |
1067 return |
|
1068 |
|
1069 QGuiApplication.setOverrideCursor( |
|
1070 QCursor(Qt.CursorShape.WaitCursor)) |
|
1071 QGuiApplication.processEvents( |
|
1072 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) |
|
1073 |
1059 for lang in langs: |
1074 for lang in langs: |
1060 proc = QProcess() |
1075 proc = QProcess() |
1061 args = [] |
1076 args = [] |
1062 |
1077 |
1063 if noobsolete: |
1078 if noobsolete: |
1081 procStarted = proc.waitForStarted() |
1096 procStarted = proc.waitForStarted() |
1082 if procStarted: |
1097 if procStarted: |
1083 self.pylupdateProcRunning = True |
1098 self.pylupdateProcRunning = True |
1084 self.__pylupdateProcesses.append((proc, "")) |
1099 self.__pylupdateProcesses.append((proc, "")) |
1085 else: |
1100 else: |
1086 EricMessageBox.critical( |
1101 with EricOverridenCursor(): |
1087 self, |
1102 EricMessageBox.critical( |
1088 self.tr('Process Generation Error'), |
1103 self, |
1089 self.tr( |
1104 self.tr('Process Generation Error'), |
1090 'Could not start {0}.<br>' |
1105 self.tr( |
1091 'Ensure that it is in the search path.' |
1106 'Could not start {0}.<br>' |
1092 ).format(self.pylupdate)) |
1107 'Ensure that it is in the search path.' |
1093 else: |
1108 ).format(self.pylupdate)) |
|
1109 else: |
|
1110 QGuiApplication.setOverrideCursor( |
|
1111 QCursor(Qt.CursorShape.WaitCursor)) |
|
1112 QGuiApplication.processEvents( |
|
1113 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) |
|
1114 |
1094 for tempProjectFile in self.__tmpProjects[:]: |
1115 for tempProjectFile in self.__tmpProjects[:]: |
1095 proc = QProcess() |
1116 proc = QProcess() |
1096 args = [] |
1117 args = [] |
1097 |
1118 |
1098 if noobsolete: |
1119 if noobsolete: |
1117 procStarted = proc.waitForStarted() |
1138 procStarted = proc.waitForStarted() |
1118 if procStarted: |
1139 if procStarted: |
1119 self.pylupdateProcRunning = True |
1140 self.pylupdateProcRunning = True |
1120 self.__pylupdateProcesses.append((proc, tempProjectFile)) |
1141 self.__pylupdateProcesses.append((proc, tempProjectFile)) |
1121 else: |
1142 else: |
1122 EricMessageBox.critical( |
1143 with EricOverridenCursor(): |
1123 self, |
1144 EricMessageBox.critical( |
1124 self.tr('Process Generation Error'), |
1145 self, |
1125 self.tr( |
1146 self.tr('Process Generation Error'), |
1126 'Could not start {0}.<br>' |
1147 self.tr( |
1127 'Ensure that it is in the search path.' |
1148 'Could not start {0}.<br>' |
1128 ).format(self.pylupdate)) |
1149 'Ensure that it is in the search path.' |
|
1150 ).format(self.pylupdate)) |
1129 # cleanup |
1151 # cleanup |
1130 with contextlib.suppress(OSError): |
1152 with contextlib.suppress(OSError): |
1131 self.__tmpProjects.remove(tempProjectFile) |
1153 self.__tmpProjects.remove(tempProjectFile) |
1132 os.remove(tempProjectFile) |
1154 os.remove(tempProjectFile) |
|
1155 |
|
1156 if not self.__pylupdateProcesses: |
|
1157 # no processes could be started, revert override cursor |
|
1158 QGuiApplication.restoreOverrideCursor() |
|
1159 QGuiApplication.processEvents( |
|
1160 QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents) |
1133 |
1161 |
1134 def __generateAll(self): |
1162 def __generateAll(self): |
1135 """ |
1163 """ |
1136 Private method to generate all translation files (.ts) for Qt Linguist. |
1164 Private method to generate all translation files (.ts) for Qt Linguist. |
1137 |
1165 |