155 if clsName: |
155 if clsName: |
156 cls = self.__module.classes[clsName] |
156 cls = self.__module.classes[clsName] |
157 for meth in list(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([bytes(QMetaObject.normalizedType(t)).decode() \ |
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)) |
163 else: |
163 else: |
164 signatures.append(meth.name) |
164 signatures.append(meth.name) |
165 return signatures |
165 return signatures |
|
166 |
|
167 def __mapType(self, type_): |
|
168 """ |
|
169 Private method to map a type as reported by Qt's meta object to the |
|
170 correct Python type. |
|
171 |
|
172 @param type_ type as reported by Qt (QByteArray) |
|
173 @return mapped Python type (string) |
|
174 """ |
|
175 mapped = bytes(type_).decode() |
|
176 |
|
177 # 1. check for const |
|
178 mapped = mapped.replace("const ", "") |
|
179 |
|
180 # 2. check fpr * |
|
181 mapped = mapped.replace("*", "") |
|
182 |
|
183 # 3. replace QString and QStringList |
|
184 mapped = mapped.replace("QStringList", "list").replace("QString", "str") |
|
185 |
|
186 # 4. replace double by float |
|
187 mapped = mapped.replace("double", "float") |
|
188 |
|
189 return mapped |
166 |
190 |
167 def __updateSlotsModel(self): |
191 def __updateSlotsModel(self): |
168 """ |
192 """ |
169 Private slot to update the slots tree display. |
193 Private slot to update the slots tree display. |
170 """ |
194 """ |
204 itm2.setCheckState(Qt.Checked) |
228 itm2.setCheckState(Qt.Checked) |
205 itm2.setForeground(QBrush(Qt.blue)) |
229 itm2.setForeground(QBrush(Qt.blue)) |
206 continue |
230 continue |
207 |
231 |
208 pyqtSignature = \ |
232 pyqtSignature = \ |
209 ", ".join([str(t) for t in metaMethod.parameterTypes()]) |
233 ", ".join([self.__mapType(t) |
|
234 for t in metaMethod.parameterTypes()]) |
210 |
235 |
211 parameterNames = metaMethod.parameterNames() |
236 parameterNames = metaMethod.parameterNames() |
212 if parameterNames: |
237 if parameterNames: |
213 for index in range(len(parameterNames)): |
238 for index in range(len(parameterNames)): |
214 if not parameterNames[index]: |
239 if not parameterNames[index]: |
215 parameterNames[index] = QByteArray("p%d" % index) |
240 parameterNames[index] = QByteArray("p%d" % index) |
216 methNamesSig = \ |
241 methNamesSig = \ |
217 ", ".join([str(n) for n in parameterNames]) |
242 ", ".join([bytes(n).decode() for n in parameterNames]) |
218 |
243 |
219 if methNamesSig: |
244 if methNamesSig: |
220 pythonSignature = "on_%s_%s(self, %s)" % \ |
245 pythonSignature = "on_%s_%s(self, %s)" % \ |
221 (name, |
246 (name, |
222 metaMethod.signature().split("(")[0], |
247 metaMethod.signature().split("(")[0], |
348 for childRow in range(topItem.rowCount()): |
373 for childRow in range(topItem.rowCount()): |
349 child = topItem.child(childRow) |
374 child = topItem.child(childRow) |
350 if child.checkState() and \ |
375 if child.checkState() and \ |
351 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable): |
376 child.flags() & Qt.ItemFlags(Qt.ItemIsUserCheckable): |
352 slotsCode.append('%s\n' % indentStr) |
377 slotsCode.append('%s\n' % indentStr) |
353 # TODO: adjust to new signal/slot mechanism |
|
354 slotsCode.append('%s@pyqtSlot(%s)\n' % \ |
378 slotsCode.append('%s@pyqtSlot(%s)\n' % \ |
355 (indentStr, child.data(pyqtSignatureRole))) |
379 (indentStr, child.data(pyqtSignatureRole))) |
356 slotsCode.append('%sdef %s:\n' % \ |
380 slotsCode.append('%sdef %s:\n' % \ |
357 (indentStr, child.data(pythonSignatureRole))) |
381 (indentStr, child.data(pythonSignatureRole))) |
358 slotsCode.append('%s"""\n' % (indentStr * 2,)) |
382 slotsCode.append('%s"""\n' % (indentStr * 2,)) |