Implemented stream operator for PyObjectWrapper.
Fixes bug #829. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Hugo Parente Lima <hugo.pl@gmail.com>
This commit is contained in:
parent
75bcc4dbdd
commit
955316b5ca
2 changed files with 46 additions and 0 deletions
|
|
@ -87,6 +87,47 @@ PyObjectWrapper::operator PyObject*() const
|
||||||
return m_me;
|
return m_me;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDataStream &operator<<(QDataStream &out, const PyObjectWrapper &myObj)
|
||||||
|
{
|
||||||
|
static PyObject *reduce_func = 0;
|
||||||
|
|
||||||
|
Shiboken::GilState gil;
|
||||||
|
if (!reduce_func) {
|
||||||
|
Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle"));
|
||||||
|
reduce_func = PyObject_GetAttrString(pickleModule, "dumps");
|
||||||
|
}
|
||||||
|
Shiboken::AutoDecRef repr(PyObject_CallFunctionObjArgs(reduce_func, (PyObject*)myObj, NULL));
|
||||||
|
if (repr.object()) {
|
||||||
|
char* buff;
|
||||||
|
Py_ssize_t size;
|
||||||
|
PyString_AsStringAndSize(repr.object(), &buff, &size);
|
||||||
|
QByteArray data(buff, size);
|
||||||
|
out << data;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream &operator>>(QDataStream &in, PyObjectWrapper &myObj)
|
||||||
|
{
|
||||||
|
static PyObject *eval_func = 0;
|
||||||
|
|
||||||
|
Shiboken::GilState gil;
|
||||||
|
if (!eval_func) {
|
||||||
|
Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle"));
|
||||||
|
eval_func = PyObject_GetAttrString(pickleModule, "loads");
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray repr;
|
||||||
|
in >> repr;
|
||||||
|
Shiboken::AutoDecRef pyCode(PyString_FromStringAndSize(repr.data(), repr.size()));
|
||||||
|
Shiboken::AutoDecRef value(PyObject_CallFunctionObjArgs(eval_func, pyCode.object(), 0));
|
||||||
|
if (!value.object()) {
|
||||||
|
value = Py_None;
|
||||||
|
}
|
||||||
|
myObj = PyObjectWrapper(value);
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Shiboken {
|
namespace Shiboken {
|
||||||
|
|
@ -132,6 +173,7 @@ SignalManager::SignalManager() : m_d(new SignalManagerPrivate)
|
||||||
|
|
||||||
// Register PyObject type to use in queued signal and slot connections
|
// Register PyObject type to use in queued signal and slot connections
|
||||||
qRegisterMetaType<PyObjectWrapper>(PYTHON_TYPE);
|
qRegisterMetaType<PyObjectWrapper>(PYTHON_TYPE);
|
||||||
|
qRegisterMetaTypeStreamOperators<PyObjectWrapper>(PYTHON_TYPE);
|
||||||
|
|
||||||
TypeResolver::createValueTypeResolver<PyObjectWrapper>(PYTHON_TYPE);
|
TypeResolver::createValueTypeResolver<PyObjectWrapper>(PYTHON_TYPE);
|
||||||
TypeResolver::createValueTypeResolver<PyObjectWrapper>("object");
|
TypeResolver::createValueTypeResolver<PyObjectWrapper>("object");
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
#include <Qt>
|
#include <Qt>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QMetaMethod>
|
#include <QMetaMethod>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
class QObject;
|
class QObject;
|
||||||
|
|
||||||
|
|
@ -49,6 +50,9 @@ private:
|
||||||
void* m_data; //future
|
void* m_data; //future
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PYSIDE_API QDataStream &operator<<(QDataStream& out, const PyObjectWrapper& myObj);
|
||||||
|
PYSIDE_API QDataStream &operator>>(QDataStream& in, PyObjectWrapper& myObj);
|
||||||
|
|
||||||
class PYSIDE_API SignalManager
|
class PYSIDE_API SignalManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue