| 10886 | } |
| 10887 | |
| 10888 | void |
| 10889 | Node::declarePythonFields() |
| 10890 | { |
| 10891 | #ifdef NATRON_RUN_WITHOUT_PYTHON |
| 10892 | |
| 10893 | return; |
| 10894 | #endif |
| 10895 | if (getScriptName_mt_safe().empty()) { |
| 10896 | return; |
| 10897 | } |
| 10898 | PythonGILLocker pgl; |
| 10899 | |
| 10900 | if ( !getGroup() ) { |
| 10901 | return; |
| 10902 | } |
| 10903 | |
| 10904 | std::locale locale; |
| 10905 | std::string nodeName; |
| 10906 | if (getIOContainer()) { |
| 10907 | nodeName = getIOContainer()->getFullyQualifiedName(); |
| 10908 | } else { |
| 10909 | nodeName = getFullyQualifiedName(); |
| 10910 | } |
| 10911 | std::string appID = getApp()->getAppIDString(); |
| 10912 | bool alreadyDefined = false; |
| 10913 | std::string nodeFullName = appID + "." + nodeName; |
| 10914 | PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, NATRON_PYTHON_NAMESPACE::getMainModule(), &alreadyDefined); |
| 10915 | assert(nodeObj); |
| 10916 | Q_UNUSED(nodeObj); |
| 10917 | if (!alreadyDefined) { |
| 10918 | qDebug() << QString::fromUtf8("declarePythonFields(): attribute ") + QString::fromUtf8( nodeFullName.c_str() ) + QString::fromUtf8(" is not defined"); |
| 10919 | throw std::logic_error(std::string("declarePythonFields(): attribute ") + nodeFullName + " is not defined"); |
| 10920 | } |
| 10921 | |
| 10922 | |
| 10923 | std::stringstream ss; |
| 10924 | #ifdef DEBUG |
| 10925 | ss << "if not " << nodeFullName << ":\n"; |
| 10926 | ss << " print \"[BUG]: " << nodeFullName << " is not defined!\"\n"; |
| 10927 | #endif |
| 10928 | const KnobsVec& knobs = getKnobs(); |
| 10929 | for (U32 i = 0; i < knobs.size(); ++i) { |
| 10930 | const std::string& knobName = knobs[i]->getName(); |
| 10931 | if ( !knobName.empty() && (knobName.find(" ") == std::string::npos) && !std::isdigit(knobName[0], locale) ) { |
| 10932 | if ( PyObject_HasAttrString( nodeObj, knobName.c_str() ) ) { |
| 10933 | continue; |
| 10934 | } |
| 10935 | ss << nodeFullName << "." << knobName << " = "; |
| 10936 | ss << nodeFullName << ".getParam(\"" << knobName << "\")\n"; |
| 10937 | } |
| 10938 | } |
| 10939 | |
| 10940 | std::string script = ss.str(); |
| 10941 | if ( !script.empty() ) { |
| 10942 | if ( !appPTR->isBackground() ) { |
| 10943 | getApp()->printAutoDeclaredVariable(script); |
| 10944 | } |
| 10945 | std::string err; |
no test coverage detected