From d314d06796c4f1bde9007eebb5a50035c0997b8c 2009-05-25 14:22:00 From: florianlink Date: 2009-05-25 14:22:00 Subject: [PATCH] added static connect/disconnect and dummy emit implementation, added dummy SIGNAL/SLOT functions to namespace git-svn-id: svn://svn.code.sf.net/p/pythonqt/code/trunk@97 ea8d5007-eb21-0410-b261-ccb3ea6e24a9 --- diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 841efcf..6897c9f 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -1130,6 +1130,35 @@ void PythonQtPrivate::registerCPPClass(const char* typeName, const char* parentT } } +static PyObject *PythonQt_SIGNAL(PyObject * /*type*/, PyObject *args) +{ + const char* value; + if (!PyArg_ParseTuple(args, "s", &value)) { + return NULL; + } + // we do not prepend 0,1 or 2, why should we? + return PyString_FromString(value); +} + +static PyObject *PythonQt_SLOT(PyObject * /*type*/, PyObject *args) +{ + const char* value; + if (!PyArg_ParseTuple(args, "s", &value)) { + return NULL; + } + // we do not prepend 0,1 or 2, why should we? + return PyString_FromString(value); +} + +static PyMethodDef PythonQt_Qt_methods[] = { +{"SIGNAL", (PyCFunction)PythonQt_SIGNAL, METH_VARARGS, +"Returns a signal string" +}, +{"SLOT", (PyCFunction)PythonQt_SLOT, METH_VARARGS, +"Returns a slot string" +} +}; + PyObject* PythonQtPrivate::packageByName(const char* name) { if (name==NULL || name[0]==0) { @@ -1138,6 +1167,11 @@ PyObject* PythonQtPrivate::packageByName(const char* name) PyObject* v = _packages.value(name); if (!v) { v = PyImport_AddModule((QByteArray("PythonQt.") + name).constData()); + if (strcmp(name,"Qt")==0 || strcmp(name,"QtCore")==0) { + // add SIGNAL and SLOT functions + PyModule_AddObject(v, "SIGNAL", PyCFunction_New(PythonQt_Qt_methods, v)); + PyModule_AddObject(v, "SLOT", PyCFunction_New(PythonQt_Qt_methods+1, v)); + } _packages.insert(name, v); // AddObject steals the reference, so increment it! Py_INCREF(v); diff --git a/src/PythonQtDoc.h b/src/PythonQtDoc.h index f51dda3..71fb754 100644 --- a/src/PythonQtDoc.h +++ b/src/PythonQtDoc.h @@ -140,11 +140,13 @@ \section Comparision Comparision with PyQt - - PythonQt is not as Pythonic as PyQt in many details (e.g. operator mapping, pickling, translation support, ...) and it is maily thought for embedding and intercommunication between Qt/Cpp and Python + - PythonQt is not as Pythonic as PyQt in many details (e.g. operator mapping, pickling, translation support, ...) and it is mainly thought for embedding and intercommunication between Qt/Cpp and Python - 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 (yet?) offer QtCore.SIGNAL() and QtCore.SLOT() methods, connect and disconnect just take strings for signals and slots - - QObject.emit to emit Qt signals from Python is not yet possible + - PythonQt offer QtCore.SIGNAL() and QtCore.SLOT() methods for compability, but no 0/1/3 is prepended + - PythonQt does not support instanceof checks for Qt classes, except for the exact match and derived Python classes + - QObject.emit to emit Qt signals from Python is not yet implemented + - PythonQt does not offer to add new signals to Python/C++ objects - Ownership of objects is a bit different in PythonQt, currently Python classes derived from a C++ class need to be manually references in PythonQt to not get deleted too early (this will be fixed) - Probably there are lots of details that differ, I do not know PyQt that well to list them all. diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index 145496b..fe111b6 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -96,6 +96,15 @@ bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal return r; } +#undef emit +void PythonQtStdDecorators::emit(QObject* sender, const QByteArray& signal, PyObject* arg1 ,PyObject* arg2 , + PyObject* arg3 ,PyObject* arg4 ,PyObject* arg5 ,PyObject* arg6 ,PyObject* arg7 ) +{ + // TODO xxx + // use normal PythonQtSlot calling code, add "allowSignal" to member lookup?! +} +#define emit + QObject* PythonQtStdDecorators::parent(QObject* o) { return o->parent(); } diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h index de97161..57c94e4 100644 --- a/src/PythonQtStdDecorators.h +++ b/src/PythonQtStdDecorators.h @@ -62,6 +62,11 @@ public slots: bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable); bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot); +#undef emit + void emit(QObject* sender, const QByteArray& signal, PyObject* arg1 = NULL,PyObject* arg2 = NULL, + PyObject* arg3 = NULL,PyObject* arg4 = NULL,PyObject* arg5 = NULL,PyObject* arg6 = NULL,PyObject* arg7 = NULL); +#define emit + bool static_QObject_connect(QObject* sender, const QByteArray& signal, PyObject* callable) { return connect(sender, signal, callable); } bool static_QObject_connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) { return connect(sender, signal, receiver, slot); } bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable) { return disconnect(sender, signal, callable); }