@@ -64,7 +64,7 void PythonQt::init(int flags) | |||
|
64 | 64 | |
|
65 | 65 | PythonQtMethodInfo::addParameterTypeAlias("QObjectList", "QList<QObject*>"); |
|
66 | 66 | qRegisterMetaType<QList<QObject*> >("QList<void*>"); |
|
67 | ||
|
67 | ||
|
68 | 68 | PythonQtRegisterToolClassesTemplateConverter(int); |
|
69 | 69 | PythonQtRegisterToolClassesTemplateConverter(float); |
|
70 | 70 | PythonQtRegisterToolClassesTemplateConverter(double); |
@@ -103,7 +103,7 void PythonQt::init(int flags) | |||
|
103 | 103 | PythonQtRegisterToolClassesTemplateConverter(QPoint); |
|
104 | 104 | PythonQtRegisterToolClassesTemplateConverter(QPointF); |
|
105 | 105 | PythonQtRegisterToolClassesTemplateConverter(QRegExp); |
|
106 | ||
|
106 | ||
|
107 | 107 | PythonQt::self()->registerCPPClass("QFont", "", "QtGui", PythonQtCreateObject<PythonQtWrapper_QFont>); |
|
108 | 108 | PythonQt::self()->registerCPPClass("QPixmap", "", "QtGui", PythonQtCreateObject<PythonQtWrapper_QPixmap>); |
|
109 | 109 | PythonQt::self()->registerCPPClass("QBrush", "", "QtGui", PythonQtCreateObject<PythonQtWrapper_QBrush>); |
@@ -140,7 +140,7 void PythonQt::init(int flags) | |||
|
140 | 140 | PythonQtRegisterToolClassesTemplateConverter(QTextFormat); |
|
141 | 141 | PythonQtRegisterToolClassesTemplateConverter(QMatrix); |
|
142 | 142 | |
|
143 | ||
|
143 | ||
|
144 | 144 | PyObject* pack = PythonQt::priv()->packageByName("QtCore"); |
|
145 | 145 | PyObject* pack2 = PythonQt::priv()->packageByName("Qt"); |
|
146 | 146 | PyObject* qtNamespace = PythonQt::priv()->getClassInfo("Qt")->pythonQtClassWrapper(); |
@@ -172,20 +172,20 PythonQt::PythonQt(int flags) | |||
|
172 | 172 | _p->_initFlags = flags; |
|
173 | 173 | |
|
174 | 174 | _p->_PythonQtObjectPtr_metaId = qRegisterMetaType<PythonQtObjectPtr>("PythonQtObjectPtr"); |
|
175 | ||
|
175 | ||
|
176 | 176 | Py_SetProgramName("PythonQt"); |
|
177 | 177 | if (flags & IgnoreSiteModule) { |
|
178 | 178 | // this prevents the automatic importing of Python site files |
|
179 | 179 | Py_NoSiteFlag = 1; |
|
180 | 180 | } |
|
181 | 181 | Py_Initialize(); |
|
182 | ||
|
182 | ||
|
183 | 183 | // add our own python object types for qt object slots |
|
184 | 184 | if (PyType_Ready(&PythonQtSlotFunction_Type) < 0) { |
|
185 | 185 | std::cerr << "could not initialize PythonQtSlotFunction_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; |
|
186 | 186 | } |
|
187 | 187 | Py_INCREF(&PythonQtSlotFunction_Type); |
|
188 | ||
|
188 | ||
|
189 | 189 | // according to Python docs, set the type late here, since it can not safely be stored in the struct when declaring it |
|
190 | 190 | PythonQtClassWrapper_Type.tp_base = &PyType_Type; |
|
191 | 191 | // add our own python object types for classes |
@@ -200,13 +200,13 PythonQt::PythonQt(int flags) | |||
|
200 | 200 | std::cerr << "could not initialize PythonQtInstanceWrapper_Type" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; |
|
201 | 201 | } |
|
202 | 202 | Py_INCREF(&PythonQtInstanceWrapper_Type); |
|
203 | ||
|
203 | ||
|
204 | 204 | // add our own python object types for redirection of stdout |
|
205 | 205 | if (PyType_Ready(&PythonQtStdOutRedirectType) < 0) { |
|
206 | 206 | std::cerr << "could not initialize PythonQtStdOutRedirectType" << ", in " << __FILE__ << ":" << __LINE__ << std::endl; |
|
207 | 207 | } |
|
208 | 208 | Py_INCREF(&PythonQtStdOutRedirectType); |
|
209 | ||
|
209 | ||
|
210 | 210 | initPythonQtModule(flags & RedirectStdOut); |
|
211 | 211 | |
|
212 | 212 | _p->setupSharedLibrarySuffixes(); |
@@ -405,7 +405,7 PythonQtInstanceWrapper* PythonQtPrivate::createNewPythonQtInstanceWrapper(QObje | |||
|
405 | 405 | result->_wrappedPtr = wrappedPtr; |
|
406 | 406 | result->_ownedByPythonQt = false; |
|
407 | 407 | result->_useQMetaTypeDestroy = false; |
|
408 | ||
|
408 | ||
|
409 | 409 | if (wrappedPtr) { |
|
410 | 410 | _wrappedObjects.insert(wrappedPtr, result); |
|
411 | 411 | } else { |
@@ -425,7 +425,7 PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla | |||
|
425 | 425 | |
|
426 | 426 | PyObject* baseClasses = PyTuple_New(1); |
|
427 | 427 | PyTuple_SET_ITEM(baseClasses, 0, (PyObject*)&PythonQtInstanceWrapper_Type); |
|
428 | ||
|
428 | ||
|
429 | 429 | PyObject* typeDict = PyDict_New(); |
|
430 | 430 | QByteArray moduleName("PythonQt"); |
|
431 | 431 | if (package && strcmp(package, "")!=0) { |
@@ -459,18 +459,18 PyObject* PythonQtPrivate::createEnumValueInstance(PyObject* enumType, unsigned | |||
|
459 | 459 | |
|
460 | 460 | PyObject* PythonQtPrivate::createNewPythonQtEnumWrapper(const char* enumName, PyObject* parentObject) { |
|
461 | 461 | PyObject* result; |
|
462 | ||
|
462 | ||
|
463 | 463 | PyObject* className = PyString_FromString(enumName); |
|
464 | ||
|
464 | ||
|
465 | 465 | PyObject* baseClasses = PyTuple_New(1); |
|
466 | 466 | PyTuple_SET_ITEM(baseClasses, 0, (PyObject*)&PyInt_Type); |
|
467 | ||
|
467 | ||
|
468 | 468 | PyObject* module = PyObject_GetAttrString(parentObject, "__module__"); |
|
469 | 469 | PyObject* typeDict = PyDict_New(); |
|
470 | 470 | PyDict_SetItemString(typeDict, "__module__", module); |
|
471 | ||
|
471 | ||
|
472 | 472 | PyObject* args = Py_BuildValue("OOO", className, baseClasses, typeDict); |
|
473 | ||
|
473 | ||
|
474 | 474 | // create the new int derived type object by calling the core type |
|
475 | 475 | result = PyObject_Call((PyObject *)&PyType_Type, args, NULL); |
|
476 | 476 | |
@@ -478,7 +478,7 PyObject* PythonQtPrivate::createNewPythonQtEnumWrapper(const char* enumName, Py | |||
|
478 | 478 | Py_DECREF(typeDict); |
|
479 | 479 | Py_DECREF(args); |
|
480 | 480 | Py_DECREF(className); |
|
481 | ||
|
481 | ||
|
482 | 482 | return result; |
|
483 | 483 | } |
|
484 | 484 | |
@@ -719,7 +719,7 QVariant PythonQt::getVariable(PyObject* object, const QString& objectname) | |||
|
719 | 719 | QStringList PythonQt::introspection(PyObject* module, const QString& objectname, PythonQt::ObjectType type) |
|
720 | 720 | { |
|
721 | 721 | QStringList results; |
|
722 | ||
|
722 | ||
|
723 | 723 | PythonQtObjectPtr object; |
|
724 | 724 | if (objectname.isEmpty()) { |
|
725 | 725 | object = module; |
@@ -738,7 +738,7 QStringList PythonQt::introspection(PyObject* module, const QString& objectname, | |||
|
738 | 738 | if (PythonQtSlotFunction_Check(object)) { |
|
739 | 739 | PythonQtSlotFunctionObject* o = (PythonQtSlotFunctionObject*)object.object(); |
|
740 | 740 | PythonQtSlotInfo* info = o->m_ml; |
|
741 | ||
|
741 | ||
|
742 | 742 | while (info) { |
|
743 | 743 | results << info->fullSignature(); |
|
744 | 744 | info = info->nextInfo(); |
@@ -746,7 +746,7 QStringList PythonQt::introspection(PyObject* module, const QString& objectname, | |||
|
746 | 746 | } else if (object->ob_type == &PythonQtClassWrapper_Type) { |
|
747 | 747 | PythonQtClassWrapper* o = (PythonQtClassWrapper*)object.object(); |
|
748 | 748 | PythonQtSlotInfo* info = o->classInfo()->constructors(); |
|
749 | ||
|
749 | ||
|
750 | 750 | while (info) { |
|
751 | 751 | results << info->fullSignature(); |
|
752 | 752 | info = info->nextInfo(); |
@@ -872,7 +872,7 PyObject* PythonQt::callAndReturnPyObject(PyObject* callable, const QVariantList | |||
|
872 | 872 | break; |
|
873 | 873 | } |
|
874 | 874 | } |
|
875 | ||
|
875 | ||
|
876 | 876 | if (!err) { |
|
877 | 877 | PyErr_Clear(); |
|
878 | 878 | result = PyObject_CallObject(callable, pargs); |
@@ -903,8 +903,8 void PythonQt::registerQObjectClassNames(const QStringList& names) | |||
|
903 | 903 | |
|
904 | 904 | void PythonQt::setImporter(PythonQtImportFileInterface* importInterface) |
|
905 | 905 | { |
|
906 | PythonQtImport::init(); | |
|
907 | 906 | _p->_importInterface = importInterface; |
|
907 | PythonQtImport::init(); | |
|
908 | 908 | } |
|
909 | 909 | |
|
910 | 910 | void PythonQt::setImporterIgnorePaths(const QStringList& paths) |
@@ -966,7 +966,7 void PythonQtPrivate::addDecorators(QObject* o, int decoTypes) | |||
|
966 | 966 | if ((m.methodType() == QMetaMethod::Method || |
|
967 | 967 | m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) { |
|
968 | 968 | if (qstrncmp(m.signature(), "new_", 4)==0) { |
|
969 |
if ((decoTypes & ConstructorDecorator) == 0) continue; |
|
|
969 | if ((decoTypes & ConstructorDecorator) == 0) continue; | |
|
970 | 970 | const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m, NULL); |
|
971 | 971 | if (info->parameters().at(0).isPointer) { |
|
972 | 972 | QByteArray signature = m.signature(); |
@@ -976,14 +976,14 void PythonQtPrivate::addDecorators(QObject* o, int decoTypes) | |||
|
976 | 976 | classInfo->addConstructor(newSlot); |
|
977 | 977 | } |
|
978 | 978 | } else if (qstrncmp(m.signature(), "delete_", 7)==0) { |
|
979 |
if ((decoTypes & DestructorDecorator) == 0) continue; |
|
|
979 | if ((decoTypes & DestructorDecorator) == 0) continue; | |
|
980 | 980 | QByteArray signature = m.signature(); |
|
981 | 981 | QByteArray nameOfClass = signature.mid(7, signature.indexOf('(')-7); |
|
982 | 982 | PythonQtClassInfo* classInfo = lookupClassInfoAndCreateIfNotPresent(nameOfClass); |
|
983 | 983 | PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(NULL, m, i, o, PythonQtSlotInfo::ClassDecorator); |
|
984 | 984 | classInfo->setDestructor(newSlot); |
|
985 | 985 | } else if (qstrncmp(m.signature(), "static_", 7)==0) { |
|
986 |
if ((decoTypes & StaticDecorator) == 0) continue; |
|
|
986 | if ((decoTypes & StaticDecorator) == 0) continue; | |
|
987 | 987 | QByteArray signature = m.signature(); |
|
988 | 988 | QByteArray nameOfClass = signature.mid(signature.indexOf('_')+1); |
|
989 | 989 | nameOfClass = nameOfClass.mid(0, nameOfClass.indexOf('_')); |
@@ -991,7 +991,7 void PythonQtPrivate::addDecorators(QObject* o, int decoTypes) | |||
|
991 | 991 | PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(NULL, m, i, o, PythonQtSlotInfo::ClassDecorator); |
|
992 | 992 | classInfo->addDecoratorSlot(newSlot); |
|
993 | 993 | } else { |
|
994 |
if ((decoTypes & InstanceDecorator) == 0) continue; |
|
|
994 | if ((decoTypes & InstanceDecorator) == 0) continue; | |
|
995 | 995 | const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m, NULL); |
|
996 | 996 | if (info->parameters().count()>1) { |
|
997 | 997 | PythonQtMethodInfo::ParameterInfo p = info->parameters().at(1); |
@@ -1022,17 +1022,17 bool PythonQt::handleError() | |||
|
1022 | 1022 | { |
|
1023 | 1023 | bool flag = false; |
|
1024 | 1024 | if (PyErr_Occurred()) { |
|
1025 | ||
|
1025 | ||
|
1026 | 1026 | // currently we just print the error and the stderr handler parses the errors |
|
1027 | 1027 | PyErr_Print(); |
|
1028 | ||
|
1028 | ||
|
1029 | 1029 | /* |
|
1030 | 1030 | // EXTRA: the format of the ptype and ptraceback is not really documented, so I use PyErr_Print() above |
|
1031 | 1031 | PyObject *ptype; |
|
1032 | 1032 | PyObject *pvalue; |
|
1033 | 1033 | PyObject *ptraceback; |
|
1034 | 1034 | PyErr_Fetch( &ptype, &pvalue, &ptraceback); |
|
1035 | ||
|
1035 | ||
|
1036 | 1036 | Py_XDECREF(ptype); |
|
1037 | 1037 | Py_XDECREF(pvalue); |
|
1038 | 1038 | Py_XDECREF(ptraceback); |
@@ -1048,7 +1048,7 void PythonQt::addSysPath(const QString& path) | |||
|
1048 | 1048 | PythonQtObjectPtr sys; |
|
1049 | 1049 | sys.setNewRef(PyImport_ImportModule("sys")); |
|
1050 | 1050 | PythonQtObjectPtr obj = lookupObject(sys, "path"); |
|
1051 |
PyList_Insert(obj, 0, PythonQtConv::QStringToPyObject(path)); |
|
|
1051 | PyList_Insert(obj, 0, PythonQtConv::QStringToPyObject(path)); | |
|
1052 | 1052 | } |
|
1053 | 1053 | |
|
1054 | 1054 | void PythonQt::overwriteSysPath(const QStringList& paths) |
@@ -1092,7 +1092,7 static PyMethodDef PythonQtMethods[] = { | |||
|
1092 | 1092 | void PythonQt::initPythonQtModule(bool redirectStdOut) |
|
1093 | 1093 | { |
|
1094 | 1094 | _p->_pythonQtModule = Py_InitModule("PythonQt", PythonQtMethods); |
|
1095 | ||
|
1095 | ||
|
1096 | 1096 | if (redirectStdOut) { |
|
1097 | 1097 | PythonQtObjectPtr sys; |
|
1098 | 1098 | PythonQtObjectPtr out; |
@@ -1196,7 +1196,7 void PythonQtPrivate::handleVirtualOverloadReturnError(const char* signature, co | |||
|
1196 | 1196 | } |
|
1197 | 1197 | |
|
1198 | 1198 | PyObject* PythonQt::helpCalled(PythonQtClassInfo* info) |
|
1199 |
{ |
|
|
1199 | { | |
|
1200 | 1200 | if (_p->_initFlags & ExternalHelp) { |
|
1201 | 1201 | emit pythonHelpRequest(QByteArray(info->className())); |
|
1202 | 1202 | return Py_BuildValue(""); |
General Comments 0
You need to be logged in to leave comments.
Login now