Skip to content

Commit

Permalink
Further unification of execution dialogs.
Browse files Browse the repository at this point in the history
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@306 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
cpolymeris@gmail.com committed Jul 22, 2012
1 parent b7a9e21 commit 2a1a2ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 167 deletions.
36 changes: 10 additions & 26 deletions src/sextante/gui/BatchProcessingDialog.py
Expand Up @@ -5,6 +5,8 @@
from sextante.parameters.ParameterTable import ParameterTable
from sextante.parameters.ParameterVector import ParameterVector
from sextante.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
from sextante.gui.AlgorithmExecutionDialog import AlgorithmExecutionDialog

from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
Expand All @@ -20,48 +22,30 @@
from sextante.gui.UnthreadedAlgorithmExecutor import SilentProgress,\
UnthreadedAlgorithmExecutor

class BatchProcessingDialog(QtGui.QDialog):
class BatchProcessingDialog(AlgorithmExecutionDialog):
def __init__(self, alg):
QtGui.QDialog.__init__(self)
self.setModal(True)
self.alg = alg
self.algs = None
self.setupUi()
self.table = QtGui.QTableWidget(None)
AlgorithmExecutionDialog.__init__(self, alg, self.table)
self.setModal(True)
self.algEx = None

def setupUi(self):
self.resize(800, 500)
self.setWindowTitle("Batch Processing - " + self.alg.name)
self.horizontalLayout = QtGui.QVBoxLayout(self)
self.horizontalLayout.setSpacing(10)
self.horizontalLayout.setMargin(10)
self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.addRowButton = QtGui.QPushButton()
self.addRowButton.setText("Add row")
self.buttonBox.addButton(self.addRowButton, QtGui.QDialogButtonBox.ActionRole)
self.deleteRowButton = QtGui.QPushButton()
self.deleteRowButton.setText("Delete row")
self.buttonBox.addButton(self.addRowButton, QtGui.QDialogButtonBox.ActionRole)
self.buttonBox.addButton(self.deleteRowButton, QtGui.QDialogButtonBox.ActionRole)
self.table = QtGui.QTableWidget(self)
self.table.setColumnCount(len(self.alg.parameters) + len(self.alg.outputs))
self.setTableContent()
self.table.horizontalHeader().setStretchLastSection(True)
self.table.verticalHeader().setVisible(False)
self.table.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.progress = QtGui.QProgressBar()
self.progress.setMinimum(0)
self.horizontalLayout.addWidget(self.table)
self.horizontalLayout.addWidget(self.progress)
self.horizontalLayout.addWidget(self.buttonBox)
self.setLayout(self.horizontalLayout)
QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed)
QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed)
QObject.connect(self.addRowButton, QtCore.SIGNAL("clicked()"), self.addRow)
QObject.connect(self.deleteRowButton, QtCore.SIGNAL("clicked()"), self.deleteRow)
QtCore.QMetaObject.connectSlotsByName(self)
self.addRowButton.clicked.connect(self.addRow)
self.deleteRowButton.clicked.connect(self.deleteRow)

def setTableContent(self):
i = 0
Expand All @@ -77,7 +61,7 @@ def setTableContent(self):
for i in range(3):
self.addRow()

def okPressed(self):
def accept(self):
self.algs = []
for row in range(self.table.rowCount()):
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
Expand Down Expand Up @@ -128,7 +112,7 @@ def loadHTMLResults(self, alg, i):
if isinstance(out, OutputHTML):
SextanteResults.addResult(out.description + "[" + str(i) + "]", out.value)

def cancelPressed(self):
def cancel(self):
self.algs = None
if self.algEx:
self.algEx.terminate()
Expand Down
141 changes: 0 additions & 141 deletions src/sextante/gui/ParametersDialog.py
Expand Up @@ -46,144 +46,3 @@ def __init__(self, alg):
self.paramTable = ParametersPanel(self, alg)
AlgorithmExecutionDialog.__init__(self, alg, self.paramTable)
self.executed = False


