+ playing in sandbox

This commit is contained in:
wmayer
2013-07-05 15:31:54 +02:00
parent 609072f140
commit 93f38c114b
4 changed files with 53 additions and 5 deletions

View File

@@ -162,6 +162,8 @@ void DocumentObjectProtectorPy::init_type()
behaviors().supportRepr();
behaviors().supportGetattr();
behaviors().supportSetattr();
add_varargs_method("purgeTouched",&DocumentObjectProtectorPy::purgeTouched,"purgeTouched()");
}
DocumentObjectProtectorPy::DocumentObjectProtectorPy(App::DocumentObject *obj)
@@ -179,6 +181,13 @@ DocumentObjectProtectorPy::~DocumentObjectProtectorPy()
delete _dp;
}
Py::Object DocumentObjectProtectorPy::getObject() const
{
App::DocumentObject* obj = _dp->getObject();
PyObject* py = obj->getPyObject();
return Py::Object(py, true);
}
Py::Object DocumentObjectProtectorPy::repr()
{
std::string s;
@@ -201,10 +210,11 @@ Py::Object DocumentObjectProtectorPy::getattr(const char * attr)
App::DocumentObject* obj = _dp->getObject();
App::Property* prop = obj->getPropertyByName(attr);
if (!prop) {
std::string s;
std::ostringstream s_out;
s_out << "No such attribute '" << attr << "'";
throw Py::AttributeError(s_out.str());
return Py::PythonExtension<DocumentObjectProtectorPy>::getattr(attr);
//std::string s;
//std::ostringstream s_out;
//s_out << "No such attribute '" << attr << "'";
//throw Py::AttributeError(s_out.str());
}
return Py::asObject(prop->getPyObject());
@@ -231,7 +241,18 @@ int DocumentObjectProtectorPy::setattr(const char * attr, const Py::Object & val
Base::PyGILStateRelease unlock;
std::auto_ptr<App::Property> copy(static_cast<App::Property*>
(prop->getTypeId().createInstance()));
copy->setPyObject(value.ptr());
if (PyObject_TypeCheck(value.ptr(), DocumentObjectProtectorPy::type_object())) {
copy->setPyObject(static_cast<const DocumentObjectProtectorPy*>(value.ptr())->getObject().ptr());
}
else {
copy->setPyObject(value.ptr());
}
return _dp->setProperty(attr, *copy) ? 0 : -1;
}
}
Py::Object DocumentObjectProtectorPy::purgeTouched(const Py::Tuple&)
{
_dp->purgeTouched();
return Py::None();
}