##// END OF EJS Templates
- added call method that does a direct call on the ObjectType...
florianlink -
r36:1d1e7c03e848
parent child
Show More
@@ -805,11 +805,19 QStringList PythonQt::introspection(PyObject* module, const QString& objectname,
805 return results;
805 return results;
806 }
806 }
807
807
808 QVariant PythonQt::call(PyObject* module, const QString& name, const QVariantList& args)
808 QVariant PythonQt::call(PyObject* object, const QString& name, const QVariantList& args)
809 {
810 PythonQtObjectPtr callable = lookupCallable(object, name);
811 if (callable) {
812 return call(callable, args);
813 } else {
814 return QVariant();
815 }
816 }
817
818 QVariant PythonQt::call(PyObject* callable, const QVariantList& args)
809 {
819 {
810 QVariant r;
820 QVariant r;
811
812 PythonQtObjectPtr callable = lookupCallable(module, name);
813 if (callable) {
821 if (callable) {
814 PythonQtObjectPtr pargs;
822 PythonQtObjectPtr pargs;
815 int count = args.size();
823 int count = args.size();
@@ -228,8 +228,11 public:
228
228
229 //@{ Calling of python callables
229 //@{ Calling of python callables
230
230
231 //! call the given python method, returns the result converted to a QVariant
231 //! call the given python \c callable in the scope of object, returns the result converted to a QVariant
232 QVariant call(PyObject* module, const QString& callable, const QVariantList& args = QVariantList());
232 QVariant call(PyObject* object, const QString& callable, const QVariantList& args = QVariantList());
233
234 //! call the given python object, returns the result converted to a QVariant
235 QVariant call(PyObject* callable, const QVariantList& args = QVariantList());
233
236
234 //@}
237 //@}
235
238
@@ -718,9 +718,11 QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
718 // c++ wrapper, check if the class names of the c++ objects match
718 // c++ wrapper, check if the class names of the c++ objects match
719 if (wrap->classInfo()->isCPPWrapper()) {
719 if (wrap->classInfo()->isCPPWrapper()) {
720 if (wrap->classInfo()->metaTypeId()>0) {
720 if (wrap->classInfo()->metaTypeId()>0) {
721 // construct a new variant from the C++ object if it has a meta type
721 // construct a new variant from the C++ object if it has a meta type (this will COPY the object!)
722 v = QVariant(wrap->classInfo()->metaTypeId(), wrap->_wrappedPtr);
722 v = QVariant(wrap->classInfo()->metaTypeId(), wrap->_wrappedPtr);
723 } else {
723 } else {
724 // TODOXXX we could as well check if there is a registered meta type for "classname*", so that we may pass
725 // the pointer here...
724 // is this worth anything? we loose the knowledge of the cpp object type
726 // is this worth anything? we loose the knowledge of the cpp object type
725 v = qVariantFromValue(wrap->_wrappedPtr);
727 v = qVariantFromValue(wrap->_wrappedPtr);
726 }
728 }
@@ -144,6 +144,7
144 - 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
144 - 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
145 - 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)
145 - 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)
146 - 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
146 - 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
147 - 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)
147 - Probably there are lots of details that differ, I do not know PyQt that well to list them all.
148 - Probably there are lots of details that differ, I do not know PyQt that well to list them all.
148
149
149
150
@@ -82,6 +82,11 QVariant PythonQtObjectPtr::call(const QString& callable, const QVariantList& ar
82 return PythonQt::self()->call(_object, callable, args);
82 return PythonQt::self()->call(_object, callable, args);
83 }
83 }
84
84
85 QVariant PythonQtObjectPtr::call(const QVariantList& args)
86 {
87 return PythonQt::self()->call(_object, args);
88 }
89
85 bool PythonQtObjectPtr::fromVariant(const QVariant& variant)
90 bool PythonQtObjectPtr::fromVariant(const QVariant& variant)
86 {
91 {
87 if (!variant.isNull()) {
92 if (!variant.isNull()) {
@@ -150,8 +150,8 public:
150 //! call the given python object (in the scope of the current object), returns the result converted to a QVariant
150 //! call the given python object (in the scope of the current object), returns the result converted to a QVariant
151 QVariant call(const QString& callable, const QVariantList& args = QVariantList());
151 QVariant call(const QString& callable, const QVariantList& args = QVariantList());
152
152
153
153 //! call the contained python object directly, returns the result converted to a QVariant
154
154 QVariant call(const QVariantList& args = QVariantList());
155
155
156 protected:
156 protected:
157
157
General Comments 0
You need to be logged in to leave comments. Login now