Example #1
0
void list_keys(py::dict dict)
{
	std::cout << py::len(dict.items()) << " keys in dict:" << std::endl;
	for(int i=0; i<py::len(dict.items()); ++i)
	{
		std::cout << std::string(py::extract<std::string>(dict.items()[i][0]))
			<< std::endl;
	}
}
Example #2
0
  boost::shared_ptr<ecto::module_<T> > inspect(boost::python::tuple args,
                                               boost::python::dict kwargs)
  {
    typedef ecto::module_<T> module_t;

    namespace bp = boost::python;

    //SHOW();
    boost::shared_ptr<module_t> mm(new module_t());
    ecto::module * m = mm.get();
    m->declare_params();

    bp::list l = kwargs.items();
    for (int j = 0; j < bp::len(l); ++j)
      {
        bp::object key = l[j][0];
        bp::object value = l[j][1];
        std::string keystring = bp::extract<std::string>(key);
        std::string valstring =
            bp::extract<std::string>(value.attr("__repr__")());
        m->parameters.at(keystring).set(value);
      }
    m->declare_io();
    return mm;
  }
Example #3
0
void Serializable::pyUpdateAttrs(const boost::python::dict& d){	
	boost::python::list l=d.items(); size_t ll=boost::python::len(l); if(ll==0) return;
	for(size_t i=0; i<ll; i++){
		boost::python::tuple t=boost::python::extract<boost::python::tuple>(l[i]);
		string key=boost::python::extract<string>(t[0]);
		pySetAttr(key,t[1]);
	}
	callPostLoad();
}
Example #4
0
//---------------------------------------------------------------------------
boost::property_tree::ptree make_ptree(const boost::python::dict &args) {
    using namespace boost::python;
    boost::property_tree::ptree p;

    for(stl_input_iterator<tuple> arg(args.items()), end; arg != end; ++arg) {
        const char *name = extract<const char*>((*arg)[0]);
        const char *type = extract<const char*>((*arg)[1].attr("__class__").attr("__name__"));

        if (strcmp(type, "int") == 0)
            p.put(name, extract<int>((*arg)[1]));
        else
            p.put(name, extract<float>((*arg)[1]));
    }

    return p;
}
Example #5
0
File: pyUtils.cpp Project: JT-a/USD
PXR_NAMESPACE_OPEN_SCOPE

bool
SdfFileFormatArgumentsFromPython(
    const boost::python::dict& dict,
    SdfLayer::FileFormatArguments* args,
    std::string* errMsg)
{
    SdfLayer::FileFormatArguments argsMap;
    typedef SdfLayer::FileFormatArguments::key_type ArgKeyType;
    typedef SdfLayer::FileFormatArguments::mapped_type ArgValueType;

    const boost::python::object items = dict.items();
    for (boost::python::ssize_t i = 0; i < len(items); ++i) {
        boost::python::extract<ArgKeyType> keyExtractor(items[i][0]);
        if (!keyExtractor.check()) {
            if (errMsg) {
                *errMsg = "All file format argument keys must be strings";
            }
            return false;
        }

        boost::python::extract<ArgValueType> valueExtractor(items[i][1]);
        if (!valueExtractor.check()) {
            if (errMsg) {
                *errMsg = "All file format argument values must be strings";
            }
            return false;
        }
            
        argsMap[keyExtractor()] = valueExtractor();
    }

    args->swap(argsMap);
    return true;
}