本文整理汇总了C++中base::PyException::ReportException方法的典型用法代码示例。如果您正苦于以下问题:C++ PyException::ReportException方法的具体用法?C++ PyException::ReportException怎么用?C++ PyException::ReportException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类base::PyException
的用法示例。
在下文中一共展示了PyException::ReportException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fromString
void PropertyPythonObject::fromString(const std::string& repr)
{
Base::PyGILStateLocker lock;
try {
Py::Module pickle(PyImport_ImportModule("json"),true);
Py::Callable method(pickle.getAttr(std::string("loads")));
Py::Tuple args(1);
args.setItem(0, Py::String(repr));
Py::Object res = method.apply(args);
if (this->object.hasAttr("__setstate__")) {
Py::Tuple args(1);
args.setItem(0, res);
Py::Callable state(this->object.getAttr("__setstate__"));
state.apply(args);
}
else if (this->object.hasAttr("__dict__")) {
this->object.setAttr("__dict__", res);
}
else {
this->object = res;
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例2: getDefaultDisplayMode
const char* ViewProviderPythonFeatureImp::getDefaultDisplayMode() const
{
// Run the getDefaultDisplayMode method of the proxy object.
Base::PyGILStateLocker lock;
static std::string mode;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("getDefaultDisplayMode"))) {
Py::Callable method(vp.getAttr(std::string("getDefaultDisplayMode")));
Py::Tuple args;
Py::String str(method.apply(args));
//if (str.isUnicode())
// str = str.encode("ascii"); // json converts strings into unicode
mode = str.as_std_string("ascii");
return mode.c_str();
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return 0;
}
示例3: attach
void ViewProviderPythonFeatureImp::attach(App::DocumentObject *pcObject)
{
// Run the attach method of the proxy object.
Base::PyGILStateLocker lock;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("attach"))) {
if (vp.hasAttr("__object__")) {
Py::Callable method(vp.getAttr(std::string("attach")));
Py::Tuple args;
method.apply(args);
}
else {
Py::Callable method(vp.getAttr(std::string("attach")));
Py::Tuple args(1);
args.setItem(0, Py::Object(object->getPyObject(), true));
method.apply(args);
}
// #0000415: Now simulate a property change event to call
// claimChildren if implemented.
pcObject->Label.touch();
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例4: method
std::vector<App::DocumentObject*> ViewProviderPythonFeatureImp::claimChildren(const std::vector<App::DocumentObject*>& base) const
{
std::vector<App::DocumentObject*> children;
Base::PyGILStateLocker lock;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("claimChildren"))) {
Py::Callable method(vp.getAttr(std::string("claimChildren")));
Py::Tuple args;
Py::Sequence list(method.apply(args));
for (Py::Sequence::iterator it = list.begin(); it != list.end(); ++it) {
PyObject* item = (*it).ptr();
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj = static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
children.push_back(obj);
}
}
}
else {
children = base;
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return children;
}
示例5: method
DocumentObjectExecReturn *FeaturePythonImp::execute()
{
// Run the execute method of the proxy object.
Base::PyGILStateLocker lock;
try {
Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == PropertyPythonObject::getClassTypeId()) {
Py::Object feature = static_cast<PropertyPythonObject*>(proxy)->getValue();
if (feature.hasAttr("__object__")) {
Py::Callable method(feature.getAttr(std::string("execute")));
Py::Tuple args(0);
method.apply(args);
}
else {
Py::Callable method(feature.getAttr(std::string("execute")));
Py::Tuple args(1);
args.setItem(0, Py::Object(object->getPyObject(), true));
method.apply(args);
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
std::stringstream str;
str << object->Label.getValue() << ": " << e.what();
return new App::DocumentObjectExecReturn(str.str());
}
return DocumentObject::StdReturn;
}
示例6: toString
std::string PropertyPythonObject::toString() const
{
std::string repr;
Base::PyGILStateLocker lock;
try {
Py::Module pickle(PyImport_ImportModule("json"),true);
Py::Callable method(pickle.getAttr(std::string("dumps")));
Py::Object dump;
if (this->object.hasAttr("__getstate__")) {
Py::Tuple args;
Py::Callable state(this->object.getAttr("__getstate__"));
dump = state.apply(args);
}
else if (this->object.hasAttr("__dict__")) {
dump = this->object.getAttr("__dict__");
}
else {
dump = this->object;
}
Py::Tuple args(1);
args.setItem(0, dump);
Py::Object res = method.apply(args);
Py::String str(res);
repr = str.as_std_string("ascii");
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return repr;
}
示例7: getDetail
SoDetail* ViewProviderPythonFeatureImp::getDetail(const char* name) const
{
// Run the onChanged method of the proxy object.
Base::PyGILStateLocker lock;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("getDetail"))) {
Py::Callable method(vp.getAttr(std::string("getDetail")));
Py::Tuple args(1);
args.setItem(0, Py::String(name));
Py::Object det(method.apply(args));
void* ptr = 0;
Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoDetail *", det.ptr(), &ptr, 0);
SoDetail* detail = reinterpret_cast<SoDetail*>(ptr);
return detail ? detail->copy() : 0;
}
}
}
catch (const Base::Exception& e) {
e.ReportException();
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return 0;
}
示例8: getElement
std::string ViewProviderPythonFeatureImp::getElement(const SoDetail *det) const
{
// Run the onChanged method of the proxy object.
Base::PyGILStateLocker lock;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("getElement"))) {
PyObject* pivy = 0;
// Note: As there is no ref'counting mechanism for the SoDetail class we must
// pass '0' as the last parameter so that the Python object does not 'own'
// the detail object.
pivy = Base::Interpreter().createSWIGPointerObj("pivy.coin", "SoDetail *", (void*)det, 0);
Py::Callable method(vp.getAttr(std::string("getElement")));
Py::Tuple args(1);
args.setItem(0, Py::Object(pivy, true));
Py::String name(method.apply(args));
return (std::string)name;
}
}
}
catch (const Base::Exception& e) {
e.ReportException();
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return "";
}
示例9: onChanged
void FeaturePythonImp::onChanged(const Property* prop)
{
// Run the execute method of the proxy object.
Base::PyGILStateLocker lock;
try {
Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == PropertyPythonObject::getClassTypeId()) {
Py::Object feature = static_cast<PropertyPythonObject*>(proxy)->getValue();
if (feature.hasAttr(std::string("onChanged"))) {
if (feature.hasAttr("__object__")) {
Py::Callable method(feature.getAttr(std::string("onChanged")));
Py::Tuple args(1);
std::string prop_name = object->getName(prop);
args.setItem(0, Py::String(prop_name));
method.apply(args);
}
else {
Py::Callable method(feature.getAttr(std::string("onChanged")));
Py::Tuple args(2);
args.setItem(0, Py::Object(object->getPyObject(), true));
std::string prop_name = object->getName(prop);
args.setItem(1, Py::String(prop_name));
method.apply(args);
}
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例10: loadPickle
void PropertyPythonObject::loadPickle(const std::string& str)
{
// find the custom attributes and restore them
Base::PyGILStateLocker lock;
try {
std::string buffer = str;
boost::regex pickle("S'(\\w+)'.+S'(\\w+)'\\n");
boost::match_results<std::string::const_iterator> what;
std::string::const_iterator start, end;
start = buffer.begin();
end = buffer.end();
while (boost::regex_search(start, end, what, pickle)) {
std::string key = std::string(what[1].first, what[1].second);
std::string val = std::string(what[2].first, what[2].second);
this->object.setAttr(key, Py::String(val));
buffer = std::string(what[2].second, end);
start = buffer.begin();
end = buffer.end();
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例11: getIcon
QIcon ViewProviderPythonFeatureImp::getIcon() const
{
// default icon
//static QPixmap px = BitmapFactory().pixmap("Tree_Python");
// Run the getIcon method of the proxy object.
Base::PyGILStateLocker lock;
try {
App::Property* proxy = object->getPropertyByName("Proxy");
if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) {
Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue();
if (vp.hasAttr(std::string("getIcon"))) {
Py::Callable method(vp.getAttr(std::string("getIcon")));
Py::Tuple args;
Py::String str(method.apply(args));
std::string content = str.as_std_string("utf-8");
QPixmap icon;
// Check if the passed string is a filename, otherwise treat as xpm data
QFileInfo fi(QString::fromUtf8(content.c_str()));
if (fi.isFile() && fi.exists()) {
icon.load(fi.absoluteFilePath());
} else {
QByteArray ary;
int strlen = (int)content.size();
ary.resize(strlen);
for (int j=0; j<strlen; j++)
ary[j]=content[j];
// Make sure to remove crap around the XPM data
QList<QByteArray> lines = ary.split('\n');
QByteArray buffer;
buffer.reserve(ary.size()+lines.size());
for (QList<QByteArray>::iterator it = lines.begin(); it != lines.end(); ++it) {
QByteArray trim = it->trimmed();
if (!trim.isEmpty()) {
buffer.append(trim);
buffer.append('\n');
}
}
icon.loadFromData(buffer, "XPM");
}
if (!icon.isNull()) {
return icon;
}
}
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return QIcon();
}
示例12: helpRequested
void TaskDialogPython::helpRequested()
{
Base::PyGILStateLocker lock;
try {
if (dlg.hasAttr(std::string("helpRequested"))) {
Py::Callable method(dlg.getAttr(std::string("helpRequested")));
Py::Tuple args;
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例13: clearSelection
void SelectionObserverPython::clearSelection(const SelectionChanges& msg)
{
Base::PyGILStateLocker lock;
try {
if (this->inst.hasAttr(std::string("clearSelection"))) {
Py::Callable method(this->inst.getAttr(std::string("clearSelection")));
Py::Tuple args(1);
args.setItem(0, Py::String(msg.pDocName ? msg.pDocName : ""));
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例14: clicked
void TaskDialogPython::clicked(int i)
{
Base::PyGILStateLocker lock;
try {
if (dlg.hasAttr(std::string("clicked"))) {
Py::Callable method(dlg.getAttr(std::string("clicked")));
Py::Tuple args(1);
args.setItem(0, Py::Int(i));
method.apply(args);
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
}
示例15: needsFullSpace
bool TaskDialogPython::needsFullSpace() const
{
Base::PyGILStateLocker lock;
try {
if (dlg.hasAttr(std::string("needsFullSpace"))) {
Py::Callable method(dlg.getAttr(std::string("needsFullSpace")));
Py::Tuple args;
Py::Boolean ret(method.apply(args));
return (bool)ret;
}
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
e.ReportException();
}
return TaskDialog::needsFullSpace();
}