| 99 | } |
| 100 | |
| 101 | bool |
| 102 | DialogParamHolder::onKnobValueChanged(KnobI* k, |
| 103 | ValueChangedReasonEnum reason, |
| 104 | double time, |
| 105 | ViewSpec view, |
| 106 | bool originatedFromMainThread) |
| 107 | { |
| 108 | std::string callback; |
| 109 | { |
| 110 | QMutexLocker k(&_imp->paramChangedCBMutex); |
| 111 | callback = _imp->paramChangedCB; |
| 112 | } |
| 113 | |
| 114 | if ( !callback.empty() ) { |
| 115 | bool userEdited = reason == eValueChangedReasonNatronGuiEdited || |
| 116 | reason == eValueChangedReasonUserEdited; |
| 117 | std::vector<std::string> args; |
| 118 | std::string error; |
| 119 | try { |
| 120 | NATRON_PYTHON_NAMESPACE::getFunctionArguments(callback, &error, &args); |
| 121 | } catch (const std::exception& e) { |
| 122 | getApp()->appendToScriptEditor( std::string("Failed to get signature of onParamChanged callback: ") |
| 123 | + e.what() ); |
| 124 | |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | if ( !error.empty() ) { |
| 129 | getApp()->appendToScriptEditor("Failed to get signature of onParamChanged callback: " + error); |
| 130 | |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | std::string signatureError; |
| 135 | signatureError.append("The param changed callback supports the following signature(s):\n"); |
| 136 | signatureError.append("- callback(paramName, app, userEdited)"); |
| 137 | if (args.size() != 3) { |
| 138 | getApp()->appendToScriptEditor("Wrong signature of onParamChanged callback: " + signatureError); |
| 139 | |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | if ( ( (args[0] != "paramName") || (args[1] != "app") || (args[2] != "userEdited") ) ) { |
| 144 | getApp()->appendToScriptEditor("Wrong signature of onParamChanged callback: " + signatureError); |
| 145 | |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | std::string appID = getApp()->getAppIDString(); |
| 150 | std::stringstream ss; |
| 151 | ss << callback << "(\"" << k->getName() << "\"," << appID << ","; |
| 152 | if (userEdited) { |
| 153 | ss << "True"; |
| 154 | } else { |
| 155 | ss << "False"; |
| 156 | } |
| 157 | ss << ")\n"; |
| 158 |
nothing calls this directly
no test coverage detected