|
@@
-301,8
+301,9
static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name)
|
|
301
|
break;
|
|
301
|
break;
|
|
302
|
case PythonQtMemberInfo::NotFound:
|
|
302
|
case PythonQtMemberInfo::NotFound:
|
|
303
|
{
|
|
303
|
{
|
|
304
|
// check for a getter_
|
|
304
|
static const QByteArray getterString("py_get_");
|
|
305
|
PythonQtMemberInfo member = wrapper->classInfo()->member(QByteArray("getter_") + attributeName);
|
|
305
|
// check for a getter slot
|
|
|
|
|
306
|
PythonQtMemberInfo member = wrapper->classInfo()->member(getterString + attributeName);
|
|
306
|
if (member._type == PythonQtMemberInfo::Slot) {
|
|
307
|
if (member._type == PythonQtMemberInfo::Slot) {
|
|
307
|
return PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, NULL, NULL, wrapper->_wrappedPtr);
|
|
308
|
return PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, NULL, NULL, wrapper->_wrappedPtr);
|
|
308
|
}
|
|
309
|
}
|
|
@@
-393,8
+394,9
static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec
|
|
393
|
} else if (member._type == PythonQtMemberInfo::EnumWrapper) {
|
|
394
|
} else if (member._type == PythonQtMemberInfo::EnumWrapper) {
|
|
394
|
error = QString("Enum '") + attributeName + "' can not be overwritten on " + obj->ob_type->tp_name + " object";
|
|
395
|
error = QString("Enum '") + attributeName + "' can not be overwritten on " + obj->ob_type->tp_name + " object";
|
|
395
|
} else if (member._type == PythonQtMemberInfo::NotFound) {
|
|
396
|
} else if (member._type == PythonQtMemberInfo::NotFound) {
|
|
396
|
// check for a setter_
|
|
397
|
// check for a setter slot
|
|
397
|
PythonQtMemberInfo setter = wrapper->classInfo()->member(QByteArray("setter_") + attributeName);
|
|
398
|
static const QByteArray setterString("py_set_");
|
|
|
|
|
399
|
PythonQtMemberInfo setter = wrapper->classInfo()->member(setterString + attributeName);
|
|
398
|
if (setter._type == PythonQtMemberInfo::Slot) {
|
|
400
|
if (setter._type == PythonQtMemberInfo::Slot) {
|
|
399
|
// call the setter and ignore the result value
|
|
401
|
// call the setter and ignore the result value
|
|
400
|
void* result;
|
|
402
|
void* result;
|
|
@@
-438,16
+440,39
static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec
|
|
438
|
return -1;
|
|
440
|
return -1;
|
|
439
|
}
|
|
441
|
}
|
|
440
|
|
|
442
|
|
|
|
|
|
443
|
static QString getStringFromObject(PythonQtInstanceWrapper* wrapper) {
|
|
|
|
|
444
|
QString result;
|
|
|
|
|
445
|
if (wrapper->_wrappedPtr) {
|
|
|
|
|
446
|
// first try some manually string conversions for some variants
|
|
|
|
|
447
|
int metaid = wrapper->classInfo()->metaTypeId();
|
|
|
|
|
448
|
result = PythonQtConv::CPPObjectToString(metaid, wrapper->_wrappedPtr);
|
|
|
|
|
449
|
if (!result.isEmpty()) {
|
|
|
|
|
450
|
return result;
|
|
|
|
|
451
|
}
|
|
|
|
|
452
|
}
|
|
|
|
|
453
|
// next, try to call py_toString
|
|
|
|
|
454
|
PythonQtMemberInfo info = wrapper->classInfo()->member("py_toString");
|
|
|
|
|
455
|
if (info._type == PythonQtMemberInfo::Slot) {
|
|
|
|
|
456
|
PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, info._slot, NULL, NULL, wrapper->_wrappedPtr);
|
|
|
|
|
457
|
if (resultObj) {
|
|
|
|
|
458
|
// TODO this is one conversion too much, would be nicer to call the slot directly...
|
|
|
|
|
459
|
result = PythonQtConv::PyObjGetString(resultObj);
|
|
|
|
|
460
|
Py_DECREF(resultObj);
|
|
|
|
|
461
|
}
|
|
|
|
|
462
|
}
|
|
|
|
|
463
|
return result;
|
|
|
|
|
464
|
}
|
|
|
|
|
465
|
|
|
441
|
static PyObject * PythonQtInstanceWrapper_str(PyObject * obj)
|
|
466
|
static PyObject * PythonQtInstanceWrapper_str(PyObject * obj)
|
|
442
|
{
|
|
467
|
{
|
|
443
|
PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
|
|
468
|
PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj;
|
|
444
|
const char* typeName = obj->ob_type->tp_name;
|
|
469
|
const char* typeName = obj->ob_type->tp_name;
|
|
445
|
QObject *qobj = wrapper->_obj;
|
|
470
|
QObject *qobj = wrapper->_obj;
|
|
446
|
if (wrapper->_wrappedPtr) {
|
|
471
|
QString str = getStringFromObject(wrapper);
|
|
447
|
QString str = PythonQtConv::CPPObjectToString(wrapper->classInfo()->metaTypeId(), wrapper->_wrappedPtr);
|
|
|
|
|
448
|
if (!str.isEmpty()) {
|
|
472
|
if (!str.isEmpty()) {
|
|
449
|
return PyString_FromFormat("%s", str.toLatin1().constData());
|
|
473
|
return PyString_FromFormat("%s", str.toLatin1().constData());
|
|
450
|
} else
|
|
474
|
}
|
|
|
|
|
475
|
if (wrapper->_wrappedPtr) {
|
|
451
|
if (wrapper->_obj) {
|
|
476
|
if (wrapper->_obj) {
|
|
452
|
return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", typeName, wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
|
|
477
|
return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", typeName, wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
|
|
453
|
} else {
|
|
478
|
} else {
|
|
@@
-464,11
+489,15
static PyObject * PythonQtInstanceWrapper_repr(PyObject * obj)
|
|
464
|
const char* typeName = obj->ob_type->tp_name;
|
|
489
|
const char* typeName = obj->ob_type->tp_name;
|
|
465
|
|
|
490
|
|
|
466
|
QObject *qobj = wrapper->_obj;
|
|
491
|
QObject *qobj = wrapper->_obj;
|
|
467
|
if (wrapper->_wrappedPtr) {
|
|
492
|
QString str = getStringFromObject(wrapper);
|
|
468
|
QString str = PythonQtConv::CPPObjectToString(wrapper->classInfo()->metaTypeId(), wrapper->_wrappedPtr);
|
|
|
|
|
469
|
if (!str.isEmpty()) {
|
|
493
|
if (!str.isEmpty()) {
|
|
|
|
|
494
|
if (str.startsWith(typeName)) {
|
|
|
|
|
495
|
return PyString_FromFormat("%s", str.toLatin1().constData());
|
|
|
|
|
496
|
} else {
|
|
470
|
return PyString_FromFormat("%s(%s, %p)", typeName, str.toLatin1().constData(), wrapper->_wrappedPtr);
|
|
497
|
return PyString_FromFormat("%s(%s, %p)", typeName, str.toLatin1().constData(), wrapper->_wrappedPtr);
|
|
471
|
} else
|
|
498
|
}
|
|
|
|
|
499
|
}
|
|
|
|
|
500
|
if (wrapper->_wrappedPtr) {
|
|
472
|
if (wrapper->_obj) {
|
|
501
|
if (wrapper->_obj) {
|
|
473
|
return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", typeName, wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
|
|
502
|
return PyString_FromFormat("%s (C++ Object %p wrapped by %s %p))", typeName, wrapper->_wrappedPtr, wrapper->_obj->metaObject()->className(), qobj);
|
|
474
|
} else {
|
|
503
|
} else {
|
|
@@
-526,6
+555,7
static int PythonQtInstanceWrapper_compare(PyObject * obj1, PyObject * obj2)
|
|
526
|
args[0] = &result;
|
|
555
|
args[0] = &result;
|
|
527
|
args[1] = obj2; // this is a reference, so it needs the direct pointer
|
|
556
|
args[1] = obj2; // this is a reference, so it needs the direct pointer
|
|
528
|
w1->_obj->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
|
|
557
|
w1->_obj->qt_metacall(QMetaObject::InvokeMetaMethod, info._slot->slotIndex(), args);
|
|
|
|
|
558
|
return result?0:-1;
|
|
529
|
}
|
|
559
|
}
|
|
530
|
}
|
|
560
|
}
|
|
531
|
}
|
|
561
|
}
|