| 6615 | } |
| 6616 | |
| 6617 | void |
| 6618 | Node::declarePythonFields() |
| 6619 | { |
| 6620 | #ifdef NATRON_RUN_WITHOUT_PYTHON |
| 6621 | |
| 6622 | return; |
| 6623 | #endif |
| 6624 | if (getScriptName_mt_safe().empty()) { |
| 6625 | return; |
| 6626 | } |
| 6627 | PythonGILLocker pgl; |
| 6628 | |
| 6629 | if ( !getGroup() ) { |
| 6630 | return; |
| 6631 | } |
| 6632 | |
| 6633 | std::locale locale; |
| 6634 | std::string nodeName; |
| 6635 | if (getIOContainer()) { |
| 6636 | nodeName = getIOContainer()->getFullyQualifiedName(); |
| 6637 | } else { |
| 6638 | nodeName = getFullyQualifiedName(); |
| 6639 | } |
| 6640 | std::string appID = getApp()->getAppIDString(); |
| 6641 | bool alreadyDefined = false; |
| 6642 | std::string nodeFullName = appID + "." + nodeName; |
| 6643 | PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, NATRON_PYTHON_NAMESPACE::getMainModule(), &alreadyDefined); |
| 6644 | assert(nodeObj); |
| 6645 | Q_UNUSED(nodeObj); |
| 6646 | if (!alreadyDefined) { |
| 6647 | qDebug() << QString::fromUtf8("declarePythonFields(): attribute ") + QString::fromUtf8( nodeFullName.c_str() ) + QString::fromUtf8(" is not defined"); |
| 6648 | throw std::logic_error(std::string("declarePythonFields(): attribute ") + nodeFullName + " is not defined"); |
| 6649 | } |
| 6650 | |
| 6651 | |
| 6652 | std::stringstream ss; |
| 6653 | #ifdef DEBUG |
| 6654 | ss << "if not " << nodeFullName << ":\n"; |
| 6655 | ss << " print(\"[BUG]: " << nodeFullName << " is not defined!\")\n"; |
| 6656 | #endif |
| 6657 | const KnobsVec& knobs = getKnobs(); |
| 6658 | for (U32 i = 0; i < knobs.size(); ++i) { |
| 6659 | const std::string& knobName = knobs[i]->getName(); |
| 6660 | if ( !knobName.empty() && (knobName.find(" ") == std::string::npos) && !std::isdigit(knobName[0], locale) ) { |
| 6661 | if ( PyObject_HasAttrString( nodeObj, knobName.c_str() ) ) { |
| 6662 | continue; |
| 6663 | } |
| 6664 | ss << nodeFullName << "." << knobName << " = "; |
| 6665 | ss << nodeFullName << ".getParam(\"" << knobName << "\")\n"; |
| 6666 | } |
| 6667 | } |
| 6668 | |
| 6669 | std::string script = ss.str(); |
| 6670 | if ( !script.empty() ) { |
| 6671 | if ( !appPTR->isBackground() ) { |
| 6672 | getApp()->printAutoDeclaredVariable(script); |
| 6673 | } |
| 6674 | std::string err; |
no test coverage detected