10 |
10 |
11 import sys |
11 import sys |
12 import os |
12 import os |
13 import json |
13 import json |
14 |
14 |
15 from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QRegExp, \ |
15 from PyQt5.QtCore import ( |
16 QSortFilterProxyModel, QProcess, QProcessEnvironment |
16 pyqtSlot, Qt, QMetaObject, QRegExp, QSortFilterProxyModel, QProcess, |
|
17 QProcessEnvironment |
|
18 ) |
17 from PyQt5.QtGui import QStandardItemModel, QBrush, QStandardItem |
19 from PyQt5.QtGui import QStandardItemModel, QBrush, QStandardItem |
18 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
20 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
19 |
21 |
20 |
22 |
21 from E5Gui.E5Application import e5App |
23 from E5Gui.E5Application import e5App |
121 if classesList: |
123 if classesList: |
122 self.classNameCombo.addItem( |
124 self.classNameCombo.addItem( |
123 CreateDialogCodeDialog.Separator) |
125 CreateDialogCodeDialog.Separator) |
124 self.classNameCombo.addItems(sorted(vagueClassesList)) |
126 self.classNameCombo.addItems(sorted(vagueClassesList)) |
125 |
127 |
126 if os.path.exists(self.srcFile) and \ |
128 if ( |
127 self.__module is not None and \ |
129 os.path.exists(self.srcFile) and |
128 self.classNameCombo.count() == 0: |
130 self.__module is not None and |
|
131 self.classNameCombo.count() == 0 |
|
132 ): |
129 self.__initError = True |
133 self.__initError = True |
130 E5MessageBox.critical( |
134 E5MessageBox.critical( |
131 self, |
135 self, |
132 self.tr("Create Dialog Code"), |
136 self.tr("Create Dialog Code"), |
133 self.tr( |
137 self.tr( |
282 mapped = bytes(type_).decode() |
286 mapped = bytes(type_).decode() |
283 |
287 |
284 # I. always check for * |
288 # I. always check for * |
285 mapped = mapped.replace("*", "") |
289 mapped = mapped.replace("*", "") |
286 |
290 |
287 if self.project.getProjectLanguage() != "Python2" or \ |
291 if ( |
288 self.project.getProjectType in ("PySide", "PySide2"): |
292 self.project.getProjectLanguage() != "Python2" or |
|
293 self.project.getProjectType in ("PySide", "PySide2") |
|
294 ): |
289 # 1. check for const |
295 # 1. check for const |
290 mapped = mapped.replace("const ", "") |
296 mapped = mapped.replace("const ", "") |
291 |
297 |
292 # 2. replace QString and QStringList |
298 # 2. replace QString and QStringList |
293 mapped = mapped.replace("QStringList", "list")\ |
299 mapped = ( |
294 .replace("QString", "str") |
300 mapped |
|
301 .replace("QStringList", "list") |
|
302 .replace("QString", "str") |
|
303 ) |
295 |
304 |
296 # 3. replace double by float |
305 # 3. replace double by float |
297 mapped = mapped.replace("double", "float") |
306 mapped = mapped.replace("double", "float") |
298 |
307 |
299 return mapped |
308 return mapped |
320 for methodDict in objectDict["methods"]: |
329 for methodDict in objectDict["methods"]: |
321 itm2 = QStandardItem(methodDict["signature"]) |
330 itm2 = QStandardItem(methodDict["signature"]) |
322 itm.appendRow(itm2) |
331 itm.appendRow(itm2) |
323 |
332 |
324 if self.__module is not None: |
333 if self.__module is not None: |
325 if methodDict["methods"][0] in signatureList or \ |
334 if ( |
326 methodDict["methods"][1] in signatureList: |
335 methodDict["methods"][0] in signatureList or |
|
336 methodDict["methods"][1] in signatureList |
|
337 ): |
327 itm2.setFlags( |
338 itm2.setFlags( |
328 Qt.ItemFlags(Qt.ItemIsEnabled)) |
339 Qt.ItemFlags(Qt.ItemIsEnabled)) |
329 itm2.setCheckState(Qt.Checked) |
340 itm2.setCheckState(Qt.Checked) |
330 itm2.setForeground(QBrush(Qt.blue)) |
341 itm2.setForeground(QBrush(Qt.blue)) |
331 continue |
342 continue |
353 def __generateCode(self): |
364 def __generateCode(self): |
354 """ |
365 """ |
355 Private slot to generate the code as requested by the user. |
366 Private slot to generate the code as requested by the user. |
356 """ |
367 """ |
357 # first decide on extension |
368 # first decide on extension |
358 if self.filenameEdit.text().endswith(".py") or \ |
369 if ( |
359 self.filenameEdit.text().endswith(".pyw"): |
370 self.filenameEdit.text().endswith(".py") or |
|
371 self.filenameEdit.text().endswith(".pyw") |
|
372 ): |
360 self.__generatePythonCode() |
373 self.__generatePythonCode() |
361 elif self.filenameEdit.text().endswith(".rb"): |
374 elif self.filenameEdit.text().endswith(".rb"): |
362 pass |
375 pass |
363 # second decide on project language |
376 # second decide on project language |
364 elif self.project.getProjectLanguage() in ["Python2", "Python3"]: |
377 elif self.project.getProjectLanguage() in ["Python2", "Python3"]: |
430 .format(tmplName, str(why))) |
443 .format(tmplName, str(why))) |
431 return |
444 return |
432 |
445 |
433 objName = self.__objectName() |
446 objName = self.__objectName() |
434 if objName: |
447 if objName: |
435 template = template\ |
448 template = ( |
|
449 template |
436 .replace( |
450 .replace( |
437 "$FORMFILE$", |
451 "$FORMFILE$", |
438 os.path.splitext(os.path.basename(self.formFile))[0])\ |
452 os.path.splitext(os.path.basename(self.formFile))[0]) |
439 .replace("$FORMCLASS$", objName)\ |
453 .replace("$FORMCLASS$", objName) |
440 .replace("$CLASSNAME$", self.classNameCombo.currentText())\ |
454 .replace("$CLASSNAME$", self.classNameCombo.currentText()) |
441 .replace("$SUPERCLASS$", self.__className()) |
455 .replace("$SUPERCLASS$", self.__className()) |
|
456 ) |
442 |
457 |
443 sourceImpl = template.splitlines(True) |
458 sourceImpl = template.splitlines(True) |
444 appendAtIndex = -1 |
459 appendAtIndex = -1 |
445 |
460 |
446 # determine indent string |
461 # determine indent string |
499 pyqtSignatureFormat = '@pyqtSlot({0})' |
514 pyqtSignatureFormat = '@pyqtSlot({0})' |
500 for row in range(self.slotsModel.rowCount()): |
515 for row in range(self.slotsModel.rowCount()): |
501 topItem = self.slotsModel.item(row) |
516 topItem = self.slotsModel.item(row) |
502 for childRow in range(topItem.rowCount()): |
517 for childRow in range(topItem.rowCount()): |
503 child = topItem.child(childRow) |
518 child = topItem.child(childRow) |
504 if child.checkState() and \ |
519 if ( |
505 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable): |
520 child.checkState() and |
|
521 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable) |
|
522 ): |
506 slotsCode.append('{0}\n'.format(indentStr)) |
523 slotsCode.append('{0}\n'.format(indentStr)) |
507 slotsCode.append('{0}{1}\n'.format( |
524 slotsCode.append('{0}{1}\n'.format( |
508 indentStr, |
525 indentStr, |
509 pyqtSignatureFormat.format( |
526 pyqtSignatureFormat.format( |
510 child.data(pyqtSignatureRole)))) |
527 child.data(pyqtSignatureRole)))) |
513 indentStr2 = indentStr * 2 |
530 indentStr2 = indentStr * 2 |
514 slotsCode.append('{0}"""\n'.format(indentStr2)) |
531 slotsCode.append('{0}"""\n'.format(indentStr2)) |
515 slotsCode.append( |
532 slotsCode.append( |
516 '{0}Slot documentation goes here.\n'.format( |
533 '{0}Slot documentation goes here.\n'.format( |
517 indentStr2)) |
534 indentStr2)) |
518 if child.data(returnTypeRole) or \ |
535 if ( |
519 child.data(parameterTypesListRole): |
536 child.data(returnTypeRole) or |
|
537 child.data(parameterTypesListRole) |
|
538 ): |
520 slotsCode.append('{0}\n'.format(indentStr2)) |
539 slotsCode.append('{0}\n'.format(indentStr2)) |
521 if child.data(parameterTypesListRole): |
540 if child.data(parameterTypesListRole): |
522 for name, type_ in zip( |
541 for name, type_ in zip( |
523 child.data(parameterNamesListRole), |
542 child.data(parameterNamesListRole), |
524 child.data(parameterTypesListRole)): |
543 child.data(parameterTypesListRole)): |