Project/CreateDialogCodeDialog.py

changeset 537
72b32daeb8d6
parent 535
4b00d7336e19
child 564
b3d966393ba9
equal deleted inserted replaced
536:6d8d39753c82 537:72b32daeb8d6
12 from PyQt4.QtCore import * 12 from PyQt4.QtCore import *
13 from PyQt4.QtGui import * 13 from PyQt4.QtGui import *
14 from PyQt4 import uic 14 from PyQt4 import uic
15 15
16 from E5Gui.E5Application import e5App 16 from E5Gui.E5Application import e5App
17 from E5Gui import E5MessageBox
17 18
18 from .NewDialogClassDialog import NewDialogClassDialog 19 from .NewDialogClassDialog import NewDialogClassDialog
19 from .Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog 20 from .Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog
20 21
21 from Utilities import ModuleParser 22 from Utilities import ModuleParser
83 classesList.sort() 84 classesList.sort()
84 self.classNameCombo.addItems(classesList) 85 self.classNameCombo.addItems(classesList)
85 86
86 if os.path.exists(self.srcFile) and self.classNameCombo.count() == 0: 87 if os.path.exists(self.srcFile) and self.classNameCombo.count() == 0:
87 self.__initError = True 88 self.__initError = True
88 QMessageBox.critical(None, 89 E5MessageBox.critical(self,
89 self.trUtf8("Create Dialog Code"), 90 self.trUtf8("Create Dialog Code"),
90 self.trUtf8("""The file <b>{0}</b> exists but does not contain""" 91 self.trUtf8("""The file <b>{0}</b> exists but does not contain"""
91 """ any classes.""").format(self.srcFile)) 92 """ any classes.""").format(self.srcFile))
92 93
93 self.okButton.setEnabled(self.classNameCombo.count() > 0) 94 self.okButton.setEnabled(self.classNameCombo.count() > 0)
110 """ 111 """
111 try: 112 try:
112 dlg = uic.loadUi(self.formFile) 113 dlg = uic.loadUi(self.formFile)
113 return dlg.objectName() 114 return dlg.objectName()
114 except AttributeError as err: 115 except AttributeError as err:
115 QMessageBox.critical(self, 116 E5MessageBox.critical(self,
116 self.trUtf8("uic error"), 117 self.trUtf8("uic error"),
117 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" 118 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>"""
118 """<p>{1}</p>""").format(self.formFile, str(err))) 119 """<p>{1}</p>""").format(self.formFile, str(err)))
119 return "" 120 return ""
120 121
126 """ 127 """
127 try: 128 try:
128 dlg = uic.loadUi(self.formFile) 129 dlg = uic.loadUi(self.formFile)
129 return dlg.metaObject().className() 130 return dlg.metaObject().className()
130 except AttributeError as err: 131 except AttributeError as err:
131 QMessageBox.critical(self, 132 E5MessageBox.critical(self,
132 self.trUtf8("uic error"), 133 self.trUtf8("uic error"),
133 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" 134 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>"""
134 """<p>{1}</p>""").format(self.formFile, str(err))) 135 """<p>{1}</p>""").format(self.formFile, str(err)))
135 return "" 136 return ""
136 137
255 ) 256 )
256 itm2.setCheckState(Qt.Unchecked) 257 itm2.setCheckState(Qt.Unchecked)
257 258
258 self.slotsView.sortByColumn(0, Qt.AscendingOrder) 259 self.slotsView.sortByColumn(0, Qt.AscendingOrder)
259 except (AttributeError, ImportError) as err: 260 except (AttributeError, ImportError) as err:
260 QMessageBox.critical(self, 261 E5MessageBox.critical(self,
261 self.trUtf8("uic error"), 262 self.trUtf8("uic error"),
262 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" 263 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>"""
263 """<p>{1}</p>""").format(self.formFile, str(err))) 264 """<p>{1}</p>""").format(self.formFile, str(err)))
264 265
265 def __generateCode(self): 266 def __generateCode(self):
297 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl.py.tmpl") 298 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl.py.tmpl")
298 tmplFile = open(tmplName, 'r', encoding = "utf-8") 299 tmplFile = open(tmplName, 'r', encoding = "utf-8")
299 template = tmplFile.read() 300 template = tmplFile.read()
300 tmplFile.close() 301 tmplFile.close()
301 except IOError as why: 302 except IOError as why:
302 QMessageBox.critical(self, 303 E5MessageBox.critical(self,
303 self.trUtf8("Code Generation"), 304 self.trUtf8("Code Generation"),
304 self.trUtf8("""<p>Could not open the code template file "{0}".</p>""" 305 self.trUtf8("""<p>Could not open the code template file "{0}".</p>"""
305 """<p>Reason: {1}</p>""")\ 306 """<p>Reason: {1}</p>""")\
306 .format(tmplName, str(why))) 307 .format(tmplName, str(why)))
307 return 308 return
330 sourceImpl = srcFile.readlines() 331 sourceImpl = srcFile.readlines()
331 srcFile.close() 332 srcFile.close()
332 if not sourceImpl[-1].endswith("\n"): 333 if not sourceImpl[-1].endswith("\n"):
333 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n") 334 sourceImpl[-1] = "{0}{1}".format(sourceImpl[-1], "\n")
334 except IOError as why: 335 except IOError as why:
335 QMessageBox.critical(self, 336 E5MessageBox.critical(self,
336 self.trUtf8("Code Generation"), 337 self.trUtf8("Code Generation"),
337 self.trUtf8("""<p>Could not open the source file "{0}".</p>""" 338 self.trUtf8("""<p>Could not open the source file "{0}".</p>"""
338 """<p>Reason: {1}</p>""")\ 339 """<p>Reason: {1}</p>""")\
339 .format(self.srcFile, str(why))) 340 .format(self.srcFile, str(why)))
340 return 341 return
389 srcFile = open(self.filenameEdit.text(), 'w', encoding = "utf-8", 390 srcFile = open(self.filenameEdit.text(), 'w', encoding = "utf-8",
390 newline = newline) 391 newline = newline)
391 srcFile.write("".join(sourceImpl)) 392 srcFile.write("".join(sourceImpl))
392 srcFile.close() 393 srcFile.close()
393 except IOError as why: 394 except IOError as why:
394 QMessageBox.critical(self, 395 E5MessageBox.critical(self,
395 self.trUtf8("Code Generation"), 396 self.trUtf8("Code Generation"),
396 self.trUtf8("""<p>Could not write the source file "{0}".</p>""" 397 self.trUtf8("""<p>Could not write the source file "{0}".</p>"""
397 """<p>Reason: {1}</p>""")\ 398 """<p>Reason: {1}</p>""")\
398 .format(self.filenameEdit.text(), str(why))) 399 .format(self.filenameEdit.text(), str(why)))
399 return 400 return

eric ide

mercurial