Skip to content

Commit

Permalink
[processing] scripts also can be feature-based algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Feb 5, 2018
1 parent cd7bb16 commit fa5ab81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 6 additions & 2 deletions python/plugins/processing/script/ScriptEditorDialog.py
Expand Up @@ -37,7 +37,11 @@
QFileDialog)

from qgis.gui import QgsGui, QgsErrorDialog
from qgis.core import QgsApplication, QgsSettings, QgsError, QgsProcessingAlgorithm
from qgis.core import (QgsApplication,
QgsSettings,
QgsError,
QgsProcessingAlgorithm,
QgsProcessingFeatureBasedAlgorithm)
from qgis.utils import iface, OverrideCursor

from processing.gui.AlgorithmDialog import AlgorithmDialog
Expand Down Expand Up @@ -208,7 +212,7 @@ def runAlgorithm(self):

alg = None
for k, v in d.items():
if inspect.isclass(v) and issubclass(v, QgsProcessingAlgorithm) and v.__name__ != "QgsProcessingAlgorithm":
if inspect.isclass(v) and issubclass(v, (QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm)) and v.__name__ not in ("QgsProcessingAlgorithm", "QgsProcessingFeatureBasedAlgorithm"):
alg = v()
break

Expand Down
7 changes: 5 additions & 2 deletions python/plugins/processing/script/ScriptUtils.py
Expand Up @@ -31,7 +31,10 @@

from qgis.PyQt.QtCore import QCoreApplication

from qgis.core import QgsProcessingAlgorithm, QgsMessageLog
from qgis.core import (QgsProcessingAlgorithm,
QgsProcessingFeatureBasedAlgorithm,
QgsMessageLog
)

from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools.system import mkdir, userFolder
Expand Down Expand Up @@ -64,7 +67,7 @@ def loadAlgorithm(moduleName, filePath):
spec.loader.exec_module(module)
for x in dir(module):
obj = getattr(module, x)
if inspect.isclass(obj) and issubclass(obj, QgsProcessingAlgorithm) and obj.__name__ != "QgsProcessingAlgorithm":
if inspect.isclass(obj) and issubclass(obj, (QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm)) and obj.__name__ not in ("QgsProcessingAlgorithm", "QgsProcessingFeatureBasedAlgorithm"):
scriptsRegistry[x] = filePath
return obj()
except ImportError as e:
Expand Down

0 comments on commit fa5ab81

Please sign in to comment.