----------------------------------------------------------------------------
| 243 | |
| 244 | //---------------------------------------------------------------------------- |
| 245 | void pqPythonManager::addMacro(const QString& fileName, vtkTypeUInt32 location) |
| 246 | { |
| 247 | QString userMacroDir = pqCoreUtilities::getParaViewUserDirectory() + "/Macros"; |
| 248 | QDir dir; |
| 249 | dir.setPath(userMacroDir); |
| 250 | // Copy macro file to user directory |
| 251 | if (!dir.exists(userMacroDir) && !dir.mkpath(userMacroDir)) |
| 252 | { |
| 253 | qWarning() << "Could not create user Macro directory:" << userMacroDir; |
| 254 | return; |
| 255 | } |
| 256 | |
| 257 | QString expectedFilePath = userMacroDir + "/" + QFileInfo(fileName).fileName(); |
| 258 | expectedFilePath = pqCoreUtilities::getNoneExistingFileName(expectedFilePath); |
| 259 | |
| 260 | // read python script from file |
| 261 | auto pxm = pqApplicationCore::instance()->getActiveServer()->proxyManager(); |
| 262 | const auto pyScript = pxm->LoadString(fileName.toUtf8().data(), location); |
| 263 | |
| 264 | // write python script to file in user directory |
| 265 | QFile file(expectedFilePath); |
| 266 | if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) |
| 267 | { |
| 268 | qWarning() << "Could not create user Macro file:" << expectedFilePath; |
| 269 | return; |
| 270 | } |
| 271 | QTextStream out(&file); |
| 272 | out << pyScript.c_str(); |
| 273 | file.close(); |
| 274 | |
| 275 | // Register the inner one |
| 276 | this->Internal->MacroSupervisor->addMacro(expectedFilePath); |
| 277 | } |
| 278 | //---------------------------------------------------------------------------- |
| 279 | void pqPythonManager::editMacro(const QString& fileName) |
| 280 | { |
no test coverage detected