eric6/Project/CreateDialogCodeDialog.py

changeset 7836
2f0d208b8137
parent 7785
9978016560ec
child 7907
7991ea245c20
child 7924
8a96736d465e
equal deleted inserted replaced
7835:0835ed67714b 7836:2f0d208b8137
421 """ project type "{0}".</p>""") 421 """ project type "{0}".</p>""")
422 .format(self.project.getProjectType())) 422 .format(self.project.getProjectType()))
423 return 423 return
424 with open(tmplName, 'r', encoding="utf-8") as tmplFile: 424 with open(tmplName, 'r', encoding="utf-8") as tmplFile:
425 template = tmplFile.read() 425 template = tmplFile.read()
426 except IOError as why: 426 except OSError as why:
427 E5MessageBox.critical( 427 E5MessageBox.critical(
428 self, 428 self,
429 self.tr("Code Generation"), 429 self.tr("Code Generation"),
430 self.tr( 430 self.tr(
431 """<p>Could not open the code template file""" 431 """<p>Could not open the code template file"""
458 try: 458 try:
459 with open(self.srcFile, 'r', encoding="utf-8") as srcFile: 459 with open(self.srcFile, 'r', encoding="utf-8") as srcFile:
460 sourceImpl = srcFile.readlines() 460 sourceImpl = srcFile.readlines()
461 if not sourceImpl[-1].endswith("\n"): 461 if not sourceImpl[-1].endswith("\n"):
462 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n") 462 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n")
463 except IOError as why: 463 except OSError as why:
464 E5MessageBox.critical( 464 E5MessageBox.critical(
465 self, 465 self,
466 self.tr("Code Generation"), 466 self.tr("Code Generation"),
467 self.tr( 467 self.tr(
468 """<p>Could not open the source file "{0}".</p>""" 468 """<p>Could not open the source file "{0}".</p>"""
551 newline = self.project.getEolString() 551 newline = self.project.getEolString()
552 fn = self.filenameEdit.text() 552 fn = self.filenameEdit.text()
553 try: 553 try:
554 with open(fn, 'w', encoding="utf-8", newline=newline) as srcFile: 554 with open(fn, 'w', encoding="utf-8", newline=newline) as srcFile:
555 srcFile.write("".join(sourceImpl)) 555 srcFile.write("".join(sourceImpl))
556 except IOError as why: 556 except OSError as why:
557 E5MessageBox.critical( 557 E5MessageBox.critical(
558 self, 558 self,
559 self.tr("Code Generation"), 559 self.tr("Code Generation"),
560 self.tr("""<p>Could not write the source file "{0}".</p>""" 560 self.tr("""<p>Could not write the source file "{0}".</p>"""
561 """<p>Reason: {1}</p>""") 561 """<p>Reason: {1}</p>""")

eric ide

mercurial