MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / declareNodeVariableToPython

Method declareNodeVariableToPython

Engine/Node.cpp:6514–6556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6512}
6513
6514void
6515Node::declareNodeVariableToPython(const std::string& nodeName)
6516{
6517#ifdef NATRON_RUN_WITHOUT_PYTHON
6518
6519 return;
6520#endif
6521 if (getScriptName_mt_safe().empty()) {
6522 return;
6523 }
6524 if ( NATRON_PYTHON_NAMESPACE::isKeyword(nodeName) ) {
6525 throw std::runtime_error(nodeName + " is a Python keyword");
6526 }
6527
6528 PythonGILLocker pgl;
6529 PyObject* mainModule = appPTR->getMainModule();
6530 assert(mainModule);
6531
6532 std::string appID = getApp()->getAppIDString();
6533 std::string nodeFullName = appID + "." + nodeName;
6534 bool alreadyDefined = false;
6535 PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, mainModule, &alreadyDefined);
6536 assert(nodeObj);
6537 Q_UNUSED(nodeObj);
6538
6539 if (!alreadyDefined) {
6540 std::stringstream ss;
6541 ss << nodeFullName << " = " << appID << ".getNode(\"" << nodeName << "\")\n";
6542#ifdef DEBUG
6543 ss << "if not " << nodeFullName << ":\n";
6544 ss << " print(\"[BUG]: " << nodeFullName << " does not exist!\")";
6545#endif
6546 std::string script = ss.str();
6547 std::string output;
6548 std::string err;
6549 if ( !appPTR->isBackground() ) {
6550 getApp()->printAutoDeclaredVariable(script);
6551 }
6552 if ( !NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, &err, &output) ) {
6553 qDebug() << err.c_str();
6554 }
6555 }
6556}
6557
6558void
6559Node::setNodeVariableToPython(const std::string& oldName,

Callers

nothing calls this directly

Calls 6

getAppFunction · 0.85
emptyMethod · 0.80
getMainModuleMethod · 0.80
getAppIDStringMethod · 0.80
isBackgroundMethod · 0.45

Tested by

no test coverage detected