Project/CreateDialogCodeDialog.py

changeset 3020
542e97d4ecb3
parent 2995
63d874899b8b
child 3030
4a0a82ddd9d2
equal deleted inserted replaced
3019:7912530a33e2 3020:542e97d4ecb3
110 110
111 if os.path.exists(self.srcFile) and \ 111 if os.path.exists(self.srcFile) and \
112 self.__module is not None and \ 112 self.__module is not None and \
113 self.classNameCombo.count() == 0: 113 self.classNameCombo.count() == 0:
114 self.__initError = True 114 self.__initError = True
115 E5MessageBox.critical(self, 115 E5MessageBox.critical(
116 self,
116 self.trUtf8("Create Dialog Code"), 117 self.trUtf8("Create Dialog Code"),
117 self.trUtf8( 118 self.trUtf8(
118 """The file <b>{0}</b> exists but does not contain""" 119 """The file <b>{0}</b> exists but does not contain"""
119 """ any classes.""").format(self.srcFile)) 120 """ any classes.""").format(self.srcFile))
120 121
138 """ 139 """
139 try: 140 try:
140 dlg = uic.loadUi(self.formFile) 141 dlg = uic.loadUi(self.formFile)
141 return dlg.objectName() 142 return dlg.objectName()
142 except (AttributeError, ImportError) as err: 143 except (AttributeError, ImportError) as err:
143 E5MessageBox.critical(self, 144 E5MessageBox.critical(
145 self,
144 self.trUtf8("uic error"), 146 self.trUtf8("uic error"),
145 self.trUtf8( 147 self.trUtf8(
146 """<p>There was an error loading the form <b>{0}</b>""" 148 """<p>There was an error loading the form <b>{0}</b>"""
147 """.</p><p>{1}</p>""").format(self.formFile, str(err))) 149 """.</p><p>{1}</p>""").format(self.formFile, str(err)))
148 return "" 150 return ""
155 """ 157 """
156 try: 158 try:
157 dlg = uic.loadUi(self.formFile) 159 dlg = uic.loadUi(self.formFile)
158 return dlg.metaObject().className() 160 return dlg.metaObject().className()
159 except (AttributeError, ImportError) as err: 161 except (AttributeError, ImportError) as err:
160 E5MessageBox.critical(self, 162 E5MessageBox.critical(
163 self,
161 self.trUtf8("uic error"), 164 self.trUtf8("uic error"),
162 self.trUtf8( 165 self.trUtf8(
163 """<p>There was an error loading the form <b>{0}</b>""" 166 """<p>There was an error loading the form <b>{0}</b>"""
164 """.</p><p>{1}</p>""").format(self.formFile, str(err))) 167 """.</p><p>{1}</p>""").format(self.formFile, str(err)))
165 return "" 168 return ""
318 ) 321 )
319 itm2.setCheckState(Qt.Unchecked) 322 itm2.setCheckState(Qt.Unchecked)
320 323
321 self.slotsView.sortByColumn(0, Qt.AscendingOrder) 324 self.slotsView.sortByColumn(0, Qt.AscendingOrder)
322 except (AttributeError, ImportError) as err: 325 except (AttributeError, ImportError) as err:
323 E5MessageBox.critical(self, 326 E5MessageBox.critical(
327 self,
324 self.trUtf8("uic error"), 328 self.trUtf8("uic error"),
325 self.trUtf8( 329 self.trUtf8(
326 """<p>There was an error loading the form <b>{0}</b>""" 330 """<p>There was an error loading the form <b>{0}</b>"""
327 """.</p><p>{1}</p>""").format(self.formFile, str(err))) 331 """.</p><p>{1}</p>""").format(self.formFile, str(err)))
328 332
386 "impl_pyqt.py.tmpl") 390 "impl_pyqt.py.tmpl")
387 tmplFile = open(tmplName, 'r', encoding="utf-8") 391 tmplFile = open(tmplName, 'r', encoding="utf-8")
388 template = tmplFile.read() 392 template = tmplFile.read()
389 tmplFile.close() 393 tmplFile.close()
390 except IOError as why: 394 except IOError as why:
391 E5MessageBox.critical(self, 395 E5MessageBox.critical(
396 self,
392 self.trUtf8("Code Generation"), 397 self.trUtf8("Code Generation"),
393 self.trUtf8( 398 self.trUtf8(
394 """<p>Could not open the code template file""" 399 """<p>Could not open the code template file"""
395 """ "{0}".</p><p>Reason: {1}</p>""")\ 400 """ "{0}".</p><p>Reason: {1}</p>""")\
396 .format(tmplName, str(why))) 401 .format(tmplName, str(why)))
421 sourceImpl = srcFile.readlines() 426 sourceImpl = srcFile.readlines()
422 srcFile.close() 427 srcFile.close()
423 if not sourceImpl[-1].endswith("\n"): 428 if not sourceImpl[-1].endswith("\n"):
424 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n") 429 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n")
425 except IOError as why: 430 except IOError as why:
426 E5MessageBox.critical(self, 431 E5MessageBox.critical(
432 self,
427 self.trUtf8("Code Generation"), 433 self.trUtf8("Code Generation"),
428 self.trUtf8( 434 self.trUtf8(
429 """<p>Could not open the source file "{0}".</p>""" 435 """<p>Could not open the source file "{0}".</p>"""
430 """<p>Reason: {1}</p>""")\ 436 """<p>Reason: {1}</p>""")\
431 .format(self.srcFile, str(why))) 437 .format(self.srcFile, str(why)))
499 srcFile = open(self.filenameEdit.text(), 'w', encoding="utf-8", 505 srcFile = open(self.filenameEdit.text(), 'w', encoding="utf-8",
500 newline=newline) 506 newline=newline)
501 srcFile.write("".join(sourceImpl)) 507 srcFile.write("".join(sourceImpl))
502 srcFile.close() 508 srcFile.close()
503 except IOError as why: 509 except IOError as why:
504 E5MessageBox.critical(self, 510 E5MessageBox.critical(
511 self,
505 self.trUtf8("Code Generation"), 512 self.trUtf8("Code Generation"),
506 self.trUtf8("""<p>Could not write the source file "{0}".</p>""" 513 self.trUtf8("""<p>Could not write the source file "{0}".</p>"""
507 """<p>Reason: {1}</p>""")\ 514 """<p>Reason: {1}</p>""")\
508 .format(self.filenameEdit.text(), str(why))) 515 .format(self.filenameEdit.text(), str(why)))
509 return 516 return

eric ide

mercurial