Skip to content

Commit 297f466

Browse files
committed
[processing] added preconfigured algorithms
1 parent 9d5df4e commit 297f466

17 files changed

+425
-61
lines changed

python/plugins/processing/core/Processing.py

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
5757
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
5858
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
59+
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider
60+
5961
from processing.tools import dataobjects
6062

6163

@@ -138,6 +140,7 @@ def initialize():
138140
Processing.addProvider(Grass7AlgorithmProvider(), updateList=False)
139141
Processing.addProvider(ScriptAlgorithmProvider(), updateList=False)
140142
Processing.addProvider(TauDEMAlgorithmProvider(), updateList=False)
143+
Processing.addProvider(PreconfiguredAlgorithmProvider(), updateList=False)
141144
Processing.addProvider(Processing.modeler, updateList=False)
142145
Processing.modeler.initializeSettings()
143146

python/plugins/processing/gui/AlgorithmDialog.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ def __init__(self, alg):
7474
self.mainWidget = ParametersPanel(self, alg)
7575
self.setMainWidget()
7676

77-
cornerWidget = QWidget()
77+
self.cornerWidget = QWidget()
7878
layout = QVBoxLayout()
7979
layout.setContentsMargins(0, 0, 0, 5)
8080
self.tabWidget.setStyleSheet("QTabBar::tab { height: 30px; }")
81-
runAsBatchButton = QPushButton(self.tr("Run as batch process..."))
82-
runAsBatchButton.clicked.connect(self.runAsBatch)
83-
layout.addWidget(runAsBatchButton)
84-
cornerWidget.setLayout(layout)
85-
self.tabWidget.setCornerWidget(cornerWidget)
81+
self.runAsBatchButton = QPushButton(self.tr("Run as batch process..."))
82+
self.runAsBatchButton.clicked.connect(self.runAsBatch)
83+
layout.addWidget(self.runAsBatchButton)
84+
self.cornerWidget.setLayout(layout)
85+
self.tabWidget.setCornerWidget(self.cornerWidget)
8686

8787
QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded)
8888
QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved)

python/plugins/processing/gui/ContextAction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
class ContextAction:
3333

34-
def setData(self, alg, toolbox):
35-
self.alg = alg
34+
def setData(self, itemData, toolbox):
35+
self.itemData = itemData
3636
self.toolbox = toolbox
3737

3838
def updateToolbox(self):

python/plugins/processing/gui/DeleteScriptAction.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ def __init__(self, scriptType):
4646

4747
def isEnabled(self):
4848
if self.scriptType == self.SCRIPT_PYTHON:
49-
return isinstance(self.alg, ScriptAlgorithm) and self.alg.allowEdit
49+
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit
5050
elif self.scriptType == self.SCRIPT_R:
51-
return isinstance(self.alg, RAlgorithm)
51+
return isinstance(self.itemData, RAlgorithm)
5252

53-
def execute(self, alg):
53+
def execute(self):
5454
reply = QMessageBox.question(None,
5555
self.tr('Confirmation', 'DeleteScriptAction'),
5656
self.tr('Are you sure you want to delete this script?',
5757
'DeleteScriptAction'),
5858
QMessageBox.Yes | QMessageBox.No,
5959
QMessageBox.No)
6060
if reply == QMessageBox.Yes:
61-
os.remove(self.alg.descriptionFile)
61+
os.remove(self.itemData.descriptionFile)
6262
if self.scriptType == self.SCRIPT_PYTHON:
6363
self.toolbox.updateProvider('script')
6464
elif self.scriptType == self.SCRIPT_R:

python/plugins/processing/gui/EditScriptAction.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ def __init__(self, scriptType):
4242

4343
def isEnabled(self):
4444
if self.scriptType == ScriptEditorDialog.SCRIPT_PYTHON:
45-
return isinstance(self.alg, ScriptAlgorithm) and self.alg.allowEdit
45+
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit
4646
elif self.scriptType == ScriptEditorDialog.SCRIPT_R:
47-
return isinstance(self.alg, RAlgorithm)
47+
return isinstance(self.itemData, RAlgorithm)
4848

4949
def execute(self):
50-
dlg = ScriptEditorDialog(self.scriptType, self.alg)
50+
dlg = ScriptEditorDialog(self.scriptType, self.itemData)
5151
dlg.show()
5252
dlg.exec_()
5353
if dlg.update:

python/plugins/processing/gui/ProcessingToolbox.py

