28 from eric6config import getConfig |
28 from eric6config import getConfig |
29 |
29 |
30 pyqtSignatureRole = Qt.UserRole + 1 |
30 pyqtSignatureRole = Qt.UserRole + 1 |
31 pythonSignatureRole = Qt.UserRole + 2 |
31 pythonSignatureRole = Qt.UserRole + 2 |
32 rubySignatureRole = Qt.UserRole + 3 |
32 rubySignatureRole = Qt.UserRole + 3 |
|
33 returnTypeRole = Qt.UserRole + 4 |
|
34 parameterTypesListRole = Qt.UserRole + 5 |
|
35 parameterNamesListRole = Qt.UserRole + 6 |
33 |
36 |
34 |
37 |
35 class CreateDialogCodeDialog(QDialog, Ui_CreateDialogCodeDialog): |
38 class CreateDialogCodeDialog(QDialog, Ui_CreateDialogCodeDialog): |
36 """ |
39 """ |
37 Class implementing a dialog to generate code for a Qt4/Qt5 dialog. |
40 Class implementing a dialog to generate code for a Qt4/Qt5 dialog. |
213 if self.project.getProjectLanguage() != "Python2" or \ |
216 if self.project.getProjectLanguage() != "Python2" or \ |
214 self.project.getProjectType == "PySide": |
217 self.project.getProjectType == "PySide": |
215 # 1. check for const |
218 # 1. check for const |
216 mapped = mapped.replace("const ", "") |
219 mapped = mapped.replace("const ", "") |
217 |
220 |
218 # 2. check fpr * |
221 # 2. check for * |
219 mapped = mapped.replace("*", "") |
222 mapped = mapped.replace("*", "") |
220 |
223 |
221 # 3. replace QString and QStringList |
224 # 3. replace QString and QStringList |
222 mapped = mapped.replace("QStringList", "list")\ |
225 mapped = mapped.replace("QStringList", "list")\ |
223 .replace("QString", "str") |
226 .replace("QString", "str") |
282 itm2.setFlags(Qt.ItemFlags(Qt.ItemIsEnabled)) |
285 itm2.setFlags(Qt.ItemFlags(Qt.ItemIsEnabled)) |
283 itm2.setCheckState(Qt.Checked) |
286 itm2.setCheckState(Qt.Checked) |
284 itm2.setForeground(QBrush(Qt.blue)) |
287 itm2.setForeground(QBrush(Qt.blue)) |
285 continue |
288 continue |
286 |
289 |
287 pyqtSignature = \ |
290 returnType = self.__mapType( |
288 ", ".join([self.__mapType(t) |
291 metaMethod.typeName().encode()) |
289 for t in metaMethod.parameterTypes()]) |
292 if returnType == 'void': |
|
293 returnType = "" |
|
294 parameterTypesList = [ |
|
295 self.__mapType(t) |
|
296 for t in metaMethod.parameterTypes()] |
|
297 pyqtSignature = ", ".join(parameterTypesList) |
290 |
298 |
291 parameterNames = metaMethod.parameterNames() |
299 parameterNames = metaMethod.parameterNames() |
292 if parameterNames: |
300 if parameterNames: |
293 for index in range(len(parameterNames)): |
301 for index in range(len(parameterNames)): |
294 if not parameterNames[index]: |
302 if not parameterNames[index]: |
295 parameterNames[index] = \ |
303 parameterNames[index] = \ |
296 QByteArray("p{0:d}".format(index) |
304 QByteArray("p{0:d}".format(index) |
297 .encode("utf-8")) |
305 .encode("utf-8")) |
298 methNamesSig = \ |
306 parameterNamesList = [bytes(n).decode() |
299 ", ".join( |
307 for n in parameterNames] |
300 [bytes(n).decode() for n in parameterNames]) |
308 methNamesSig = ", ".join(parameterNamesList) |
301 |
309 |
302 if methNamesSig: |
310 if methNamesSig: |
303 if qVersion() >= "5.0.0": |
311 if qVersion() >= "5.0.0": |
304 pythonSignature = \ |
312 pythonSignature = \ |
305 "on_{0}_{1}(self, {2})".format( |
313 "on_{0}_{1}(self, {2})".format( |
323 pythonSignature = "on_{0}_{1}(self)".format( |
331 pythonSignature = "on_{0}_{1}(self)".format( |
324 name, |
332 name, |
325 metaMethod.signature().split("(")[0]) |
333 metaMethod.signature().split("(")[0]) |
326 itm2.setData(pyqtSignature, pyqtSignatureRole) |
334 itm2.setData(pyqtSignature, pyqtSignatureRole) |
327 itm2.setData(pythonSignature, pythonSignatureRole) |
335 itm2.setData(pythonSignature, pythonSignatureRole) |
|
336 itm2.setData(returnType, returnTypeRole) |
|
337 itm2.setData(parameterTypesList, |
|
338 parameterTypesListRole) |
|
339 itm2.setData(parameterNamesList, |
|
340 parameterNamesListRole) |
328 |
341 |
329 itm2.setFlags(Qt.ItemFlags( |
342 itm2.setFlags(Qt.ItemFlags( |
330 Qt.ItemIsUserCheckable | |
343 Qt.ItemIsUserCheckable | |
331 Qt.ItemIsEnabled | |
344 Qt.ItemIsEnabled | |
332 Qt.ItemIsSelectable) |
345 Qt.ItemIsSelectable) |
493 indentStr, |
506 indentStr, |
494 pyqtSignatureFormat.format( |
507 pyqtSignatureFormat.format( |
495 child.data(pyqtSignatureRole)))) |
508 child.data(pyqtSignatureRole)))) |
496 slotsCode.append('{0}def {1}:\n'.format( |
509 slotsCode.append('{0}def {1}:\n'.format( |
497 indentStr, child.data(pythonSignatureRole))) |
510 indentStr, child.data(pythonSignatureRole))) |
498 slotsCode.append('{0}"""\n'.format(indentStr * 2)) |
511 indentStr2 = indentStr * 2 |
|
512 slotsCode.append('{0}"""\n'.format(indentStr2)) |
499 slotsCode.append( |
513 slotsCode.append( |
500 '{0}Slot documentation goes here.\n'.format( |
514 '{0}Slot documentation goes here.\n'.format( |
501 indentStr * 2)) |
515 indentStr2)) |
502 slotsCode.append('{0}"""\n'.format(indentStr * 2)) |
516 if child.data(returnTypeRole) or \ |
|
517 child.data(parameterTypesListRole): |
|
518 slotsCode.append('{0}\n'.format(indentStr2)) |
|
519 if child.data(parameterTypesListRole): |
|
520 for name, type_ in zip( |
|
521 child.data(parameterNamesListRole), |
|
522 child.data(parameterTypesListRole)): |
|
523 slotsCode.append( |
|
524 '{0}@param {1} DESCRIPTION\n'.format( |
|
525 indentStr2, name)) |
|
526 slotsCode.append('{0}@type {1}\n'.format( |
|
527 indentStr2, type_)) |
|
528 if child.data(returnTypeRole): |
|
529 slotsCode.append( |
|
530 '{0}@returns DESCRIPTION\n'.format( |
|
531 indentStr2)) |
|
532 slotsCode.append('{0}@rtype {1}\n'.format( |
|
533 indentStr2, child.data(returnTypeRole))) |
|
534 slotsCode.append('{0}"""\n'.format(indentStr2)) |
503 slotsCode.append('{0}# {1}: not implemented yet\n'.format( |
535 slotsCode.append('{0}# {1}: not implemented yet\n'.format( |
504 indentStr * 2, "TODO")) |
536 indentStr2, "TODO")) |
505 slotsCode.append('{0}raise NotImplementedError\n'.format( |
537 slotsCode.append('{0}raise NotImplementedError\n'.format( |
506 indentStr * 2)) |
538 indentStr2)) |
507 |
539 |
508 if appendAtIndex == -1: |
540 if appendAtIndex == -1: |
509 sourceImpl.extend(slotsCode) |
541 sourceImpl.extend(slotsCode) |
510 else: |
542 else: |
511 sourceImpl[appendAtIndex:appendAtIndex] = slotsCode |
543 sourceImpl[appendAtIndex:appendAtIndex] = slotsCode |