14 changes: 10 additions & 4 deletions python/plugins/processing/core/GeoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def __init__(self):
self.canRunInBatchMode = True
#to be set by the provider when it loads the algorithm
self.provider = None

#if the algorithm is run as part of a model, the parent model can be set in this variable,
#to allow for customized behaviour, in case some operations should be run differently when
#running as part of a model
self.model = None

self.defineCharacteristics()

Expand Down Expand Up @@ -135,13 +140,14 @@ def checkParameterValuesBeforeExecuting(self):
#=========================================================


def execute(self, progress):
def execute(self, progress, model = None):

'''The method to use to call a processing algorithm.
Although the body of the algorithm is in processAlgorithm(),
it should be called using this method, since it performs
some additional operations.
Raises a GeoAlgorithmExecutionException in case anything goes wrong.'''

self.model = model
try:
self.setOutputCRS()
self.resolveTemporaryOutputs()
Expand All @@ -153,7 +159,7 @@ def execute(self, progress):
except GeoAlgorithmExecutionException, gaee:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, gaee.msg)
raise gaee
except:
except Exception, e:
#if something goes wrong and is not caught in the algorithm,
#we catch it here and wrap it
lines = ["Uncaught error while executing algorithm"]
Expand All @@ -165,7 +171,7 @@ def execute(self, progress):
lines.append(errstring)
lines.append(errstring.replace("\n", "|"))
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, lines)
raise GeoAlgorithmExecutionException(errstring)
raise GeoAlgorithmExecutionException(str(e))


def runPostExecutionScript(self, progress):
Expand Down
47 changes: 6 additions & 41 deletions python/plugins/processing/core/Processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.AlgorithmClassification import AlgorithmDecorator
from processing.gui.AlgorithmExecutor import AlgorithmExecutor
from processing.gui.RenderingStyles import RenderingStyles
from processing.gui.Postprocessing import Postprocessing
from processing.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor
from processing.core.SilentProgress import SilentProgress
from processing.modeler.Providers import Providers
from processing.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
from processing.modeler.ModelerOnlyAlgorithmProvider import ModelerOnlyAlgorithmProvider
Expand Down Expand Up @@ -310,45 +308,12 @@ def runAlgorithm(algOrName, onFinish, *args):
elif cursor.shape() != Qt.WaitCursor:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))

useThreads = ProcessingConfig.getSetting(ProcessingConfig.USE_THREADS)

#this is doing strange things, so temporarily the thread execution is disabled from the console
useThreads = False

if useThreads:
algEx = AlgorithmExecutor(alg)
progress = QProgressDialog()
progress.setWindowTitle(alg.name)
progress.setLabelText("Executing %s..." % alg.name)
def finish():
QApplication.restoreOverrideCursor()
if onFinish is not None:
onFinish(alg, SilentProgress())
progress.close()
def error(msg):
QApplication.restoreOverrideCursor()
print msg
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, msg)
def cancel():
try:
algEx.finished.disconnect()
algEx.terminate()
QApplication.restoreOverrideCursor()
progress.close()
except:
pass
algEx.error.connect(error)
algEx.finished.connect(finish)
algEx.start()
algEx.wait()
else:
#progress = SilentProgress()
progress = MessageBarProgress()
ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
if onFinish is not None and ret:
onFinish(alg, progress)
QApplication.restoreOverrideCursor()
progress.close()
progress = MessageBarProgress()
ret = UnthreadedAlgorithmExecutor.runalg(alg, progress)
if onFinish is not None and ret:
onFinish(alg, progress)
QApplication.restoreOverrideCursor()
progress.close()
return alg


Expand Down
6 changes: 1 addition & 5 deletions python/plugins/processing/core/ProcessingConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

class ProcessingConfig():

