Project/CreateDialogCodeDialog.py

changeset 1139
b18376d58832
parent 1137
1a37887aefa7
child 1148
ddc482ded355
equal deleted inserted replaced
1137:1a37887aefa7 1139:b18376d58832
173 @param type_ type as reported by Qt (QByteArray) 173 @param type_ type as reported by Qt (QByteArray)
174 @return mapped Python type (string) 174 @return mapped Python type (string)
175 """ 175 """
176 mapped = bytes(type_).decode() 176 mapped = bytes(type_).decode()
177 177
178 # 1. check for const 178 if self.project.getProjectLanguage() != "Python2" or \
179 mapped = mapped.replace("const ", "") 179 self.project.getProjectType == "PySide":
180 180 # 1. check for const
181 # 2. check fpr * 181 mapped = mapped.replace("const ", "")
182 mapped = mapped.replace("*", "") 182
183 183 # 2. check fpr *
184 # 3. replace QString and QStringList 184 mapped = mapped.replace("*", "")
185 mapped = mapped.replace("QStringList", "list").replace("QString", "str") 185
186 186 # 3. replace QString and QStringList
187 # 4. replace double by float 187 mapped = mapped.replace("QStringList", "list").replace("QString", "str")
188 mapped = mapped.replace("double", "float") 188
189 # 4. replace double by float
190 mapped = mapped.replace("double", "float")
189 191
190 return mapped 192 return mapped
191 193
192 def __updateSlotsModel(self): 194 def __updateSlotsModel(self):
193 """ 195 """
300 slotsCode = [] 302 slotsCode = []
301 303
302 if self.__module is None: 304 if self.__module is None:
303 # new file 305 # new file
304 try: 306 try:
305 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl.py.tmpl") 307 if self.project.getProjectLanguage() == "Python2":
308 if self.project.getProjectType() == "PySide":
309 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'),
310 "impl_pyside.py2.tmpl")
311 else:
312 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'),
313 "impl_pyqt.py2.tmpl")
314 else:
315 tmplName = os.path.join(getConfig('ericCodeTemplatesDir'),
316 "impl_pyqt.py.tmpl")
306 tmplFile = open(tmplName, 'r', encoding="utf-8") 317 tmplFile = open(tmplName, 'r', encoding="utf-8")
307 template = tmplFile.read() 318 template = tmplFile.read()
308 tmplFile.close() 319 tmplFile.close()
309 except IOError as why: 320 except IOError as why:
310 E5MessageBox.critical(self, 321 E5MessageBox.critical(self,
364 if line.lstrip().startswith("def __init__"): 375 if line.lstrip().startswith("def __init__"):
365 indentStr = line.replace(line.lstrip(), "") 376 indentStr = line.replace(line.lstrip(), "")
366 break 377 break
367 378
368 # do the coding stuff 379 # do the coding stuff
380 if self.project.getProjectLanguage() == "Python2":
381 if self.project.getProjectType() == "PySide":
382 pyqtSignatureFormat = '@Slot({0})'
383 else:
384 pyqtSignatureFormat = '@pyqtSignature("{0}")'
385 else:
386 pyqtSignatureFormat = '@pyqtSlot({0})'
369 for row in range(self.slotsModel.rowCount()): 387 for row in range(self.slotsModel.rowCount()):
370 topItem = self.slotsModel.item(row) 388 topItem = self.slotsModel.item(row)
371 for childRow in range(topItem.rowCount()): 389 for childRow in range(topItem.rowCount()):
372 child = topItem.child(childRow) 390 child = topItem.child(childRow)
373 if child.checkState() and \ 391 if child.checkState() and \
374 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable): 392 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable):
375 slotsCode.append('{0}\n'.format(indentStr)) 393 slotsCode.append('{0}\n'.format(indentStr))
376 slotsCode.append('{0}@pyqtSlot({1})\n'.format( 394 slotsCode.append('{0}{1}\n'.format(
377 indentStr, child.data(pyqtSignatureRole))) 395 indentStr,
396 pyqtSignatureFormat.format(child.data(pyqtSignatureRole))))
378 slotsCode.append('{0}def {1}:\n'.format( 397 slotsCode.append('{0}def {1}:\n'.format(
379 indentStr, child.data(pythonSignatureRole))) 398 indentStr, child.data(pythonSignatureRole)))
380 slotsCode.append('{0}"""\n'.format(indentStr * 2)) 399 slotsCode.append('{0}"""\n'.format(indentStr * 2))
381 slotsCode.append('{0}Slot documentation goes here.\n'.format( 400 slotsCode.append('{0}Slot documentation goes here.\n'.format(
382 indentStr * 2)) 401 indentStr * 2))

eric ide

mercurial