1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
// This file contains the C++ code necessary marshal and demarshal
// all the _simple_ types that dcoppython can understand.
// "Simple" types are types that do not contain other types.
// So, int and QString are simple types; QDict, QMap and QStringList are not.
// This file is processed by gen_marshal_code.py to produce a header
// file, which is included by marshaller.cpp
//
// Marshalling:
// The code in the "marshal" section has the following variables available:
// PyObject * obj; // the object to marshal
// QDataStream *str; // the stream to marshal to
// The function should return true if the object can be marshalled.
// str may be NULL. If so, the function should ignore the actually marshalling
// and merely return true or false, depending on whether the object _could_
// be marshalled.
//
// Demarshalling:
// The code in the "demarshal" section has the following variables available:
// QDataStream *str; // the stream to demarshal from
// The function should return a PyObject* which is a reference to the
// newly created object. Ownership of the reference should be passed to
// the caller. The function can return null if for any reason it
// could not demarshal.
type: void
%% marshall
{
Q_UNUSED(str); // stop warnings
Q_UNUSED(obj);
return true;
}
%% demarshal
{
Q_UNUSED(str); // stop warnings
Py_INCREF(Py_None);
return Py_None;
}
type: bool
%doc as int b (1=True, 2=False)
%doc info Any Python object is converted to bool by the standard Python truth test.
%% from_pyobj
{
*ok=true;
return PyObject_IsTrue(obj);
}
%% to_pyobj
{
return PyInt_FromLong(val ? 1 : 0);
}
%% marshal
{
if (str) {
bool ok;
bool b = fromPyObject_bool(obj,&ok);
(*str) << (Q_INT8)b;
}
return true;
}
%% demarshal
{
Q_INT8 i;
(*str) >> i;
return toPyObject_bool(i!=0);
}
%%
type:int
%doc as int i
%% marshal
{
if (!PyInt_Check(obj)) return false;
if (str) {
(*str) << (Q_INT32)PyInt_AsLong(obj);
}
return true;
}
%% demarshal
{
Q_INT32 i;
(*str) >> i;
return PyInt_FromLong( (long)i );
}
%%
type:uint
%doc as int i
%% marshal
{
if (!PyInt_Check(obj)) return false;
if (str) {
(*str) << (Q_INT32)PyInt_AsLong(obj);
}
return true;
}
%% demarshal
{
Q_INT32 i;
(*str) >> i;
return PyInt_FromLong( (long)i );
}
%%
type:double
%doc as float i
%% marshal
{
if (!PyFloat_Check(obj)) return false;
if (str) {
(*str) << PyFloat_AsDouble(obj);
}
return true;
}
%% demarshal
{
double d;
(*str) >> d;
return PyFloat_FromDouble(d);
}
%%
type:uchar
%doc as str c
%doc as int c
%% marshal
{
if (PyString_Check(obj) && PyString_Size(obj)==1) {
if (str) {
char *c = PyString_AsString(obj);
(*str) << (*c);
}
return true;
}
if (PyInt_Check(obj)) {
if (str) {
long l = PyInt_AsLong(obj);
Q_UINT8 c = (Q_UINT8)(l & 0xff);
(*str) << c;
}
return true;
}
return false;
}
%%demarshal
{
Q_UINT8 c;
(*str) >> c;
return PyString_FromStringAndSize((const char *)(&c),1);
}
%%
type:char
%doc as int c
%% marshal
{
if (PyInt_Check(obj)) {
if (str) {
long l = PyInt_AsLong(obj);
Q_INT8 c = (Q_INT8)(l & 0xff);
(*str) << c;
}
return true;
}
return false;
}
%%demarshal
{
Q_INT8 c;
(*str) >> c;
return PyInt_FromLong((long)c);
}
%%
type:QByteArray
%% marshal
{
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
if ( pb && pb->bf_getreadbuffer && pb->bf_getsegcount )
{
// Get the number of buffer segments
int seg_count = (pb->bf_getsegcount)(obj, 0);
if ( seg_count != 1 )
// Can't handle more (or less) than 1 buffer segment
// at the moment
return false;
// Get buffer size and data
void *data;
int size;
if ( (size = (pb->bf_getreadbuffer)(obj, 0, &data)) < 0 )
return false;
if (str) {
QByteArray a;
a.setRawData( (const char*)data, size );
(*str) << a;
a.resetRawData( (const char*)data, size );
}
return true;
}
else
// obj does not implement the buffer interface
return false;
}
%% demarshal
{
// Demarshal to a writable buffer object
QByteArray a;
(*str) >> a;
uint size = a.size();
char *data = a.data();
// Create a new buffer object and copy the data.
// Don't use PyBuffer_FromMemory() and the likes since
// that wouldn't give correct allocation and deallocation.
PyObject *buffer_obj = PyBuffer_New( size );
if ( !buffer_obj )
return NULL;
PyBufferProcs *pb = buffer_obj->ob_type->tp_as_buffer;
void *buffer_data;
(pb->bf_getwritebuffer)( buffer_obj, 0, &buffer_data );
for ( uint i = 0; i < size; i++ )
((char*)buffer_data)[i] = data[i];
return buffer_obj;
}
%%
type:QString
%doc as str s
%% marshal
{
if (!PyString_Check(obj)) return false;
if (str) {
QString s( PyString_AsString(obj) );
(*str) << s;
}
return true;
}
%% demarshal
{
QString s;
(*str) >> s;
return PyString_FromString( s.utf8().data() );
}
%%
type:QCString
%doc as str s
%% marshal
{
if (!PyString_Check(obj)) return false;
if (str) {
QCString s( PyString_AsString(obj) );
(*str) << s;
}
return true;
}
%% demarshal
{
QCString s;
(*str) >> s;
return PyString_FromString( s.data() );
}
%%
type:QRect
%doc as ( (int x1, int y1), (int x2, int y2) )
%doc as ( int x1, int y1, int x2, int y2 )
%% from_pyobj
{
int xp1, yp1, xp2, yp2;
QRect r;
*ok=false;
if (!PyTuple_Check(obj)) return r;
if (!PyArg_ParseTuple(obj, (char*)"(ii)(ii)", &xp1, &yp1, &xp2, &yp2) &&
!PyArg_ParseTuple(obj, (char*)"iiii", &xp1, &yp1, &xp2, &yp2))
return r;
r.setCoords( xp1, yp1, xp2, yp2 );
*ok=true;
return r;
}
%% to_pyobj
{
int xp1, yp1, xp2, yp2;
val.coords(&xp1,&yp1,&xp2,&yp2);
return Py_BuildValue((char*)"(ii)(ii)", xp1, yp1, xp2, yp2);
}
%% marshal
%defaultcode
%% demarshal
%defaultcode
%%
type:QPoint
%doc as (int x, int y)
%% from_pyobj
{
int x,y;
QPoint p;
*ok=false;
if (!PyTuple_Check(obj)) return p;
if (!PyArg_ParseTuple(obj, (char*)"ii", &x, &y))
return p;
p.setX(x);
p.setY(y);
*ok=true;
return p;
}
%% to_pyobj
{
return Py_BuildValue((char*)"ii", val.x(), val.y() );
}
%% marshall
%defaultcode
%% demarshall
%defaultcode
%%
type:QSize
%doc as (int width, int height)
%% from_pyobj
{
int w,h;
QSize sz;
*ok=false;
if (!PyTuple_Check(obj)) return sz;
if (!PyArg_ParseTuple(obj, (char*)"ii", &w, &h))
return sz;
sz.setWidth(w);
sz.setHeight(h);
*ok=true;
return sz;
}
%% to_pyobj
{
return Py_BuildValue((char*)"ii", val.width(), val.height() );
}
%% marshall
%defaultcode
%% demarshall
%defaultcode
%%
type:QColor
%doc as (int red, int green, int blue)
%% from_pyobj
{
int r,g,b;
QColor c;
*ok=false;
if (!PyTuple_Check(obj)) return c;
if (!PyArg_ParseTuple(obj, (char*)"iii", &r, &g, &b))
return c;
c.setRgb(r,g,b);
*ok=true;
return c;
}
%% to_pyobj
{
return Py_BuildValue((char*)"iii", val.red(), val.green(), val.blue() );
}
%% marshall
%defaultcode
%% demarshall
%defaultcode
%%
type:QPointArray
%doc as [ (int x, int y), (int x, int y), (int x, int y), ... ]
%% from_pyobj
{
*ok=false;
if (!PyList_Check(obj)) return QPointArray();
int size = PyList_Size(obj);
QPointArray pa(size);
for(int c=0;c<size;c++) {
QPoint p = fromPyObject_QPoint(PyList_GetItem(obj,c), ok);
if (!*ok) return false;
pa.setPoint(c,p);
}
*ok=true;
return pa;
}
%% to_pyobj
{
PyObject *obj = PyList_New(val.size());
if (!obj) return NULL;
for(uint c=0;c<val.size();c++) {
PyObject *tuple = toPyObject_QPoint( val.point(c) );
PyList_SetItem(obj, c, tuple);
// Py_DECREF(tuple);
}
return obj;
}
%% marshall
%defaultcode
%% demarshall
%defaultcode
%%
type:QDate
%doc as (int year, int month, int day)
%% from_pyobj
{
*ok=false;
if (!PyTuple_Check(obj)) return QDate();
int y,m,d;
if (!PyArg_ParseTuple(obj, (char*)"iii", &y, &m, &d))
return QDate();
*ok=true;
return QDate(y,m,d);
}
%% to_pyobj
{
return Py_BuildValue((char*)"iii", val.year(), val.month(), val.day() );
}
%% marshal
%defaultcode
%% demarshal
%defaultcode
%%
type:QTime
%doc as (int hour, int minute, int second=0, int millisecond=0)
%% from_pyobj
{
*ok=false;
if (!PyTuple_Check(obj)) return QTime();
int h,m,s=0,ms=0;
if (!PyArg_ParseTuple(obj, (char*)"ii|ii", &h, &m, &s, &ms))
return QTime();
*ok=true;
return QTime(h,m,s,ms);
}
%% to_pyobj
{
return Py_BuildValue((char*)"iiii", val.hour(), val.minute(), val.second(), val.msec() );
}
%% marshal
%defaultcode
%% demarshal
%defaultcode
%%
type:QDateTime
%doc as ( (int year, int month, int day), (int hour, int minute, int second=0, int millsecond=0) )
%doc as long unixDate
%% from_pyobj
{
*ok=false;
if (PyLong_Check(obj)) {
*ok=true;
QDateTime dt;
dt.setTime_t( (uint)PyLong_AsLong(obj) );
return dt;
}
if (PyInt_Check(obj)) {
*ok=true;
QDateTime dt;
dt.setTime_t( (uint)PyInt_AsLong(obj) );
return dt;
}
PyObject *date_tuple, *time_tuple;
if (PyArg_ParseTuple(obj, (char*)"OO", &date_tuple, &time_tuple)) {
QDateTime dt;
dt.setTime( fromPyObject_QTime(time_tuple, ok) );
if (*ok) dt.setDate( fromPyObject_QDate(date_tuple, ok) );
return dt;
}
return QDateTime();
}
%% to_pyobj
{
PyObject *date_tuple = toPyObject_QDate( val.date() );
PyObject *time_tuple = toPyObject_QTime( val.time() );
return Py_BuildValue((char*)"OO", date_tuple, time_tuple );
}
%% marshal
%defaultcode
%% demarshal
%defaultcode
%%
type:KURL
%doc as str url
%% from_pyobj
{
*ok=false;
if (!PyString_Check(obj)) return KURL();
*ok=true;
return KURL( QString(PyString_AsString(obj)) );
}
%% to_pyobj
{
return PyString_FromString( val.prettyURL().utf8().data() );
}
%% marshal
%defaultcode
%% demarshal
%defaultcode
%%
type:DCOPRef
%% from_pyobj
{
if (PyInstance_Check(obj) &&
PyObject_HasAttrString(obj, (char*)"appname") &&
PyObject_HasAttrString(obj, (char*)"name")) {
PyObject *appname = PyObject_GetAttrString(obj, (char*)"appname");
PyObject *name = PyObject_GetAttrString(obj, (char*)"name");
if (PyString_Check(appname) && PyString_Check(name)) {
char *c_appname = PyString_AsString(appname);
char *c_name = PyString_AsString(name);
DCOPRef ref;
ref.setRef(QCString(c_appname), QCString(c_name) );
Py_DECREF(appname);
Py_DECREF(name);
*ok=true;
return ref;
}
Py_DECREF(appname);
Py_DECREF(name);
}
*ok=false;
return DCOPRef();
}
%% to_pyobj
{
if (val.isNull()) {
Py_INCREF(Py_None);
return Py_None;
}
return ImportedModules::instance()->createDCOPObject(val.app(), val.object() );
}
%% marshal
%defaultcode
%% demarshal
%defaultcode
%%
// type:DCOPRef
// %doc as (str app, str obj, str type)
// %doc as (str app, str obj)
// %% from_pyobj
// {
// *ok=false;
// char *dcopref_app=NULL, *dcopref_obj=NULL, *dcopref_type=NULL;
// if (PyArg_ParseTuple(obj,(char*)"ss|s", &dcopref_app, &dcopref_obj, &dcopref_type)) {
// *ok=true;
// if (dcopref_type) {
// DCOPRef dr(QCString(dcopref_app), QCString(dcopref_obj), QCString(dcopref_type));
// return dr;
// }
// DCOPRef dr(QCString(dcopref_app), QCString(dcopref_obj));
// return dr;
// }
// return DCOPRef();
// }
// %% to_pyobj
// {
// return Py_BuildValue((char*)"sss", val.app().data(), val.obj().data(), val.type().data() );
// }
// %% marshal
// %defaultcode
// %% demarshal
// %defaultcode
// %%
// type:QFont
// %% marshal
// %constructor ("default")
// %dict-map family:string,rawName:string
// %% demarshal
// %dict-map
// %%
|