Skip to content

Commit

Permalink
[processing] added preconfigured algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Apr 7, 2016
1 parent 9d5df4e commit 297f466
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 61 deletions.
3 changes: 3 additions & 0 deletions python/plugins/processing/core/Processing.py
Expand Up @@ -56,6 +56,8 @@
from processing.algs.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from processing.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
from processing.algs.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider
from processing.preconfigured.PreconfiguredAlgorithmProvider import PreconfiguredAlgorithmProvider

from processing.tools import dataobjects


Expand Down Expand Up @@ -138,6 +140,7 @@ def initialize():
Processing.addProvider(Grass7AlgorithmProvider(), updateList=False)
Processing.addProvider(ScriptAlgorithmProvider(), updateList=False)
Processing.addProvider(TauDEMAlgorithmProvider(), updateList=False)
Processing.addProvider(PreconfiguredAlgorithmProvider(), updateList=False)
Processing.addProvider(Processing.modeler, updateList=False)
Processing.modeler.initializeSettings()

Expand Down
12 changes: 6 additions & 6 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -74,15 +74,15 @@ def __init__(self, alg):
self.mainWidget = ParametersPanel(self, alg)
self.setMainWidget()

cornerWidget = QWidget()
self.cornerWidget = QWidget()
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 5)
self.tabWidget.setStyleSheet("QTabBar::tab { height: 30px; }")
runAsBatchButton = QPushButton(self.tr("Run as batch process..."))
runAsBatchButton.clicked.connect(self.runAsBatch)
layout.addWidget(runAsBatchButton)
cornerWidget.setLayout(layout)
self.tabWidget.setCornerWidget(cornerWidget)
self.runAsBatchButton = QPushButton(self.tr("Run as batch process..."))
self.runAsBatchButton.clicked.connect(self.runAsBatch)
layout.addWidget(self.runAsBatchButton)
self.cornerWidget.setLayout(layout)
self.tabWidget.setCornerWidget(self.cornerWidget)

QgsMapLayerRegistry.instance().layerWasAdded.connect(self.mainWidget.layerAdded)
QgsMapLayerRegistry.instance().layersWillBeRemoved.connect(self.mainWidget.layersWillBeRemoved)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/gui/ContextAction.py
Expand Up @@ -31,8 +31,8 @@

class ContextAction:

def setData(self, alg, toolbox):
self.alg = alg
def setData(self, itemData, toolbox):
self.itemData = itemData
self.toolbox = toolbox

def updateToolbox(self):
Expand Down
8 changes: 4 additions & 4 deletions python/plugins/processing/gui/DeleteScriptAction.py
Expand Up @@ -46,19 +46,19 @@ def __init__(self, scriptType):

def isEnabled(self):
if self.scriptType == self.SCRIPT_PYTHON:
return isinstance(self.alg, ScriptAlgorithm) and self.alg.allowEdit
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit
elif self.scriptType == self.SCRIPT_R:
return isinstance(self.alg, RAlgorithm)
return isinstance(self.itemData, RAlgorithm)

def execute(self, alg):
def execute(self):
reply = QMessageBox.question(None,
self.tr('Confirmation', 'DeleteScriptAction'),
self.tr('Are you sure you want to delete this script?',
'DeleteScriptAction'),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.Yes:
os.remove(self.alg.descriptionFile)
os.remove(self.itemData.descriptionFile)
if self.scriptType == self.SCRIPT_PYTHON:
self.toolbox.updateProvider('script')
elif self.scriptType == self.SCRIPT_R:
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/gui/EditScriptAction.py
Expand Up @@ -42,12 +42,12 @@ def __init__(self, scriptType):

def isEnabled(self):
if self.scriptType == ScriptEditorDialog.SCRIPT_PYTHON:
return isinstance(self.alg, ScriptAlgorithm) and self.alg.allowEdit
return isinstance(self.itemData, ScriptAlgorithm) and self.itemData.allowEdit
elif self.scriptType == ScriptEditorDialog.SCRIPT_R:
return isinstance(self.alg, RAlgorithm)
return isinstance(self.itemData, RAlgorithm)

def execute(self):
dlg = ScriptEditorDialog(self.scriptType, self.alg)
dlg = ScriptEditorDialog(self.scriptType, self.itemData)
dlg.show()
dlg.exec_()
if dlg.update:
Expand Down
52 changes: 32 additions & 20 deletions python/plugins/processing/gui/ProcessingToolbox.py
Expand Up @@ -17,6 +17,7 @@
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
Expand All @@ -32,6 +33,7 @@
from PyQt.QtWidgets import QMenu, QAction, QTreeWidgetItem, QLabel, QMessageBox
from qgis.utils import iface

from processing.gui.Postprocessing import handleAlgorithmResults
from processing.core.Processing import Processing
from processing.core.ProcessingLog import ProcessingLog
from processing.core.ProcessingConfig import ProcessingConfig
Expand All @@ -41,7 +43,8 @@
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
from processing.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
from processing.gui.ConfigDialog import ConfigDialog

from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import runalg

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
Expand Down Expand Up @@ -194,11 +197,14 @@ def showPopupMenu(self, point):
editRenderingStylesAction.triggered.connect(
self.editRenderingStyles)
popupmenu.addAction(editRenderingStylesAction)

if isinstance(item, (TreeAlgorithmItem, TreeActionItem)):
data = item.alg if isinstance(item, TreeAlgorithmItem) else item.action
actions = Processing.contextMenuActions
if len(actions) > 0:
popupmenu.addSeparator()
for action in actions:
action.setData(alg, self)
action.setData(data, self)
if action.isEnabled():
contextMenuAction = QAction(action.name,
self.algorithmTree)
Expand Down Expand Up @@ -237,24 +243,30 @@ def executeAlgorithm(self):
dlg.exec_()
return
alg = alg.getCopy()
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool() != prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)
if dlg.executed:
showRecent = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
self.addRecentAlgorithms(True)
if (alg.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0:
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool() != prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)
if dlg.executed:
showRecent = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_RECENT_ALGORITHMS)
if showRecent:
self.addRecentAlgorithms(True)
else:
progress = MessageBarProgress()
runalg(alg, progress)
handleAlgorithmResults(alg, progress)
progress.close()
if isinstance(item, TreeActionItem):
action = item.action
action.setData(self)
Expand Down
6 changes: 0 additions & 6 deletions python/plugins/processing/gui/ToolboxAction.py
Expand Up @@ -32,12 +32,6 @@

