Skip to content
Permalink
Browse files

[FEATURE] Script-provided algorithms support for run script action

Scripts with now launch a processing algorithm dialog (when
appropriate) when:
- drag and dropping a python script onto the main window
- using the browser panel's right-click run script action
  • Loading branch information
nirvn committed Aug 17, 2018
1 parent a6d0d7a commit fcd01577036f88e77035e6d8848f8e555d8eca68
Showing with 21 additions and 2 deletions.
  1. +21 −2 src/app/qgisapp.cpp
@@ -6179,9 +6179,28 @@ void QgisApp::runScript( const QString &filePath )

mPythonUtils->runString(
QString( "import sys\n"
"import inspect\n"
"from qgis.utils import iface\n"
"exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read())\n" ).arg( filePath )
, tr( "Failed to run Python script:" ), false );
"try:\n"
" from qgis.core import QgsApplication, QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm\n"
" from processing.gui.AlgorithmDialog import AlgorithmDialog\n"
"except ImportError:\n"
" processing_found = False\n"
"else:\n"
" processing_found = True\n"
"d={}\n"
"exec(open(\"%1\".replace(\"\\\\\", \"/\").encode(sys.getfilesystemencoding())).read(), d)\n"
"if processing_found:\n"
" alg = None\n"
" for k, v in d.items():\n"
" if inspect.isclass(v) and issubclass(v, (QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm)) and v.__name__ not in (\"QgsProcessingAlgorithm\", \"QgsProcessingFeatureBasedAlgorithm\"):\n"
" alg = v()\n"
" break\n"
" if alg:\n"
" alg.setProvider(QgsApplication.processingRegistry().providerById(\"script\"))\n"
" alg.initAlgorithm()\n"
" dlg = AlgorithmDialog(alg)\n"
" dlg.show()\n" ).arg( filePath ), tr( "Failed to run Python script:" ), false );
#else
Q_UNUSED( filePath );
#endif

0 comments on commit fcd0157

Please sign in to comment.
You can’t perform that action at this time.