TABLE_LIKE_PARAM_PANEL = "TABLE_LIKE_PARAM_PANEL"
OUTPUT_FOLDER = "OUTPUT_FOLDER"
RASTER_STYLE = "RASTER_STYLE"
VECTOR_POINT_STYLE = "VECTOR_POINT_STYLE"
Expand All @@ -39,7 +38,6 @@ class ProcessingConfig():
USE_SELECTED = "USE_SELECTED"
USE_FILENAME_AS_LAYER_NAME = "USE_FILENAME_AS_LAYER_NAME"
KEEP_DIALOG_OPEN = "KEEP_DIALOG_OPEN"
USE_THREADS = "USE_THREADS"
SHOW_DEBUG_IN_DIALOG = "SHOW_DEBUG_IN_DIALOG"
RECENT_ALGORITHMS = "RECENT_ALGORITHMS"
PRE_EXECUTION_SCRIPT = "PRE_EXECUTION_SCRIPT"
Expand All @@ -54,11 +52,9 @@ class ProcessingConfig():
def initialize():
icon = QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")
ProcessingConfig.settingIcons["General"] = icon
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_THREADS, "Run algorithms in a new thread (unstable)", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.SHOW_DEBUG_IN_DIALOG, "Show extra info in Log panel", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.KEEP_DIALOG_OPEN, "Keep dialog open after running an algorithm", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_SELECTED, "Use only selected features", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.TABLE_LIKE_PARAM_PANEL, "Show table-like parameter panels", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_SELECTED, "Use only selected features", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", False))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.SHOW_RECENT_ALGORITHMS, "Show recently executed algorithms", True))
ProcessingConfig.addSetting(Setting("General", ProcessingConfig.OUTPUT_FOLDER, "Output folder", tempFolder()))
Expand Down
10 changes: 2 additions & 8 deletions python/plugins/processing/grass/GrassAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from processing.parameters.ParameterFactory import ParameterFactory
from processing.outputs.OutputFactory import OutputFactory
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools import dataobjects
from processing.tools import dataobjects, system
from processing.grass.GrassUtils import GrassUtils
from processing.parameters.ParameterSelection import ParameterSelection
from processing.core.WrongHelpFileException import WrongHelpFileException
Expand All @@ -55,12 +55,6 @@
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterString import ParameterString

NUM_EXPORTED = 1

def getNumExportedLayers():
NUM_EXPORTED += 1
return NUM_EXPORTED

class GrassAlgorithm(GeoAlgorithm):

GRASS_OUTPUT_TYPE_PARAMETER = "GRASS_OUTPUT_TYPE_PARAMETER"
Expand Down Expand Up @@ -443,7 +437,7 @@ def exportRasterLayer(self, layer):


def getTempFilename(self):
filename = "tmp" + str(time.time()).replace(".","") + str(getNumExportedLayers())
filename = "tmp" + str(time.time()).replace(".","") + str(system.getNumExportedLayers())
return filename

def commandLineName(self):
Expand Down
12 changes: 9 additions & 3 deletions python/plugins/processing/grass/GrassUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
import stat
import shutil
from qgis.core import QgsApplication
from PyQt4.QtCore import *
import traceback
Expand All @@ -32,8 +33,7 @@
from processing.core.ProcessingConfig import ProcessingConfig
from processing.tools.system import *
from processing.core.ProcessingLog import ProcessingLog
import stat
import shutil


class GrassUtils:

Expand Down Expand Up @@ -67,6 +67,12 @@ def grassScriptFilename():
filename = "grass_script.bat"
filename = userFolder() + os.sep + filename
return filename

@staticmethod
def getGrassVersion():
#I do not know if this should be removed or let the user enter it
#or something like that... This is just a temporary thing
return "6.4.0"

@staticmethod
def grassPath():
Expand Down
2 changes: 0 additions & 2 deletions python/plugins/processing/grass/nviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from qgis.core import *
from processing.parameters.ParameterMultipleInput import ParameterMultipleInput
from processing.grass.GrassUtils import GrassUtils
Expand All @@ -34,7 +33,6 @@
from processing.parameters.ParameterNumber import ParameterNumber
from processing.parameters.ParameterRaster import ParameterRaster
from processing.tools import dataobjects
import time

class nviz(GeoAlgorithm):

Expand Down
71 changes: 23 additions & 48 deletions python/plugins/processing/gui/AlgorithmExecutionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@
from processing.parameters.ParameterFixedTable import ParameterFixedTable
from processing.parameters.ParameterTableField import ParameterTableField
from processing.parameters.ParameterTable import ParameterTable
from processing.gui.AlgorithmExecutor import AlgorithmExecutor
from processing.core.ProcessingLog import ProcessingLog
from processing.gui.Postprocessing import Postprocessing
from processing.parameters.ParameterRange import ParameterRange
from processing.parameters.ParameterNumber import ParameterNumber