def setParamValues(self):
params = self.alg.parameters
outputs = self.alg.outputs

for param in params:
if not self.setParamValue(param, self.paramTable.valueItems[param.name]):
return False

for output in outputs:
if output.hidden:
continue
output.value = self.paramTable.valueItems[output.name].getValue()
if not SextanteConfig.getSetting(SextanteConfig.TABLE_LIKE_PARAM_PANEL):
if isinstance(output, (OutputRaster, OutputVector, OutputTable, OutputHTML)):
output.open = self.paramTable.checkBoxes[output.name].isChecked()

return True

def setParamValue(self, param, widget):
if isinstance(param, ParameterRaster):
return param.setValue(widget.getValue())
elif isinstance(param, (ParameterVector, ParameterTable)):
try:
return param.setValue(widget.itemData(widget.currentIndex()).toPyObject())
except:
return param.setValue(widget.getValue())
elif isinstance(param, ParameterBoolean):
return param.setValue(widget.currentIndex() == 0)
elif isinstance(param, ParameterSelection):
return param.setValue(widget.currentIndex())
elif isinstance(param, ParameterFixedTable):
return param.setValue(widget.table)
elif isinstance(param, ParameterRange):
return param.setValue(widget.getValue())
if isinstance(param, ParameterTableField):
return param.setValue(widget.currentText())
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
options = QGisLayers.getVectorLayers()
else:
options = QGisLayers.getRasterLayers()
value = []
for index in widget.selectedoptions:
value.append(options[index])
return param.setValue(value)
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs, ParameterExtent)):
return param.setValue(widget.getValue())
else:
return param.setValue(str(widget.text()))

@pyqtSlot()
def accept(self):
#~ try:
if self.setParamValues():
msg = self.alg.checkParameterValuesBeforeExecuting()
if msg:
QMessageBox.critical(self, "Unable to execute algorithm", msg)
return
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(False)
buttons = self.paramTable.iterateButtons
iterateParam = None

for i in range(len(buttons.values())):
button = buttons.values()[i]
if button.isChecked():
iterateParam = buttons.keys()[i]
break

self.progress.setMaximum(0)
self.progressLabel.setText("Processing algorithm...")
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
useThread = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
if useThread:
if iterateParam:
self.algEx = AlgorithmExecutor(self.alg, iterateParam)
else:
command = self.alg.getAsCommand()
if command:
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
self.algEx = AlgorithmExecutor(self.alg)
self.algEx.finished.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.start()
SextanteLog.addToLog(SextanteLog.LOG_INFO,
"Algorithm %s started" % self.alg.name)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True)
self.finish()
else:
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
if iterateParam:
UnthreadedAlgorithmExecutor.runalgIterating(self.alg, iterateParam, self)
else:
command = self.alg.getAsCommand()
if command:
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
if UnthreadedAlgorithmExecutor.runalg(self.alg, self):
SextantePostprocessing.handleAlgorithmResults(self.alg, not keepOpen)
self.executed = True
QApplication.restoreOverrideCursor()
if not keepOpen:
self.close()
else:
self.progressLabel.setText("")
self.progress.setMaximum(100)
self.progress.setValue(0)
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)


else:
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")

@pyqtSlot()
def finish(self):
self.executed = True
SextanteLog.addToLog(SextanteLog.LOG_INFO,
"Algorithm %s finished correctly" % self.alg.name)
QApplication.restoreOverrideCursor()
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
if not keepOpen:
self.close()
else:
self.progressLabel.setText("")
self.progress.setMaximum(100)
self.progress.setValue(0)
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)

@pyqtSlot(int)
def iterate(self, i):
SextanteLog.addToLog(SextanteLog.LOG_INFO,
"Algorithm %s iteration #%i completed" % (self.alg.name, i))

0 comments on commit 2a1a2ef

Please sign in to comment.