14 from PyQt4.QtGui import * |
14 from PyQt4.QtGui import * |
15 from PyQt4 import uic |
15 from PyQt4 import uic |
16 |
16 |
17 from E4Gui.E4Application import e4App |
17 from E4Gui.E4Application import e4App |
18 |
18 |
19 from NewDialogClassDialog import NewDialogClassDialog |
19 from .NewDialogClassDialog import NewDialogClassDialog |
20 from Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog |
20 from .Ui_CreateDialogCodeDialog import Ui_CreateDialogCodeDialog |
21 |
21 |
22 from Utilities import ModuleParser |
22 from Utilities import ModuleParser |
23 |
23 |
24 import UI.PixmapCache |
24 import UI.PixmapCache |
25 |
25 |
77 |
77 |
78 if self.__module is not None: |
78 if self.__module is not None: |
79 self.filenameEdit.setText(self.srcFile) |
79 self.filenameEdit.setText(self.srcFile) |
80 |
80 |
81 classesList = [] |
81 classesList = [] |
82 for cls in self.__module.classes.values(): |
82 for cls in list(self.__module.classes.values()): |
83 classesList.append(cls.name) |
83 classesList.append(cls.name) |
84 classesList.sort() |
84 classesList.sort() |
85 self.classNameCombo.addItems(classesList) |
85 self.classNameCombo.addItems(classesList) |
86 |
86 |
87 if os.path.exists(self.srcFile) and self.classNameCombo.count() == 0: |
87 if os.path.exists(self.srcFile) and self.classNameCombo.count() == 0: |
112 @return object name (string) |
112 @return object name (string) |
113 """ |
113 """ |
114 try: |
114 try: |
115 dlg = uic.loadUi(self.formFile) |
115 dlg = uic.loadUi(self.formFile) |
116 return dlg.objectName() |
116 return dlg.objectName() |
117 except AttributeError, err: |
117 except AttributeError as err: |
118 QMessageBox.critical(self, |
118 QMessageBox.critical(self, |
119 self.trUtf8("uic error"), |
119 self.trUtf8("uic error"), |
120 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" |
120 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" |
121 """<p>{1}</p>""").format(self.formFile, unicode(err)), |
121 """<p>{1}</p>""").format(self.formFile, str(err)), |
122 QMessageBox.StandardButtons(\ |
122 QMessageBox.StandardButtons(\ |
123 QMessageBox.Ok)) |
123 QMessageBox.Ok)) |
124 return "" |
124 return "" |
125 |
125 |
126 def __className(self): |
126 def __className(self): |
130 @return class name (sting) |
130 @return class name (sting) |
131 """ |
131 """ |
132 try: |
132 try: |
133 dlg = uic.loadUi(self.formFile) |
133 dlg = uic.loadUi(self.formFile) |
134 return dlg.metaObject().className() |
134 return dlg.metaObject().className() |
135 except AttributeError, err: |
135 except AttributeError as err: |
136 QMessageBox.critical(self, |
136 QMessageBox.critical(self, |
137 self.trUtf8("uic error"), |
137 self.trUtf8("uic error"), |
138 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" |
138 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" |
139 """<p>{1}</p>""").format(self.formFile, unicode(err)), |
139 """<p>{1}</p>""").format(self.formFile, str(err)), |
140 QMessageBox.StandardButtons(\ |
140 QMessageBox.StandardButtons(\ |
141 QMessageBox.Ok)) |
141 QMessageBox.Ok)) |
142 return "" |
142 return "" |
143 |
143 |
144 def __signatures(self): |
144 def __signatures(self): |
152 |
152 |
153 signatures = [] |
153 signatures = [] |
154 clsName = self.classNameCombo.currentText() |
154 clsName = self.classNameCombo.currentText() |
155 if clsName: |
155 if clsName: |
156 cls = self.__module.classes[clsName] |
156 cls = self.__module.classes[clsName] |
157 for meth in cls.methods.values(): |
157 for meth in list(cls.methods.values()): |
158 if meth.name.startswith("on_"): |
158 if meth.name.startswith("on_"): |
159 if meth.pyqtSignature is not None: |
159 if meth.pyqtSignature is not None: |
160 sig = ", ".join([str(QMetaObject.normalizedType(t)) \ |
160 sig = ", ".join([str(QMetaObject.normalizedType(t)) \ |
161 for t in meth.pyqtSignature.split(",")]) |
161 for t in meth.pyqtSignature.split(",")]) |
162 signatures.append("%s(%s)" % (meth.name, sig)) |
162 signatures.append("%s(%s)" % (meth.name, sig)) |
236 Qt.ItemIsSelectable) |
236 Qt.ItemIsSelectable) |
237 ) |
237 ) |
238 itm2.setCheckState(Qt.Unchecked) |
238 itm2.setCheckState(Qt.Unchecked) |
239 |
239 |
240 self.slotsView.sortByColumn(0, Qt.AscendingOrder) |
240 self.slotsView.sortByColumn(0, Qt.AscendingOrder) |
241 except (AttributeError, ImportError), err: |
241 except (AttributeError, ImportError) as err: |
242 QMessageBox.critical(self, |
242 QMessageBox.critical(self, |
243 self.trUtf8("uic error"), |
243 self.trUtf8("uic error"), |
244 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" |
244 self.trUtf8("""<p>There was an error loading the form <b>{0}</b>.</p>""" |
245 """<p>{1}</p>""").format(self.formFile, unicode(err)), |
245 """<p>{1}</p>""").format(self.formFile, str(err)), |
246 QMessageBox.StandardButtons(\ |
246 QMessageBox.StandardButtons(\ |
247 QMessageBox.Ok)) |
247 QMessageBox.Ok)) |
248 |
248 |
249 def __generateCode(self): |
249 def __generateCode(self): |
250 """ |
250 """ |
277 |
277 |
278 if self.__module is None: |
278 if self.__module is None: |
279 # new file |
279 # new file |
280 try: |
280 try: |
281 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl.py.tmpl") |
281 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl.py.tmpl") |
282 tmplFile = open(tmplName, 'rb') |
282 tmplFile = open(tmplName, 'r') |
283 template = tmplFile.read() |
283 template = tmplFile.read() |
284 tmplFile.close() |
284 tmplFile.close() |
285 except IOError, why: |
285 except IOError as why: |
286 QMessageBox.critical(self, |
286 QMessageBox.critical(self, |
287 self.trUtf8("Code Generation"), |
287 self.trUtf8("Code Generation"), |
288 self.trUtf8("""<p>Could not open the code template file "{0}".</p>""" |
288 self.trUtf8("""<p>Could not open the code template file "{0}".</p>""" |
289 """<p>Reason: {1}</p>""")\ |
289 """<p>Reason: {1}</p>""")\ |
290 .format(tmplName, unicode(why)), |
290 .format(tmplName, str(why)), |
291 QMessageBox.StandardButtons(\ |
291 QMessageBox.StandardButtons(\ |
292 QMessageBox.Ok)) |
292 QMessageBox.Ok)) |
293 return |
293 return |
294 |
294 |
295 objName = self.__objectName() |
295 objName = self.__objectName() |
310 indentStr = line.replace(line.lstrip(), "") |
310 indentStr = line.replace(line.lstrip(), "") |
311 break |
311 break |
312 else: |
312 else: |
313 # extend existing file |
313 # extend existing file |
314 try: |
314 try: |
315 srcFile = open(self.srcFile, 'rb') |
315 srcFile = open(self.srcFile, 'r') |
316 sourceImpl = srcFile.readlines() |
316 sourceImpl = srcFile.readlines() |
317 srcFile.close() |
317 srcFile.close() |
318 if not sourceImpl[-1].endswith(os.linesep): |
318 if not sourceImpl[-1].endswith(os.linesep): |
319 sourceImpl[-1] = "%s%s" % (sourceImpl[-1], os.linesep) |
319 sourceImpl[-1] = "%s%s" % (sourceImpl[-1], os.linesep) |
320 except IOError, why: |
320 except IOError as why: |
321 QMessageBox.critical(self, |
321 QMessageBox.critical(self, |
322 self.trUtf8("Code Generation"), |
322 self.trUtf8("Code Generation"), |
323 self.trUtf8("""<p>Could not open the source file "{0}".</p>""" |
323 self.trUtf8("""<p>Could not open the source file "{0}".</p>""" |
324 """<p>Reason: {1}</p>""")\ |
324 """<p>Reason: {1}</p>""")\ |
325 .format(self.srcFile, unicode(why)), |
325 .format(self.srcFile, str(why)), |
326 QMessageBox.StandardButtons(\ |
326 QMessageBox.StandardButtons(\ |
327 QMessageBox.Ok)) |
327 QMessageBox.Ok)) |
328 return |
328 return |
329 |
329 |
330 cls = self.__module.classes[self.classNameCombo.currentText()] |
330 cls = self.__module.classes[self.classNameCombo.currentText()] |
368 else: |
368 else: |
369 sourceImpl[appendAtIndex:appendAtIndex] = slotsCode |
369 sourceImpl[appendAtIndex:appendAtIndex] = slotsCode |
370 |
370 |
371 # write the new code |
371 # write the new code |
372 try: |
372 try: |
373 srcFile = open(self.filenameEdit.text(), 'wb') |
373 srcFile = open(self.filenameEdit.text(), 'w') |
374 srcFile.write("".join(sourceImpl)) |
374 srcFile.write("".join(sourceImpl)) |
375 srcFile.close() |
375 srcFile.close() |
376 except IOError, why: |
376 except IOError as why: |
377 QMessageBox.critical(self, |
377 QMessageBox.critical(self, |
378 self.trUtf8("Code Generation"), |
378 self.trUtf8("Code Generation"), |
379 self.trUtf8("""<p>Could not write the source file "{0}".</p>""" |
379 self.trUtf8("""<p>Could not write the source file "{0}".</p>""" |
380 """<p>Reason: {1}</p>""")\ |
380 """<p>Reason: {1}</p>""")\ |
381 .format(self.filenameEdit.text(), unicode(why)), |
381 .format(self.filenameEdit.text(), str(why)), |
382 QMessageBox.StandardButtons(\ |
382 QMessageBox.StandardButtons(\ |
383 QMessageBox.Ok)) |
383 QMessageBox.Ok)) |
384 return |
384 return |
385 |
385 |
386 self.project.appendFile(self.filenameEdit.text()) |
386 self.project.appendFile(self.filenameEdit.text()) |