18 ) |
18 ) |
19 from PyQt6.QtGui import QStandardItemModel, QStandardItem, QBrush, QColor |
19 from PyQt6.QtGui import QStandardItemModel, QStandardItem, QBrush, QColor |
20 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
20 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
21 |
21 |
22 |
22 |
23 from E5Gui.E5Application import e5App |
23 from E5Gui.EricApplication import ericApp |
24 from E5Gui import E5MessageBox |
24 from E5Gui import EricMessageBox |
25 |
25 |
26 from .Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog |
26 from .Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog |
27 from .NewDialogClassDialog import NewDialogClassDialog |
27 from .NewDialogClassDialog import NewDialogClassDialog |
28 |
28 |
29 from eric7config import getConfig |
29 from eric7config import getConfig |
89 packagesRoot) |
89 packagesRoot) |
90 else: |
90 else: |
91 self.packagesPath = self.project.getProjectPath() |
91 self.packagesPath = self.project.getProjectPath() |
92 |
92 |
93 if os.path.exists(self.srcFile): |
93 if os.path.exists(self.srcFile): |
94 vm = e5App().getObject("ViewManager") |
94 vm = ericApp().getObject("ViewManager") |
95 ed = vm.getOpenEditor(self.srcFile) |
95 ed = vm.getOpenEditor(self.srcFile) |
96 if ed and not vm.checkDirty(ed): |
96 if ed and not vm.checkDirty(ed): |
97 self.__initError = True |
97 self.__initError = True |
98 return |
98 return |
99 |
99 |
127 os.path.exists(self.srcFile) and |
127 os.path.exists(self.srcFile) and |
128 self.__module is not None and |
128 self.__module is not None and |
129 self.classNameCombo.count() == 0 |
129 self.classNameCombo.count() == 0 |
130 ): |
130 ): |
131 self.__initError = True |
131 self.__initError = True |
132 E5MessageBox.critical( |
132 EricMessageBox.critical( |
133 self, |
133 self, |
134 self.tr("Create Dialog Code"), |
134 self.tr("Create Dialog Code"), |
135 self.tr( |
135 self.tr( |
136 """The file <b>{0}</b> exists but does not contain""" |
136 """The file <b>{0}</b> exists but does not contain""" |
137 """ any classes.""").format(self.srcFile)) |
137 """ any classes.""").format(self.srcFile)) |
156 @param command uic command to be run |
156 @param command uic command to be run |
157 @type str |
157 @type str |
158 @return tuple of process output and error flag |
158 @return tuple of process output and error flag |
159 @rtype tuple of (str, bool) |
159 @rtype tuple of (str, bool) |
160 """ |
160 """ |
161 venvManager = e5App().getObject("VirtualEnvManager") |
161 venvManager = ericApp().getObject("VirtualEnvManager") |
162 projectType = self.project.getProjectType() |
162 projectType = self.project.getProjectType() |
163 |
163 |
164 venvName = self.project.getDebugProperty("VIRTUALENV") |
164 venvName = self.project.getDebugProperty("VIRTUALENV") |
165 if not venvName: |
165 if not venvName: |
166 # no project specific environment, try a type specific one |
166 # no project specific environment, try a type specific one |
208 outText = str(output, "utf-8", "replace") |
208 outText = str(output, "utf-8", "replace") |
209 if proc.exitCode() == 0: |
209 if proc.exitCode() == 0: |
210 ok = True |
210 ok = True |
211 uicText = outText.strip() |
211 uicText = outText.strip() |
212 else: |
212 else: |
213 E5MessageBox.critical( |
213 EricMessageBox.critical( |
214 self, |
214 self, |
215 self.tr("uic error"), |
215 self.tr("uic error"), |
216 self.tr( |
216 self.tr( |
217 """<p>There was an error loading the form <b>{0}</b>""" |
217 """<p>There was an error loading the form <b>{0}</b>""" |
218 """.</p><p>{1}</p>""").format( |
218 """.</p><p>{1}</p>""").format( |
219 self.formFile, outText) |
219 self.formFile, outText) |
220 ) |
220 ) |
221 else: |
221 else: |
222 E5MessageBox.critical( |
222 EricMessageBox.critical( |
223 self, |
223 self, |
224 self.tr("uic error"), |
224 self.tr("uic error"), |
225 self.tr( |
225 self.tr( |
226 """<p>The project specific Python interpreter <b>{0}</b>""" |
226 """<p>The project specific Python interpreter <b>{0}</b>""" |
227 """ could not be started or did not finish within 30""" |
227 """ could not be started or did not finish within 30""" |
340 (methodDict["methods"][0] in signatureList or |
340 (methodDict["methods"][0] in signatureList or |
341 methodDict["methods"][1] in signatureList) |
341 methodDict["methods"][1] in signatureList) |
342 ): |
342 ): |
343 itm2.setFlags(Qt.ItemFlag.ItemIsEnabled) |
343 itm2.setFlags(Qt.ItemFlag.ItemIsEnabled) |
344 itm2.setCheckState(Qt.CheckState.Checked) |
344 itm2.setCheckState(Qt.CheckState.Checked) |
345 if e5App().usesDarkPalette(): |
345 if ericApp().usesDarkPalette(): |
346 itm2.setForeground(QBrush(QColor("#75bfff"))) |
346 itm2.setForeground(QBrush(QColor("#75bfff"))) |
347 else: |
347 else: |
348 itm2.setForeground(QBrush(Qt.GlobalColor.blue)) |
348 itm2.setForeground(QBrush(Qt.GlobalColor.blue)) |
349 continue |
349 continue |
350 |
350 |
385 def __generatePythonCode(self): |
385 def __generatePythonCode(self): |
386 """ |
386 """ |
387 Private slot to generate Python code as requested by the user. |
387 Private slot to generate Python code as requested by the user. |
388 """ |
388 """ |
389 if self.project.getProjectLanguage() != "Python3": |
389 if self.project.getProjectLanguage() != "Python3": |
390 E5MessageBox.critical( |
390 EricMessageBox.critical( |
391 self, |
391 self, |
392 self.tr("Code Generation"), |
392 self.tr("Code Generation"), |
393 self.tr( |
393 self.tr( |
394 """<p>Code generation for project language""" |
394 """<p>Code generation for project language""" |
395 """ "{0}" is not supported.</p>""") |
395 """ "{0}" is not supported.</p>""") |
422 ]: |
422 ]: |
423 tmplName = os.path.join( |
423 tmplName = os.path.join( |
424 getConfig('ericCodeTemplatesDir'), |
424 getConfig('ericCodeTemplatesDir'), |
425 "impl_pyqt6.py.tmpl") |
425 "impl_pyqt6.py.tmpl") |
426 else: |
426 else: |
427 E5MessageBox.critical( |
427 EricMessageBox.critical( |
428 self, |
428 self, |
429 self.tr("Code Generation"), |
429 self.tr("Code Generation"), |
430 self.tr( |
430 self.tr( |
431 """<p>No code template file available for""" |
431 """<p>No code template file available for""" |
432 """ project type "{0}".</p>""") |
432 """ project type "{0}".</p>""") |
433 .format(self.project.getProjectType())) |
433 .format(self.project.getProjectType())) |
434 return |
434 return |
435 with open(tmplName, 'r', encoding="utf-8") as tmplFile: |
435 with open(tmplName, 'r', encoding="utf-8") as tmplFile: |
436 template = tmplFile.read() |
436 template = tmplFile.read() |
437 except OSError as why: |
437 except OSError as why: |
438 E5MessageBox.critical( |
438 EricMessageBox.critical( |
439 self, |
439 self, |
440 self.tr("Code Generation"), |
440 self.tr("Code Generation"), |
441 self.tr( |
441 self.tr( |
442 """<p>Could not open the code template file""" |
442 """<p>Could not open the code template file""" |
443 """ "{0}".</p><p>Reason: {1}</p>""") |
443 """ "{0}".</p><p>Reason: {1}</p>""") |
470 with open(self.srcFile, 'r', encoding="utf-8") as srcFile: |
470 with open(self.srcFile, 'r', encoding="utf-8") as srcFile: |
471 sourceImpl = srcFile.readlines() |
471 sourceImpl = srcFile.readlines() |
472 if not sourceImpl[-1].endswith("\n"): |
472 if not sourceImpl[-1].endswith("\n"): |
473 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n") |
473 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n") |
474 except OSError as why: |
474 except OSError as why: |
475 E5MessageBox.critical( |
475 EricMessageBox.critical( |
476 self, |
476 self, |
477 self.tr("Code Generation"), |
477 self.tr("Code Generation"), |
478 self.tr( |
478 self.tr( |
479 """<p>Could not open the source file "{0}".</p>""" |
479 """<p>Could not open the source file "{0}".</p>""" |
480 """<p>Reason: {1}</p>""") |
480 """<p>Reason: {1}</p>""") |
562 fn = self.filenameEdit.text() |
562 fn = self.filenameEdit.text() |
563 try: |
563 try: |
564 with open(fn, 'w', encoding="utf-8", newline=newline) as srcFile: |
564 with open(fn, 'w', encoding="utf-8", newline=newline) as srcFile: |
565 srcFile.write("".join(sourceImpl)) |
565 srcFile.write("".join(sourceImpl)) |
566 except OSError as why: |
566 except OSError as why: |
567 E5MessageBox.critical( |
567 EricMessageBox.critical( |
568 self, |
568 self, |
569 self.tr("Code Generation"), |
569 self.tr("Code Generation"), |
570 self.tr("""<p>Could not write the source file "{0}".</p>""" |
570 self.tr("""<p>Could not write the source file "{0}".</p>""" |
571 """<p>Reason: {1}</p>""") |
571 """<p>Reason: {1}</p>""") |
572 .format(fn, str(why))) |
572 .format(fn, str(why))) |