##// END OF EJS Templates
SIGNAL/SLOT methods improved and supported in connect/disconnect...
florianlink -
r62:b7a51b352089
parent child
Show More
@@ -1137,7 +1137,7 static PyObject *PythonQt_SIGNAL(PyObject * /*type*/, PyObject *args)
1137 1137 return NULL;
1138 1138 }
1139 1139 // we do not prepend 0,1 or 2, why should we?
1140 return PyString_FromString(value);
1140 return PyString_FromString(QByteArray("2") + value);
1141 1141 }
1142 1142
1143 1143 static PyObject *PythonQt_SLOT(PyObject * /*type*/, PyObject *args)
@@ -1147,7 +1147,7 static PyObject *PythonQt_SLOT(PyObject * /*type*/, PyObject *args)
1147 1147 return NULL;
1148 1148 }
1149 1149 // we do not prepend 0,1 or 2, why should we?
1150 return PyString_FromString(value);
1150 return PyString_FromString(QByteArray("1") + value);
1151 1151 }
1152 1152
1153 1153 static PyMethodDef PythonQt_Qt_methods[] = {
@@ -143,7 +143,6
143 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 offer QtCore.SIGNAL() and QtCore.SLOT() methods for compability, but no 0/1/3 is prepended
147 146 - PythonQt does not support instanceof checks for Qt classes, except for the exact match and derived Python classes
148 147 - QObject.emit to emit Qt signals from Python is not yet implemented
149 148 - PythonQt does not offer to add new signals to Python/C++ objects
@@ -46,8 +46,14
46 46
47 47 bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, PyObject* callable)
48 48 {
49 QByteArray signalTmp("2");
50 signalTmp += signal;
49 QByteArray signalTmp;
50 char first = signal.at(0);
51 if (first>='0' && first<='9') {
52 signalTmp = signal;
53 } else {
54 signalTmp = "2" + signal;
55 }
56
51 57 if (sender) {
52 58 return PythonQt::self()->addSignalHandler(sender, signalTmp, callable);
53 59 } else {
@@ -59,21 +65,35 bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, Q
59 65 {
60 66 bool r = false;
61 67 if (sender && receiver) {
62 QByteArray signalTmp("2");
63 signalTmp += signal;
64 QByteArray slotTmp("1");
65 slotTmp += slot;
66 if (receiver) {
67 r = QObject::connect(sender, signalTmp, receiver, slotTmp);
68 QByteArray signalTmp;
69 char first = signal.at(0);
70 if (first>='0' && first<='9') {
71 signalTmp = signal;
72 } else {
73 signalTmp = "2" + signal;
68 74 }
75
76 QByteArray slotTmp;
77 first = slot.at(0);
78 if (first>='0' && first<='9') {
79 slotTmp = slot;
80 } else {
81 slotTmp = "1" + slot;
82 }
83 r = QObject::connect(sender, signalTmp, receiver, slotTmp);
69 84 }
70 85 return r;
71 86 }
72 87
73 88 bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal, PyObject* callable)
74 89 {
75 QByteArray signalTmp("2");
76 signalTmp += signal;
90 QByteArray signalTmp;
91 char first = signal.at(0);
92 if (first>='0' && first<='9') {
93 signalTmp = signal;
94 } else {
95 signalTmp = "2" + signal;
96 }
77 97 if (sender) {
78 98 return PythonQt::self()->removeSignalHandler(sender, signalTmp, callable);
79 99 } else {
@@ -85,13 +105,23 bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal
85 105 {
86 106 bool r = false;
87 107 if (sender && receiver) {
88 QByteArray signalTmp("2");
89 signalTmp += signal;
90 QByteArray slotTmp("1");
91 slotTmp += slot;
92 if (receiver) {
93 r = QObject::disconnect(sender, signalTmp, receiver, slotTmp);
108 QByteArray signalTmp;
109 char first = signal.at(0);
110 if (first>='0' && first<='9') {
111 signalTmp = signal;
112 } else {
113 signalTmp = "2" + signal;
94 114 }
115
116 QByteArray slotTmp;
117 first = slot.at(0);
118 if (first>='0' && first<='9') {
119 slotTmp = slot;
120 } else {
121 slotTmp = "1" + slot;
122 }
123
124 r = QObject::disconnect(sender, signalTmp, receiver, slotTmp);
95 125 }
96 126 return r;
97 127 }
General Comments 0
You need to be logged in to leave comments. Login now