from processing.parameters.ParameterFile import ParameterFile
from processing.parameters.ParameterCrs import ParameterCrs
from processing.core.ProcessingConfig import ProcessingConfig
Expand Down Expand Up @@ -75,11 +73,7 @@ def __init__(self, alg, mainWidget):
self.runButton = QtGui.QPushButton()
self.runButton.setText("Run")
self.buttonBox.addButton(self.runButton, QtGui.QDialogButtonBox.ActionRole)
self.runButton.clicked.connect(self.accept)
self.scrollArea = QtGui.QScrollArea()
if self.mainWidget:
self.scrollArea.setWidget(self.mainWidget)
self.scrollArea.setWidgetResizable(True)
self.runButton.clicked.connect(self.accept)
self.setWindowTitle(self.alg.name)
self.progressLabel = QtGui.QLabel()
self.progress = QtGui.QProgressBar()
Expand All @@ -91,7 +85,7 @@ def __init__(self, alg, mainWidget):
self.verticalLayout.setMargin(0)
self.tabWidget = QtGui.QTabWidget()
self.tabWidget.setMinimumWidth(300)
self.tabWidget.addTab(self.scrollArea, "Parameters")
self.tabWidget.addTab(self.mainWidget, "Parameters")
self.verticalLayout.addWidget(self.tabWidget)
self.logText = QTextEdit()
self.logText.readOnly = True
Expand Down Expand Up @@ -146,9 +140,8 @@ def setParamValues(self):
if output.hidden:
continue
output.value = self.paramTable.valueItems[output.name].getValue()
if not ProcessingConfig.getSetting(ProcessingConfig.TABLE_LIKE_PARAM_PANEL):
if isinstance(output, (OutputRaster, OutputVector, OutputTable)):
output.open = self.paramTable.checkBoxes[output.name].isChecked()
if isinstance(output, (OutputRaster, OutputVector, OutputTable)):
output.open = self.paramTable.checkBoxes[output.name].isChecked()

return True

Expand Down Expand Up @@ -192,8 +185,7 @@ def setParamValue(self, param, widget):
@pyqtSlot()
def accept(self):
checkCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_CRS)
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
useThread = ProcessingConfig.getSetting(ProcessingConfig.USE_THREADS)
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
self.showDebug = ProcessingConfig.getSetting(ProcessingConfig.SHOW_DEBUG_IN_DIALOG)
try:
self.setParamValues()
Expand Down Expand Up @@ -224,46 +216,29 @@ def accept(self):
self.progress.setMaximum(0)
self.progressLabel.setText("Processing algorithm...")
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
if useThread and not self.iterateParam: #iterative execution on separate thread is still not working fine...

self.setInfo("<b>Algorithm %s starting...</b>" % self.alg.name)
if self.iterateParam:
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg, self.iterateParam, self):
self.finish()
else:
QApplication.restoreOverrideCursor()
if not keepOpen:
self.close()
else:
self.resetGUI()
else:
command = self.alg.getAsCommand()
if command:
ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM, command)
self.algEx = AlgorithmExecutor(self.alg)
self.algEx.algExecuted.connect(self.finish)
self.algEx.error.connect(self.error)
self.algEx.percentageChanged.connect(self.setPercentage)
self.algEx.textChanged.connect(self.setText)
self.algEx.iterated.connect(self.iterate)
self.algEx.infoSet.connect(self.setInfo)
self.algEx.commandSet.connect(self.setCommand)
self.algEx.debugInfoSet.connect(self.setDebugInfo)
self.algEx.consoleInfoSet.connect(self.setConsoleInfo)
self.algEx.start()
self.setInfo("<b>Algorithm %s started</b>" % self.alg.name)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True)
else:
self.setInfo("<b>Algorithm %s starting...</b>" % self.alg.name)
if self.iterateParam:
if UnthreadedAlgorithmExecutor.runalgIterating(self.alg, self.iterateParam, self):
self.finish()
else:
QApplication.restoreOverrideCursor()
if not keepOpen:
self.close()
else:
self.resetGUI()
if UnthreadedAlgorithmExecutor.runalg(self.alg, self):
self.finish()
else:
command = self.alg.getAsCommand()
if command:
ProcessingLog.addToLog(ProcessingLog.LOG_ALGORITHM, command)
if UnthreadedAlgorithmExecutor.runalg(self.alg, self):
self.finish()
QApplication.restoreOverrideCursor()
if not keepOpen:
self.close()
else:
QApplication.restoreOverrideCursor()
if not keepOpen:
self.close()
else:
self.resetGUI()
self.resetGUI()
except AlgorithmExecutionDialog.InvalidParameterValue as ex:
try:
self.buttonBox.accepted.connect(lambda: ex.widget.setPalette(QPalette()))
Expand Down
Loading