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

Method runScript

Qt/Python/pqPythonShell.cxx:445–476  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

443
444//-----------------------------------------------------------------------------
445void pqPythonShell::runScript()
446{
447 pqServer* server = pqApplicationCore::instance()->getActiveServer();
448 pqFileDialog dialog(server, this, tr("Run Script"), QString(),
449 tr("Python Files") + QString(" (*.py);;") + tr("All Files") + QString(" (*)"), false, false);
450 dialog.setObjectName("PythonShellRunScriptDialog");
451 dialog.setFileMode(pqFileDialog::ExistingFile);
452 if (dialog.exec() == QDialog::Accepted)
453 {
454 const auto pxm = server->proxyManager();
455 const vtkTypeUInt32 location = dialog.getSelectedLocation();
456 for (const QString& filename : dialog.getSelectedFiles())
457 {
458 const std::string contents = pxm->LoadString(filename.toStdString().c_str(), location);
459 if (!contents.empty())
460 {
461 QString code;
462 // First inject code to let the script know its own path
463 code.append(QString("__file__ = r'%1'\n").arg(filename));
464 // Then append the file content
465 code.append(contents.c_str());
466 code.append("\n");
467 code.append("del __file__\n");
468 this->executeScript(code.toUtf8().data());
469 }
470 else
471 {
472 qCritical() << tr("Error: script ") << filename << tr(" was empty or could not be opened.");
473 }
474 }
475 }
476}

Callers

nothing calls this directly

Calls 13

executeScriptMethod · 0.95
instanceFunction · 0.85
trFunction · 0.85
setFileModeMethod · 0.80
getSelectedFilesMethod · 0.80
LoadStringMethod · 0.80
QStringClass · 0.50
getActiveServerMethod · 0.45
execMethod · 0.45
proxyManagerMethod · 0.45
emptyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected