From 1d1e7c03e84834a800b61717b0027da44043cf2d 2009-04-22 15:04:33 From: florianlink Date: 2009-04-22 15:04:33 Subject: [PATCH] - added call method that does a direct call on the ObjectType - added comments and improved docs git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@72 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 2e14bb9..57a3b0a 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -805,11 +805,19 @@ QStringList PythonQt::introspection(PyObject* module, const QString& objectname, return results; } -QVariant PythonQt::call(PyObject* module, const QString& name, const QVariantList& args) +QVariant PythonQt::call(PyObject* object, const QString& name, const QVariantList& args) +{ + PythonQtObjectPtr callable = lookupCallable(object, name); + if (callable) { + return call(callable, args); + } else { + return QVariant(); + } +} + +QVariant PythonQt::call(PyObject* callable, const QVariantList& args) { QVariant r; - - PythonQtObjectPtr callable = lookupCallable(module, name); if (callable) { PythonQtObjectPtr pargs; int count = args.size(); diff --git a/src/PythonQt.h b/src/PythonQt.h index cde8086..d9472de 100644 --- a/src/PythonQt.h +++ b/src/PythonQt.h @@ -228,8 +228,11 @@ public: //@{ Calling of python callables - //! call the given python method, returns the result converted to a QVariant - QVariant call(PyObject* module, const QString& callable, const QVariantList& args = QVariantList()); + //! call the given python \c callable in the scope of object, returns the result converted to a QVariant + QVariant call(PyObject* object, const QString& callable, const QVariantList& args = QVariantList()); + + //! call the given python object, returns the result converted to a QVariant + QVariant call(PyObject* callable, const QVariantList& args = QVariantList()); //@} diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index 2d1df92..dfe6f16 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -718,9 +718,11 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) // c++ wrapper, check if the class names of the c++ objects match if (wrap->classInfo()->isCPPWrapper()) { if (wrap->classInfo()->metaTypeId()>0) { - // construct a new variant from the C++ object if it has a meta type + // construct a new variant from the C++ object if it has a meta type (this will COPY the object!) v = QVariant(wrap->classInfo()->metaTypeId(), wrap->_wrappedPtr); } else { + // TODOXXX we could as well check if there is a registered meta type for "classname*", so that we may pass + // the pointer here... // is this worth anything? we loose the knowledge of the cpp object type v = qVariantFromValue(wrap->_wrappedPtr); } diff --git a/src/PythonQtDoc.h b/src/PythonQtDoc.h index fc248c8..f1b1bc1 100644 --- a/src/PythonQtDoc.h +++ b/src/PythonQtDoc.h @@ -144,6 +144,7 @@ - PythonQt allows to communicate in both directions, e.g. calling a Python object from C++ AND calling a C++ method from Python, while PyQt only handles the Python->C++ direction - PythonQt offers properties as Python attributes, while PyQt offers them as setter/getter methods (e.g. QWidget.width is a property in PythonQt and a method in PyQt) - PythonQt does not auto-convert objects, e.g. when a QPainter expects a QBrush and you pass a QColor, it is rejected, you will need to write QBrush(QColor(1,2,3)) instead + - PythonQt returns/handles enums/flags as integers, which can cause problems on overloads that take ints and enums, a future version might use an own enum type (like PyQt does) - Probably there are lots of details that differ, I do not know PyQt that well to list them all. diff --git a/src/PythonQtObjectPtr.cpp b/src/PythonQtObjectPtr.cpp index 5b66f65..d21e806 100644 --- a/src/PythonQtObjectPtr.cpp +++ b/src/PythonQtObjectPtr.cpp @@ -82,6 +82,11 @@ QVariant PythonQtObjectPtr::call(const QString& callable, const QVariantList& ar return PythonQt::self()->call(_object, callable, args); } +QVariant PythonQtObjectPtr::call(const QVariantList& args) +{ + return PythonQt::self()->call(_object, args); +} + bool PythonQtObjectPtr::fromVariant(const QVariant& variant) { if (!variant.isNull()) { diff --git a/src/PythonQtObjectPtr.h b/src/PythonQtObjectPtr.h index eb88f42..8d53c16 100644 --- a/src/PythonQtObjectPtr.h +++ b/src/PythonQtObjectPtr.h @@ -150,8 +150,8 @@ public: //! call the given python object (in the scope of the current object), returns the result converted to a QVariant QVariant call(const QString& callable, const QVariantList& args = QVariantList()); - - + //! call the contained python object directly, returns the result converted to a QVariant + QVariant call(const QVariantList& args = QVariantList()); protected: