MCPcopy Create free account
hub / github.com/Kitware/ParaView / addMacro

Method addMacro

Qt/Python/pqPythonManager.cxx:245–277  ·  view source on GitHub ↗

----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

243
244//----------------------------------------------------------------------------
245void 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//----------------------------------------------------------------------------
279void pqPythonManager::editMacro(const QString& fileName)
280{

Callers 2

onAddPressedMethod · 0.45
createMacroMethod · 0.45

Calls 9

QFileInfoClass · 0.85
instanceFunction · 0.85
LoadStringMethod · 0.80
setPathMethod · 0.45
proxyManagerMethod · 0.45
getActiveServerMethod · 0.45
dataMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected