Skip to content

Commit a09892f

Browse files
committed
[Feature][Processing] Headless
To use QGIS Processing in python scripts out of QGIS. The changes made concern the dependence to legendInterface. In cases where the interface.iface is null (None) QGIS Processing uses the QgsMapLayerRegistry instance.
1 parent 0ad5cc9 commit a09892f

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

python/plugins/processing/core/Processing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from processing.core.ProcessingConfig import ProcessingConfig
3535
from processing.core.GeoAlgorithm import GeoAlgorithm
3636
from processing.core.ProcessingLog import ProcessingLog
37+
from processing.core.SilentProgress import SilentProgress
3738
from processing.gui.AlgorithmClassification import AlgorithmDecorator
3839
from processing.gui.MessageBarProgress import MessageBarProgress
3940
from processing.gui.RenderingStyles import RenderingStyles
@@ -347,7 +348,9 @@ def runAlgorithm(algOrName, onFinish, *args):
347348
elif cursor.shape() != Qt.WaitCursor:
348349
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
349350

350-
progress = MessageBarProgress()
351+
progress = SilentProgress()
352+
if not interface.iface == None :
353+
progress = MessageBarProgress()
351354
ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
352355
if onFinish is not None and ret:
353356
onFinish(alg, progress)

python/plugins/processing/core/SilentProgress.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ def setDebugInfo(self, _):
4848

4949
def setConsoleInfo(self, _):
5050
pass
51+
52+
def close(self):
53+
pass

python/plugins/processing/tools/dataobjects.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def getSupportedOutputTableExtensions():
6565

6666

6767
def getRasterLayers():
68-
layers = interface.iface.legendInterface().layers()
68+
layers = QgsMapLayerRegistry.instance().mapLayers().values()
6969
raster = list()
7070

7171
for layer in layers:
@@ -76,7 +76,7 @@ def getRasterLayers():
7676

7777

7878
def getVectorLayers(shapetype=[-1]):
79-
layers = interface.iface.legendInterface().layers()
79+
layers = QgsMapLayerRegistry.instance().mapLayers().values()
8080
vector = []
8181
for layer in layers:
8282
if layer.type() == layer.VectorLayer:
@@ -96,7 +96,7 @@ def getAllLayers():
9696

9797

9898
def getTables():
99-
layers = interface.iface.legendInterface().layers()
99+
layers = QgsMapLayerRegistry.instance().mapLayers().values()
100100
tables = list()
101101
for layer in layers:
102102
if layer.type() == layer.VectorLayer:

0 commit comments

Comments
 (0)