+ playing in sandbox

This commit is contained in:
wmayer 2013-07-05 15:31:54 +02:00
parent 6fde5d764b
commit 249e806a31
4 changed files with 53 additions and 5 deletions

View File

@ -160,6 +160,25 @@ protected:
const AbstractCallable& callable;
};
class CustomPurgeEvent : public AbstractCustomProtectorEvent
{
public:
CustomPurgeEvent(App::DocumentObject* o)
: obj(o)
{
}
~CustomPurgeEvent()
{
}
void execute()
{
obj->purgeTouched();
}
protected:
App::DocumentObject* obj;
};
class DocumentReceiver : public QObject
{
public:
@ -324,3 +343,8 @@ void DocumentObjectProtector::execute(const AbstractCallable& call)
DocumentReceiver::globalInstance()->postEventAndWait(new CustomCallableEvent(call));
}
void DocumentObjectProtector::purgeTouched()
{
validate();
DocumentReceiver::globalInstance()->postEventAndWait(new CustomPurgeEvent(obj));
}

View File

@ -127,6 +127,7 @@ public:
App::DocumentObject* getObject() const;
bool setProperty(const std::string& name, const App::Property& p);
void execute(const AbstractCallable&);
void purgeTouched();
private:
void validate();

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();
}

View File

@ -72,7 +72,9 @@ public:
Py::Object repr();
Py::Object getattr(const char *);
Py::Object getObject() const;
int setattr(const char *, const Py::Object &);
Py::Object purgeTouched(const Py::Tuple&);
private:
DocumentObjectProtector* _dp;