##// END OF EJS Templates
added QObject tr decorator...
florianlink -
r68:544aa98d116b
parent child
Show More
@@ -1,155 +1,161
1 1 /*
2 2 *
3 3 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
4 4 *
5 5 * This library is free software; you can redistribute it and/or
6 6 * modify it under the terms of the GNU Lesser General Public
7 7 * License as published by the Free Software Foundation; either
8 8 * version 2.1 of the License, or (at your option) any later version.
9 9 *
10 10 * This library is distributed in the hope that it will be useful,
11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 13 * Lesser General Public License for more details.
14 14 *
15 15 * Further, this software is distributed without any warranty that it is
16 16 * free of the rightful claim of any third person regarding infringement
17 17 * or the like. Any license provided herein, whether implied or
18 18 * otherwise, applies only to this software file. Patent licenses, if
19 19 * any, provided herein do not apply to combinations of this program with
20 20 * other software, or any other product whatsoever.
21 21 *
22 22 * You should have received a copy of the GNU Lesser General Public
23 23 * License along with this library; if not, write to the Free Software
24 24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 25 *
26 26 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
27 27 * 28359 Bremen, Germany or:
28 28 *
29 29 * http://www.mevis.de
30 30 *
31 31 */
32 32
33 33 //----------------------------------------------------------------------------------
34 34 /*!
35 35 // \file PythonQtStdDecorators.cpp
36 36 // \author Florian Link
37 37 // \author Last changed by $Author: florian $
38 38 // \date 2007-04
39 39 */
40 40 //----------------------------------------------------------------------------------
41 41
42 42 #include "PythonQtStdDecorators.h"
43 43 #include "PythonQt.h"
44 44 #include "PythonQtClassInfo.h"
45
45 #include <QCoreApplication>
46 46
47 47 bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, PyObject* callable)
48 48 {
49 49 QByteArray signalTmp;
50 50 char first = signal.at(0);
51 51 if (first>='0' && first<='9') {
52 52 signalTmp = signal;
53 53 } else {
54 54 signalTmp = "2" + signal;
55 55 }
56 56
57 57 if (sender) {
58 58 return PythonQt::self()->addSignalHandler(sender, signalTmp, callable);
59 59 } else {
60 60 return false;
61 61 }
62 62 }
63 63
64 64 bool PythonQtStdDecorators::connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot)
65 65 {
66 66 bool r = false;
67 67 if (sender && receiver) {
68 68 QByteArray signalTmp;
69 69 char first = signal.at(0);
70 70 if (first>='0' && first<='9') {
71 71 signalTmp = signal;
72 72 } else {
73 73 signalTmp = "2" + signal;
74 74 }
75 75
76 76 QByteArray slotTmp;
77 77 first = slot.at(0);
78 78 if (first>='0' && first<='9') {
79 79 slotTmp = slot;
80 80 } else {
81 81 slotTmp = "1" + slot;
82 82 }
83 83 r = QObject::connect(sender, signalTmp, receiver, slotTmp);
84 84 }
85 85 return r;
86 86 }
87 87
88 88 bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal, PyObject* callable)
89 89 {
90 90 QByteArray signalTmp;
91 91 char first = signal.at(0);
92 92 if (first>='0' && first<='9') {
93 93 signalTmp = signal;
94 94 } else {
95 95 signalTmp = "2" + signal;
96 96 }
97 97 if (sender) {
98 98 return PythonQt::self()->removeSignalHandler(sender, signalTmp, callable);
99 99 } else {
100 100 return false;
101 101 }
102 102 }
103 103
104 104 bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot)
105 105 {
106 106 bool r = false;
107 107 if (sender && receiver) {
108 108 QByteArray signalTmp;
109 109 char first = signal.at(0);
110 110 if (first>='0' && first<='9') {
111 111 signalTmp = signal;
112 112 } else {
113 113 signalTmp = "2" + signal;
114 114 }
115 115
116 116 QByteArray slotTmp;
117 117 first = slot.at(0);
118 118 if (first>='0' && first<='9') {
119 119 slotTmp = slot;
120 120 } else {
121 121 slotTmp = "1" + slot;
122 122 }
123 123
124 124 r = QObject::disconnect(sender, signalTmp, receiver, slotTmp);
125 125 }
126 126 return r;
127 127 }
128 128
129 129 #undef emit
130 130 void PythonQtStdDecorators::emit(QObject* sender, const QByteArray& signal, PyObject* arg1 ,PyObject* arg2 ,
131 131 PyObject* arg3 ,PyObject* arg4 ,PyObject* arg5 ,PyObject* arg6 ,PyObject* arg7 )
132 132 {
133 133 // TODO xxx
134 134 // use normal PythonQtSlot calling code, add "allowSignal" to member lookup?!
135 135 }
136 136 #define emit
137 137
138 138 QObject* PythonQtStdDecorators::parent(QObject* o) {
139 139 return o->parent();
140 140 }
141 141
142 142 void PythonQtStdDecorators::setParent(QObject* o, QObject* parent)
143 143 {
144 144 o->setParent(parent);
145 145 }
146 146
147 147 QVariantList PythonQtStdDecorators::children(QObject* o)
148 148 {
149 149 QVariantList v;
150 150 QListIterator<QObject*> it(o->children());
151 151 while (it.hasNext()) {
152 152 v << qVariantFromValue(it.next());
153 153 }
154 154 return v;
155 155 }
156
157 QString PythonQtStdDecorators::tr(QObject* obj, const QByteArray& text, const QByteArray& ambig, int n)
158 {
159 return QCoreApplication::translate(obj->metaObject()->className(), text.constData(), ambig.constData(), QCoreApplication::CodecForTr, n);
160 }
161
@@ -1,101 +1,103
1 1 #ifndef _PYTHONQTSTDDECORATORS_H
2 2 #define _PYTHONQTSTDDECORATORS_H
3 3
4 4 /*
5 5 *
6 6 * Copyright (C) 2006 MeVis Research GmbH All Rights Reserved.
7 7 *
8 8 * This library is free software; you can redistribute it and/or
9 9 * modify it under the terms of the GNU Lesser General Public
10 10 * License as published by the Free Software Foundation; either
11 11 * version 2.1 of the License, or (at your option) any later version.
12 12 *
13 13 * This library is distributed in the hope that it will be useful,
14 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 16 * Lesser General Public License for more details.
17 17 *
18 18 * Further, this software is distributed without any warranty that it is
19 19 * free of the rightful claim of any third person regarding infringement
20 20 * or the like. Any license provided herein, whether implied or
21 21 * otherwise, applies only to this software file. Patent licenses, if
22 22 * any, provided herein do not apply to combinations of this program with
23 23 * other software, or any other product whatsoever.
24 24 *
25 25 * You should have received a copy of the GNU Lesser General Public
26 26 * License along with this library; if not, write to the Free Software
27 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 28 *
29 29 * Contact information: MeVis Research GmbH, Universitaetsallee 29,
30 30 * 28359 Bremen, Germany or:
31 31 *
32 32 * http://www.mevis.de
33 33 *
34 34 */
35 35
36 36 //----------------------------------------------------------------------------------
37 37 /*!
38 38 // \file PythonQtStdDecorators.h
39 39 // \author Florian Link
40 40 // \author Last changed by $Author: florian $
41 41 // \date 2007-04
42 42 */
43 43 //----------------------------------------------------------------------------------
44 44
45 45 #include "PythonQtSystem.h"
46 46 #include <Python.h>
47 47 #include <QObject>
48 48 #include <QVariantList>
49 49 #include <QTextDocument>
50 50 #include <QColor>
51 51 #include <QDateTime>
52 52 #include <QDate>
53 53 #include <QTime>
54 54
55 55 class PYTHONQT_EXPORT PythonQtStdDecorators : public QObject
56 56 {
57 57 Q_OBJECT
58 58
59 59 public slots:
60 60 bool connect(QObject* sender, const QByteArray& signal, PyObject* callable);
61 61 bool connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot);
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 65 #undef emit
66 66 void emit(QObject* sender, const QByteArray& signal, PyObject* arg1 = NULL,PyObject* arg2 = NULL,
67 67 PyObject* arg3 = NULL,PyObject* arg4 = NULL,PyObject* arg5 = NULL,PyObject* arg6 = NULL,PyObject* arg7 = NULL);
68 68 #define emit
69 69
70 70 QObject* parent(QObject* o);
71 71 void setParent(QObject* o, QObject* parent);
72 72
73 73 QVariantList children(QObject* o);
74 74
75 75 double static_Qt_qAbs(double a) { return qAbs(a); }
76 76 double static_Qt_qBound(double a,double b,double c) { return qBound(a,b,c); }
77 77 void static_Qt_qDebug(const QByteArray& msg) { qDebug(msg.constData()); }
78 78 // TODO: multi arg qDebug...
79 79 void static_Qt_qWarning(const QByteArray& msg) { qWarning(msg.constData()); }
80 80 // TODO: multi arg qWarning...
81 81 void static_Qt_qCritical(const QByteArray& msg) { qCritical(msg.constData()); }
82 82 // TODO: multi arg qCritical...
83 83 void static_Qt_qFatal(const QByteArray& msg) { qFatal(msg.constData()); }
84 84 // TODO: multi arg qFatal...
85 85 bool static_Qt_qFuzzyCompare(double a, double b) { return qFuzzyCompare(a, b); }
86 86 double static_Qt_qMax(double a, double b) { return qMax(a, b); }
87 87 double static_Qt_qMin(double a, double b) { return qMin(a, b); }
88 88 int static_Qt_qRound(double a) { return qRound(a); }
89 89 qint64 static_Qt_qRound64(double a) { return qRound64(a); }
90 90 const char* static_Qt_qVersion() { return qVersion(); }
91 91 int static_Qt_qrand() { return qrand(); }
92 92 void static_Qt_qsrand(uint a) { qsrand(a); }
93 93
94 QString tr(QObject* obj, const QByteArray& text, const QByteArray& text = QByteArray(), int n = -1);
95
94 96 QByteArray static_Qt_SIGNAL(const QByteArray& s) { return QByteArray("2") + s; }
95 97 QByteArray static_Qt_SLOT(const QByteArray& s) { return QByteArray("1") + s; }
96 98
97 99 //TODO: add findChild/findChildren/children/...
98 100 };
99 101
100 102
101 103 #endif
General Comments 0
You need to be logged in to leave comments. Login now