summaryrefslogtreecommitdiffstats
path: root/libpyside
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-11-01 18:42:47 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2011-12-09 19:25:36 -0300
commit0f38019c02fe0459230c6ca583a7b2aba12e6212 (patch)
treef0432bbeb3ca9e60473c7a4d785c2d396065ab5a /libpyside
parentc93001f792db0de9eede4ef14ba365ea21470f78 (diff)
downloadpyside-0f38019c02fe0459230c6ca583a7b2aba12e6212.tar.gz
pyside-0f38019c02fe0459230c6ca583a7b2aba12e6212.tar.xz
pyside-0f38019c02fe0459230c6ca583a7b2aba12e6212.zip
Replaced TypeResolver by SbkConverter and SpecificConverter.
Also updated QtGui's WId conversion to Python 3.
Diffstat (limited to 'libpyside')
-rw-r--r--libpyside/globalreceiver.cpp7
-rw-r--r--libpyside/globalreceiverv2.cpp2
-rw-r--r--libpyside/pyside.cpp10
-rw-r--r--libpyside/pysidemetafunction.cpp27
-rw-r--r--libpyside/pysideproperty.cpp10
-rw-r--r--libpyside/signalmanager.cpp46
6 files changed, 68 insertions, 34 deletions
diff --git a/libpyside/globalreceiver.cpp b/libpyside/globalreceiver.cpp
index 05d5e4d..ace1692 100644
--- a/libpyside/globalreceiver.cpp
+++ b/libpyside/globalreceiver.cpp
@@ -29,6 +29,7 @@
#include <QEvent>
#include <QLinkedList>
#include <autodecref.h>
+#include <sbkconverter.h>
#include <gilstate.h>
#include "typeresolver.h"
@@ -293,8 +294,9 @@ int GlobalReceiver::qt_metacall(QMetaObject::Call call, int id, void** args)
QList<QByteArray> paramTypes = slot.parameterTypes();
Shiboken::AutoDecRef preparedArgs(PyTuple_New(paramTypes.count()));
for (int i = 0, max = paramTypes.count(); i < max; ++i) {
- PyObject* arg = Shiboken::TypeResolver::get(paramTypes[i].constData())->toPython(args[i+1]); // Do not increment the reference
- PyTuple_SET_ITEM(preparedArgs.object(), i, arg);
+ const QByteArray& paramType = paramTypes[i];
+ Shiboken::Conversions::SpecificConverter converter(paramType.constData());
+ PyTuple_SET_ITEM(preparedArgs.object(), i, converter.toPython(args[i+1]));
}
retval = data->call(preparedArgs);
}
@@ -306,4 +308,3 @@ int GlobalReceiver::qt_metacall(QMetaObject::Call call, int id, void** args)
return -1;
}
-
diff --git a/libpyside/globalreceiverv2.cpp b/libpyside/globalreceiverv2.cpp
index cfcf477..65a37ee 100644
--- a/libpyside/globalreceiverv2.cpp
+++ b/libpyside/globalreceiverv2.cpp
@@ -111,7 +111,7 @@ QByteArray DynamicSlotDataV2::hash(PyObject* callback)
{
Shiboken::GilState gil;
if (PyMethod_Check(callback))
- return QByteArray::number((qlonglong)PyObject_Hash(PyMethod_GET_FUNCTION(callback)))
+ return QByteArray::number((qlonglong)PyObject_Hash(PyMethod_GET_FUNCTION(callback)))
+ QByteArray::number((qlonglong)PyObject_Hash(PyMethod_GET_SELF(callback)));
else
return QByteArray::number((qlonglong)PyObject_Hash(callback));
diff --git a/libpyside/pyside.cpp b/libpyside/pyside.cpp
index e2736f1..0d96f95 100644
--- a/libpyside/pyside.cpp
+++ b/libpyside/pyside.cpp
@@ -35,6 +35,7 @@
#include <basewrapper.h>
#include <conversions.h>
+#include <sbkconverter.h>
#include <typeresolver.h>
#include <bindingmanager.h>
#include <algorithm>
@@ -141,7 +142,7 @@ void destroyQCoreApplication()
Shiboken::BindingManager& bm = Shiboken::BindingManager::instance();
SbkObject* pyQApp = bm.retrieveWrapper(app);
- PyTypeObject* pyQObjectType = Shiboken::TypeResolver::get("QObject*")->pythonType();
+ PyTypeObject* pyQObjectType = Shiboken::Conversions::getPythonTypeObject("QObject*");
assert(pyQObjectType);
void* data[2] = {pyQApp, pyQObjectType};
@@ -174,7 +175,10 @@ void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base, const s
//initialize staticQMetaObject property
void* metaObjectPtr = &userData->mo;
- Shiboken::AutoDecRef pyMetaObject(Shiboken::TypeResolver::get("QMetaObject*")->toPython(&metaObjectPtr));
+ static SbkConverter* converter = Shiboken::Conversions::getConverter("QMetaObject");
+ if (!converter)
+ return;
+ Shiboken::AutoDecRef pyMetaObject(Shiboken::Conversions::pointerToPython(converter, metaObjectPtr));
PyObject_SetAttrString(reinterpret_cast<PyObject*>(type), "staticMetaObject", pyMetaObject);
}
@@ -185,7 +189,7 @@ void initDynamicMetaObject(SbkObjectType* type, const QMetaObject* base)
void initQObjectSubType(SbkObjectType* type, PyObject* args, PyObject* kwds)
{
- PyTypeObject* qObjType = Shiboken::TypeResolver::get("QObject*")->pythonType();
+ PyTypeObject* qObjType = Shiboken::Conversions::getPythonTypeObject("QObject*");
QByteArray className(Shiboken::String::toCString(PyTuple_GET_ITEM(args, 0)));
PyObject* bases = PyTuple_GET_ITEM(args, 1);
diff --git a/libpyside/pysidemetafunction.cpp b/libpyside/pysidemetafunction.cpp
index 271ab43..17fe839 100644
--- a/libpyside/pysidemetafunction.cpp
+++ b/libpyside/pysidemetafunction.cpp
@@ -169,10 +169,10 @@ bool call(QObject* self, int methodIndex, PyObject* args, PyObject** retVal)
continue;
}
- Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get(typeName);
- if (typeResolver) {
- if (Shiboken::TypeResolver::getType(typeName) == Shiboken::TypeResolver::ValueType) {
- int typeId = QMetaType::type(typeName);
+ Shiboken::Conversions::SpecificConverter converter(typeName);
+ if (converter) {
+ int typeId = QMetaType::type(typeName);
+ if (!Shiboken::Conversions::pythonTypeIsObjectType(converter)) {
if (!typeId) {
PyErr_Format(PyExc_TypeError, "Value types used on meta functions (including signals) need to be "
"registered on meta type: %s", typeName.data());
@@ -181,8 +181,15 @@ bool call(QObject* self, int methodIndex, PyObject* args, PyObject** retVal)
methValues[i] = QVariant(typeId, (void*) 0);
}
methArgs[i] = methValues[i].data();
- if (i != 0) // Don't do this for return type
- typeResolver->toCpp(PySequence_Fast_GET_ITEM(sequence.object(), i - 1), &methArgs[i]);
+ if (i == 0) // Don't do this for return type
+ continue;
+ if (typeId == QVariant::String) {
+ QString tmp;
+ converter.toCpp(PySequence_Fast_GET_ITEM(sequence.object(), i - 1), &tmp);
+ methValues[i] = tmp;
+ } else {
+ converter.toCpp(PySequence_Fast_GET_ITEM(sequence.object(), i - 1), methArgs[i]);
+ }
} else {
PyErr_Format(PyExc_TypeError, "Unknown type used to call meta function (that may be a signal): %s", argTypes[i].constData());
break;
@@ -195,10 +202,10 @@ bool call(QObject* self, int methodIndex, PyObject* args, PyObject** retVal)
if (retVal) {
if (methArgs[0]) {
- static Shiboken::TypeResolver* qVariantTypeResolver = Shiboken::TypeResolver::get("QVariant");
- Q_ASSERT(qVariantTypeResolver);
-
- *retVal = qVariantTypeResolver->toPython(&methValues[0]);
+ static SbkConverter* qVariantTypeConverter = Shiboken::Conversions::getConverter("QVariant");
+ Q_ASSERT(qVariantTypeConverter);
+ *retVal = Shiboken::Conversions::copyToPython(qVariantTypeConverter, &methValues[0]);
+ SbkDbg() << (*retVal);
} else {
*retVal = Py_None;
Py_INCREF(*retVal);
diff --git a/libpyside/pysideproperty.cpp b/libpyside/pysideproperty.cpp
index 4d253e8..e5ae5d5 100644
--- a/libpyside/pysideproperty.cpp
+++ b/libpyside/pysideproperty.cpp
@@ -104,8 +104,10 @@ PyTypeObject PySidePropertyType = {
static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::Call call, void** args)
{
- Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get(pp->d->typeName);
- Q_ASSERT(typeResolver);
+ Shiboken::Conversions::SpecificConverter converter(pp->d->typeName);
+ Q_ASSERT(converter);
+
+ QByteArray type(pp->d->typeName);
switch(call) {
case QMetaObject::ReadProperty:
@@ -113,7 +115,7 @@ static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::C
Shiboken::GilState gil;
PyObject* value = PySide::Property::getValue(pp, self);
if (value) {
- typeResolver->toCpp(value, &args[0]);
+ converter.toCpp(value, args[0]);
Py_DECREF(value);
} else if (PyErr_Occurred()) {
PyErr_Print(); // Clear any errors but print them to stderr
@@ -124,7 +126,7 @@ static void qpropertyMetaCall(PySideProperty* pp, PyObject* self, QMetaObject::C
case QMetaObject::WriteProperty:
{
Shiboken::GilState gil;
- Shiboken::AutoDecRef value(typeResolver->toPython(args[0]));
+ Shiboken::AutoDecRef value(converter.toPython(args[0]));
PySide::Property::setValue(pp, self, value);
break;
}
diff --git a/libpyside/signalmanager.cpp b/libpyside/signalmanager.cpp
index 54fce07..4bcfae5 100644
--- a/libpyside/signalmanager.cpp
+++ b/libpyside/signalmanager.cpp
@@ -38,6 +38,7 @@
#include <algorithm>
#include <typeresolver.h>
#include <basewrapper.h>
+#include <sbkconverter.h>
#include <conversions.h>
#if QSLOT_CODE != 1 || QSIGNAL_CODE != 2
@@ -225,6 +226,22 @@ static void clearSignalManager()
PySide::SignalManager::instance().clear();
}
+static void PyObject_PythonToCpp_PyObject_PTR(PyObject* pyIn, void* cppOut)
+{
+ *((PyObject**)cppOut) = pyIn;
+}
+static PythonToCppFunc is_PyObject_PythonToCpp_PyObject_PTR_Convertible(PyObject* pyIn)
+{
+ return PyObject_PythonToCpp_PyObject_PTR;
+}
+static PyObject* PyObject_PTR_CppToPython_PyObject(const void* cppIn)
+{
+ PyObject* pyOut = (PyObject*)cppIn;
+ if (pyOut)
+ Py_INCREF(pyOut);
+ return pyOut;
+}
+
SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
{
// Register Qt primitive typedefs used on signals.
@@ -234,9 +251,14 @@ SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
qRegisterMetaType<PyObjectWrapper>(PYTHON_TYPE);
qRegisterMetaTypeStreamOperators<PyObjectWrapper>(PYTHON_TYPE);
- TypeResolver::createValueTypeResolver<PyObjectWrapper>(PYTHON_TYPE);
- TypeResolver::createValueTypeResolver<PyObjectWrapper>("object");
- TypeResolver::createValueTypeResolver<PyObjectWrapper>("PySide::PyObjectWrapper");
+ SbkConverter* converter = Shiboken::Conversions::createConverter(&PyBaseObject_Type, 0);
+ Shiboken::Conversions::setCppPointerToPythonFunction(converter, PyObject_PTR_CppToPython_PyObject);
+ Shiboken::Conversions::setPythonToCppPointerFunctions(converter, PyObject_PythonToCpp_PyObject_PTR, is_PyObject_PythonToCpp_PyObject_PTR_Convertible);
+ Shiboken::Conversions::registerConverterName(converter, PYTHON_TYPE);
+ Shiboken::Conversions::registerConverterName(converter, "object");
+ Shiboken::Conversions::registerConverterName(converter, "PyObjectWrapper");
+ Shiboken::Conversions::registerConverterName(converter, "PySide::PyObjectWrapper");
+
PySide::registerCleanupFunction(clearSignalManager);
if (!metaObjectAttr)
@@ -436,11 +458,12 @@ int SignalManager::callPythonMetaMethod(const QMetaMethod& method, void** args,
if (!retval.isNull() && retval != Py_None && !PyErr_Occurred()) {
const char* returnType = method.typeName();
if (returnType && std::strcmp("", returnType)) {
- Shiboken::TypeResolver* typeResolver = Shiboken::TypeResolver::get(returnType);
- if (typeResolver)
- typeResolver->toCpp(retval, &args[0]);
+ Shiboken::Conversions::SpecificConverter converter(returnType);
+ if (converter)
+ converter.toCpp(retval, args[0]);
else
- PyErr_Format(PyExc_RuntimeError, "Can't fidn type resolver \"%s\" to call Python meta method.", returnType);
+ PyErr_Format(PyExc_RuntimeError, "Can't find converter for '%s' to call Python meta method.", returnType);
+
}
}
}
@@ -555,13 +578,10 @@ static PyObject* parseArguments(const QList<QByteArray>& paramTypes, void** args
for (int i = 0, max = argsSize; i < max; ++i) {
void* data = args[i+1];
const char* dataType = paramTypes[i].constData();
-
- Shiboken::TypeResolver* tr = Shiboken::TypeResolver::get(dataType);
- if (tr) {
- PyObject* arg = tr->toPython(data);
- PyTuple_SET_ITEM(preparedArgs, i, arg);
+ Shiboken::Conversions::SpecificConverter converter(dataType);
+ if (converter) {
+ PyTuple_SET_ITEM(preparedArgs, i, converter.toPython(data));
} else {
-
PyErr_Format(PyExc_TypeError, "Can't call meta function because I have no idea how to handle %s", dataType);
Py_DECREF(preparedArgs);
return 0;