class ToolboxAction:

def __init__(self):
# This should be true if the action should be shown even if
# there are no algorithms in the provider (for instance,
# when it is deactivated
self.showAlways = False

def setData(self, toolbox):
self.toolbox = toolbox

Expand Down
42 changes: 26 additions & 16 deletions python/plugins/processing/gui/menus.py
@@ -1,11 +1,14 @@
import os
from PyQt.QtWidgets import QAction, QMenu
from PyQt4.QtGui import QIcon
from processing.core.Processing import Processing
from processing.core.ProcessingConfig import ProcessingConfig, Setting
from PyQt.QtWidgets import QAction, QMenu
from processing.gui.MessageDialog import MessageDialog
from processing.gui.AlgorithmDialog import AlgorithmDialog
from qgis.utils import iface
import os
from PyQt4.QtGui import QIcon
from processing.gui.MessageBarProgress import MessageBarProgress
from processing.gui.AlgorithmExecutor import runalg
from processing.gui.Postprocessing import handleAlgorithmResults

algorithmsToolbar = None
menusSettingsGroup = 'Menus'
Expand Down Expand Up @@ -196,19 +199,26 @@ def _executeAlgorithm(alg):
dlg.exec_()
return
alg = alg.getCopy()
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool() != prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)
if (alg.getVisibleParametersCount() + alg.getVisibleOutputsCount()) > 0:
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = AlgorithmDialog(alg)
canvas = iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool() != prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)
else:
progress = MessageBarProgress()
runalg(alg, progress)
handleAlgorithmResults(alg, progress)
progress.close()



def getMenu(name, parent):
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/DeleteModelAction.py
Expand Up @@ -37,7 +37,7 @@ def __init__(self):
self.name = self.tr('Delete model', 'DeleteModelAction')

def isEnabled(self):
return isinstance(self.alg, ModelerAlgorithm)
return isinstance(self.itemData, ModelerAlgorithm)

def execute(self):
reply = QMessageBox.question(
Expand All @@ -47,5 +47,5 @@ def execute(self):
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.Yes:
os.remove(self.alg.descriptionFile)
os.remove(self.itemData.descriptionFile)
self.toolbox.updateProvider('model')
4 changes: 2 additions & 2 deletions python/plugins/processing/modeler/EditModelAction.py
Expand Up @@ -36,10 +36,10 @@ def __init__(self):
self.name = self.tr('Edit model', 'EditModelAction')

def isEnabled(self):
return isinstance(self.alg, ModelerAlgorithm)
return isinstance(self.itemData, ModelerAlgorithm)

def execute(self):
dlg = ModelerDialog(self.alg.getCopy())
dlg = ModelerDialog(self.itemData.getCopy())
dlg.exec_()
if dlg.update:
self.toolbox.updateProvider('model')
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
NewPreconfiguredAlgorithmAction.py
---------------------
Date : April 2016
Copyright : (C) 2016 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'April 2016'
__copyright__ = '(C) 2016, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

import os
from PyQt4.QtGui import QMessageBox
from processing.gui.ContextAction import ContextAction
from processing.preconfigured.PreconfiguredAlgorithm import PreconfiguredAlgorithm


class DeletePreconfiguredAlgorithmAction(ContextAction):

def __init__(self):
self.name = self.tr('Delete preconfigured algorithm', 'DeletePreconfiguredAlgorithmAction')

def isEnabled(self):
return isinstance(self.itemData, PreconfiguredAlgorithm)

def execute(self):
reply = QMessageBox.question(None,
self.tr('Confirmation', 'DeletePreconfiguredAlgorithmAction'),
self.tr('Are you sure you want to delete this algorithm?',
'DeletePreconfiguredAlgorithmAction'),
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.Yes:
os.remove(self.itemData.descriptionFile)
self.toolbox.updateProvider('preconfigured')
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
NewPreconfiguredAlgorithmAction.py
---------------------
Date : April 2016
Copyright : (C) 2016 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""


__author__ = 'Victor Olaya'
__date__ = 'April 2016'
__copyright__ = '(C) 2016, Victor Olaya'

# This will get replaced with a git SHA1 when you do a git archive

__revision__ = '$Format:%H$'

from processing.gui.ContextAction import ContextAction
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.preconfigured.PreconfiguredAlgorithmDialog import PreconfiguredAlgorithmDialog
from processing.preconfigured.PreconfiguredAlgorithm import PreconfiguredAlgorithm

class NewPreconfiguredAlgorithmAction(ContextAction):

def __init__(self):
self.name = self.tr('Create preconfigured algorithm', 'NewPreconfiguredAlgorithmAction')

def isEnabled(self):
return (isinstance(self.itemData, GeoAlgorithm) and
not isinstance(self.itemData, PreconfiguredAlgorithm))

def execute(self):
dlg = PreconfiguredAlgorithmDialog(self.itemData, self.toolbox)
dlg.exec_()

0 comments on commit 297f466

Please sign in to comment.