@@ -1130,6 +1130,35 void PythonQtPrivate::registerCPPClass(const char* typeName, const char* parentT | |||
|
1130 | 1130 | } |
|
1131 | 1131 | } |
|
1132 | 1132 | |
|
1133 | static PyObject *PythonQt_SIGNAL(PyObject * /*type*/, PyObject *args) | |
|
1134 | { | |
|
1135 | const char* value; | |
|
1136 | if (!PyArg_ParseTuple(args, "s", &value)) { | |
|
1137 | return NULL; | |
|
1138 | } | |
|
1139 | // we do not prepend 0,1 or 2, why should we? | |
|
1140 | return PyString_FromString(value); | |
|
1141 | } | |
|
1142 | ||
|
1143 | static PyObject *PythonQt_SLOT(PyObject * /*type*/, PyObject *args) | |
|
1144 | { | |
|
1145 | const char* value; | |
|
1146 | if (!PyArg_ParseTuple(args, "s", &value)) { | |
|
1147 | return NULL; | |
|
1148 | } | |
|
1149 | // we do not prepend 0,1 or 2, why should we? | |
|
1150 | return PyString_FromString(value); | |
|
1151 | } | |
|
1152 | ||
|
1153 | static PyMethodDef PythonQt_Qt_methods[] = { | |
|
1154 | {"SIGNAL", (PyCFunction)PythonQt_SIGNAL, METH_VARARGS, | |
|
1155 | "Returns a signal string" | |
|
1156 | }, | |
|
1157 | {"SLOT", (PyCFunction)PythonQt_SLOT, METH_VARARGS, | |
|
1158 | "Returns a slot string" | |
|
1159 | } | |
|
1160 | }; | |
|
1161 | ||
|
1133 | 1162 | PyObject* PythonQtPrivate::packageByName(const char* name) |
|
1134 | 1163 | { |
|
1135 | 1164 | if (name==NULL || name[0]==0) { |
@@ -1138,6 +1167,11 PyObject* PythonQtPrivate::packageByName(const char* name) | |||
|
1138 | 1167 | PyObject* v = _packages.value(name); |
|
1139 | 1168 | if (!v) { |
|
1140 | 1169 | v = PyImport_AddModule((QByteArray("PythonQt.") + name).constData()); |
|
1170 | if (strcmp(name,"Qt")==0 || strcmp(name,"QtCore")==0) { | |
|
1171 | // add SIGNAL and SLOT functions | |
|
1172 | PyModule_AddObject(v, "SIGNAL", PyCFunction_New(PythonQt_Qt_methods, v)); | |
|
1173 | PyModule_AddObject(v, "SLOT", PyCFunction_New(PythonQt_Qt_methods+1, v)); | |
|
1174 | } | |
|
1141 | 1175 | _packages.insert(name, v); |
|
1142 | 1176 | // AddObject steals the reference, so increment it! |
|
1143 | 1177 | Py_INCREF(v); |
@@ -140,11 +140,13 | |||
|
140 | 140 | |
|
141 | 141 | \section Comparision Comparision with PyQt |
|
142 | 142 | |
|
143 | - 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 | |
|
143 | - 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 | |
|
144 | 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 | 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 (yet?) offer QtCore.SIGNAL() and QtCore.SLOT() methods, connect and disconnect just take strings for signals and slots | |
|
147 | - QObject.emit to emit Qt signals from Python is not yet possible | |
|
146 | - PythonQt offer QtCore.SIGNAL() and QtCore.SLOT() methods for compability, but no 0/1/3 is prepended | |
|
147 | - PythonQt does not support instanceof checks for Qt classes, except for the exact match and derived Python classes | |
|
148 | - QObject.emit to emit Qt signals from Python is not yet implemented | |
|
149 | - PythonQt does not offer to add new signals to Python/C++ objects | |
|
148 | 150 | - 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) |
|
149 | 151 | - Probably there are lots of details that differ, I do not know PyQt that well to list them all. |
|
150 | 152 |
@@ -96,6 +96,15 bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal | |||
|
96 | 96 | return r; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | #undef emit | |
|
100 | void PythonQtStdDecorators::emit(QObject* sender, const QByteArray& signal, PyObject* arg1 ,PyObject* arg2 , | |
|
101 | PyObject* arg3 ,PyObject* arg4 ,PyObject* arg5 ,PyObject* arg6 ,PyObject* arg7 ) | |
|
102 | { | |
|
103 | // TODO xxx | |
|
104 | // use normal PythonQtSlot calling code, add "allowSignal" to member lookup?! | |
|
105 | } | |
|
106 | #define emit | |
|
107 | ||
|
99 | 108 | QObject* PythonQtStdDecorators::parent(QObject* o) { |
|
100 | 109 | return o->parent(); |
|
101 | 110 | } |
@@ -62,6 +62,11 public slots: | |||
|
62 | 62 | bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable); |
|
63 | 63 | bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot); |
|
64 | 64 | |
|
65 | #undef emit | |
|
66 | void emit(QObject* sender, const QByteArray& signal, PyObject* arg1 = NULL,PyObject* arg2 = NULL, | |
|
67 | PyObject* arg3 = NULL,PyObject* arg4 = NULL,PyObject* arg5 = NULL,PyObject* arg6 = NULL,PyObject* arg7 = NULL); | |
|
68 | #define emit | |
|
69 | ||
|
65 | 70 |
|
|
66 | 71 | bool static_QObject_connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) { return connect(sender, signal, receiver, slot); } |
|
67 | 72 | bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable) { return disconnect(sender, signal, callable); } |
General Comments 0
You need to be logged in to leave comments.
Login now