+32-20
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
***************************************************************************
1818
"""
1919

20+
2021
__author__ = 'Victor Olaya'
2122
__date__ = 'August 2012'
2223
__copyright__ = '(C) 2012, Victor Olaya'
@@ -32,6 +33,7 @@
3233
from PyQt.QtWidgets import QMenu, QAction, QTreeWidgetItem, QLabel, QMessageBox
3334
from qgis.utils import iface
3435

36+
from processing.gui.Postprocessing import handleAlgorithmResults
3537
from processing.core.Processing import Processing
3638
from processing.core.ProcessingLog import ProcessingLog
3739
from processing.core.ProcessingConfig import ProcessingConfig
@@ -41,7 +43,8 @@
4143
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
4244
from processing.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
4345
from processing.gui.ConfigDialog import ConfigDialog
44-
46+
from processing.gui.MessageBarProgress import MessageBarProgress
47+
from processing.gui.AlgorithmExecutor import runalg
4548

4649
pluginPath = os.path.split(os.path.dirname(__file__))[0]
4750
WIDGET, BASE = uic.loadUiType(
@@ -194,11 +197,14 @@ def showPopupMenu(self, point):
194197
editRenderingStylesAction.triggered.connect(
195198
self.editRenderingStyles)
196199
popupmenu.addAction(editRenderingStylesAction)
200+
201+
if isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
202+
data = item.alg if isinstance(item, TreeAlgorithmItem) else item.action
197203
actions = Processing.contextMenuActions
198204
if len(actions) > 0:
199205
popupmenu.addSeparator()
200206
for action in actions:
201-
action.setData(alg, self)
207+
action.setData(data, self)
202208
if action.isEnabled():
203209
contextMenuAction = QAction(action.name,
204210
self.algorithmTree)
@@ -237,24 +243,30 @@ def executeAlgorithm(self):
237243
dlg.exec_()
238244
return
239245
alg = alg.getCopy()
240-
dlg = alg.getCustomParametersDialog()
241-
if not dlg:
242-
dlg = AlgorithmDialog(alg)
243-
canvas = iface.mapCanvas()
244-
prevMapTool = canvas.mapTool()
245-
dlg.show()
246-
dlg.exec_()
247-
if canvas.mapTool() != prevMapTool:
248-
try:
249-
canvas.mapTool().reset()
250-
except:
251-
pass
252-
canvas.setMapTool(prevMapTool)
253-
if dlg.executed:
254-
showRecent = ProcessingConfig.getSetting(
255-
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
256-
if showRecent:
257-
self.addRecentAlgorithms(True)
246+
if (alg.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0:
247+
dlg = alg.getCustomParametersDialog()
248+
if not dlg:
249+
dlg = AlgorithmDialog(alg)
250+
canvas = iface.mapCanvas()
251+
prevMapTool = canvas.mapTool()
252+
dlg.show()
253+
dlg.exec_()
254+
if canvas.mapTool() != prevMapTool:
255+
try:
256+
canvas.mapTool().reset()
257+
except:
258+
pass
259+
canvas.setMapTool(prevMapTool)
260+
if dlg.executed:
261+
showRecent = ProcessingConfig.getSetting(
262+
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
263+
if showRecent:
264+
self.addRecentAlgorithms(True)
265+
else:
266+
progress = MessageBarProgress()
267+
runalg(alg, progress)
268+
handleAlgorithmResults(alg, progress)
269+
progress.close()
258270
if isinstance(item, TreeActionItem):
259271
action = item.action
260272
action.setData(self)

python/plugins/processing/gui/ToolboxAction.py

-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232

3333
class ToolboxAction:
3434

35-
def __init__(self):
36-
# This should be true if the action should be shown even if
37-
# there are no algorithms in the provider (for instance,
38-
# when it is deactivated
39-
self.showAlways = False
40-
4135
def setData(self, toolbox):
4236
self.toolbox = toolbox
4337

python/plugins/processing/gui/menus.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import os
2+
from PyQt.QtWidgets import QAction, QMenu
3+
from PyQt4.QtGui import QIcon
14
from processing.core.Processing import Processing
25
from processing.core.ProcessingConfig import ProcessingConfig, Setting
3-
from PyQt.QtWidgets import QAction, QMenu
46
from processing.gui.MessageDialog import MessageDialog
57
from processing.gui.AlgorithmDialog import AlgorithmDialog
68
from qgis.utils import iface
7-
import os
8-
from PyQt4.QtGui import QIcon
9+
from processing.gui.MessageBarProgress import MessageBarProgress
10+
from processing.gui.AlgorithmExecutor import runalg
11+
from processing.gui.Postprocessing import handleAlgorithmResults
912

1013
algorithmsToolbar = None
1114
menusSettingsGroup = 'Menus'
@@ -196,19 +199,26 @@ def _executeAlgorithm(alg):
196199
dlg.exec_()
197200
return
198201
alg = alg.getCopy()
199-
dlg = alg.getCustomParametersDialog()
200-
if not dlg:
201-
dlg = AlgorithmDialog(alg)
202-
canvas = iface.mapCanvas()
203-
prevMapTool = canvas.mapTool()
204-
dlg.show()
205-
dlg.exec_()
206-
if canvas.mapTool() != prevMapTool:
207-
try:
208-
canvas.mapTool().reset()
209-
except:
210-
pass
211-
canvas.setMapTool(prevMapTool)
202+
if (alg.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0:
203+
dlg = alg.getCustomParametersDialog()
204+
if not dlg:
205+
dlg = AlgorithmDialog(alg)
206+
canvas = iface.mapCanvas()
207+
prevMapTool = canvas.mapTool()
208+
dlg.show()
209+
dlg.exec_()
210+
if canvas.mapTool() != prevMapTool:
211+
try:
212+
canvas.mapTool().reset()
213+
except:
214+
pass
215+
canvas.setMapTool(prevMapTool)
216+
else:
217+
progress = MessageBarProgress()
218+
runalg(alg, progress)
219+
handleAlgorithmResults(alg, progress)
220+
progress.close()
221+
212222

213223

214224
def getMenu(name, parent):

python/plugins/processing/modeler/DeleteModelAction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(self):
3737
self.name = self.tr('Delete model', 'DeleteModelAction')
3838

3939
def isEnabled(self):
40-
return isinstance(self.alg, ModelerAlgorithm)
40+
return isinstance(self.itemData, ModelerAlgorithm)
4141

4242
def execute(self):
4343
reply = QMessageBox.question(
@@ -47,5 +47,5 @@ def execute(self):
4747
QMessageBox.Yes | QMessageBox.No,
4848
QMessageBox.No)
4949
if reply == QMessageBox.Yes:
50-
os.remove(self.alg.descriptionFile)
50+
os.remove(self.itemData.descriptionFile)
5151
self.toolbox.updateProvider('model')

python/plugins/processing/modeler/EditModelAction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def __init__(self):
3636
self.name = self.tr('Edit model', 'EditModelAction')
3737

3838
def isEnabled(self):
39-
return isinstance(self.alg, ModelerAlgorithm)
39+
return isinstance(self.itemData, ModelerAlgorithm)
4040

4141
def execute(self):
42-
dlg = ModelerDialog(self.alg.getCopy())
42+
dlg = ModelerDialog(self.itemData.getCopy())
4343
dlg.exec_()
4444
if dlg.update:
4545
self.toolbox.updateProvider('model')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
NewPreconfiguredAlgorithmAction.py
6+
---------------------
7+
Date : April 2016
8+
Copyright : (C) 2016 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Victor Olaya'
21+
__date__ = 'April 2016'
22+
__copyright__ = '(C) 2016, Victor Olaya'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
from PyQt4.QtGui import QMessageBox
30+
from processing.gui.ContextAction import ContextAction
31+
from processing.preconfigured.PreconfiguredAlgorithm import PreconfiguredAlgorithm
32+
33+
34+
class DeletePreconfiguredAlgorithmAction(ContextAction):
35+
36+
def __init__(self):
37+
self.name = self.tr('Delete preconfigured algorithm', 'DeletePreconfiguredAlgorithmAction')
38+
39+
def isEnabled(self):
40+
return isinstance(self.itemData, PreconfiguredAlgorithm)
41+
42+
def execute(self):
43+
reply = QMessageBox.question(None,
44+
self.tr('Confirmation', 'DeletePreconfiguredAlgorithmAction'),
45+
self.tr('Are you sure you want to delete this algorithm?',
46+
'DeletePreconfiguredAlgorithmAction'),
47+
QMessageBox.Yes | QMessageBox.No,
48+
QMessageBox.No)
49+
if reply == QMessageBox.Yes:
50+
os.remove(self.itemData.descriptionFile)
51+
self.toolbox.updateProvider('preconfigured')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
NewPreconfiguredAlgorithmAction.py
6+
---------------------
7+
Date : April 2016
8+
Copyright : (C) 2016 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
21+
__author__ = 'Victor Olaya'
22+
__date__ = 'April 2016'
23+
__copyright__ = '(C) 2016, Victor Olaya'
24+
25+
# This will get replaced with a git SHA1 when you do a git archive
26+
27+
__revision__ = '$Format:%H$'
28+
29+
from processing.gui.ContextAction import ContextAction
30+
from processing.core.GeoAlgorithm import GeoAlgorithm
31+
from processing.preconfigured.PreconfiguredAlgorithmDialog import PreconfiguredAlgorithmDialog
32+
from processing.preconfigured.PreconfiguredAlgorithm import PreconfiguredAlgorithm
33+
34+
class NewPreconfiguredAlgorithmAction(ContextAction):
35+
36+
def __init__(self):
37+
self.name = self.tr('Create preconfigured algorithm', 'NewPreconfiguredAlgorithmAction')
38+
39+
def isEnabled(self):
40+
return (isinstance(self.itemData, GeoAlgorithm) and
41+
not isinstance(self.itemData, PreconfiguredAlgorithm))
42+
43+
def execute(self):
44+
dlg = PreconfiguredAlgorithmDialog(self.itemData, self.toolbox)
45+
dlg.exec_()

0 commit comments

Comments
 (0)