本文整理汇总了C++中py::Tuple::getItem方法的典型用法代码示例。如果您正苦于以下问题:C++ Tuple::getItem方法的具体用法?C++ Tuple::getItem怎么用?C++ Tuple::getItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py::Tuple
的用法示例。
在下文中一共展示了Tuple::getItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setQ
void RotationPy::setQ(Py::Tuple arg)
{
double q0 = (double)Py::Float(arg.getItem(0));
double q1 = (double)Py::Float(arg.getItem(1));
double q2 = (double)Py::Float(arg.getItem(2));
double q3 = (double)Py::Float(arg.getItem(3));
this->getRotationPtr()->setValue(q0,q1,q2,q3);
}
示例2: sAddCommand
PyObject* Application::sAddCommand(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
char* pName;
char* pSource=0;
PyObject* pcCmdObj;
if (!PyArg_ParseTuple(args, "sO|s", &pName,&pcCmdObj,&pSource)) // convert args: Python->C
return NULL; // NULL triggers exception
// get the call stack to find the Python module name
//
std::string module, group;
try {
Base::PyGILStateLocker lock;
Py::Module mod(PyImport_ImportModule("inspect"), true);
Py::Callable inspect(mod.getAttr("stack"));
Py::Tuple args;
Py::List list(inspect.apply(args));
args = list.getItem(0);
// usually this is the file name of the calling script
std::string file = args.getItem(1).as_string();
Base::FileInfo fi(file);
// convert backslashes to slashes
file = fi.filePath();
module = fi.fileNamePure();
// for the group name get the directory name after 'Mod'
boost::regex rx("/Mod/(\\w+)/");
boost::smatch what;
if (boost::regex_search(file, what, rx)) {
group = what[1];
}
else {
group = module;
}
}
catch (Py::Exception& e) {
e.clear();
}
try {
Base::PyGILStateLocker lock;
Py::Object cmd(pcCmdObj);
if (cmd.hasAttr("GetCommands")) {
Command* cmd = new PythonGroupCommand(pName, pcCmdObj);
if (!module.empty()) {
cmd->setAppModuleName(module.c_str());
}
if (!group.empty()) {
cmd->setGroupName(group.c_str());
}
Application::Instance->commandManager().addCommand(cmd);
}
else {
Command* cmd = new PythonCommand(pName, pcCmdObj, pSource);
if (!module.empty()) {
cmd->setAppModuleName(module.c_str());
}
if (!group.empty()) {
cmd->setGroupName(group.c_str());
}
Application::Instance->commandManager().addCommand(cmd);
}
}
catch (const Base::Exception& e) {
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
return 0;
}
catch (...) {
PyErr_SetString(Base::BaseExceptionFreeCADError, "Unknown C++ exception raised in Application::sAddCommand()");
return 0;
}
Py_INCREF(Py_None);
return Py_None;
}