Skip to content

Commit 2a1a2ef

Browse files
author
cpolymeris@gmail.com
committed
Further unification of execution dialogs.
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@306 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
1 parent b7a9e21 commit 2a1a2ef

File tree

2 files changed

+10
-167
lines changed

2 files changed

+10
-167
lines changed

src/sextante/gui/BatchProcessingDialog.py

+10-26
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from sextante.parameters.ParameterTable import ParameterTable
66
from sextante.parameters.ParameterVector import ParameterVector
77
from sextante.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
8+
from sextante.gui.AlgorithmExecutionDialog import AlgorithmExecutionDialog
9+
810
from sextante.parameters.ParameterBoolean import ParameterBoolean
911
from sextante.parameters.ParameterSelection import ParameterSelection
1012
from sextante.parameters.ParameterFixedTable import ParameterFixedTable
@@ -20,48 +22,30 @@
2022
from sextante.gui.UnthreadedAlgorithmExecutor import SilentProgress,\
2123
UnthreadedAlgorithmExecutor
2224

23-
class BatchProcessingDialog(QtGui.QDialog):
25+
class BatchProcessingDialog(AlgorithmExecutionDialog):
2426
def __init__(self, alg):
25-
QtGui.QDialog.__init__(self)
26-
self.setModal(True)
27-
self.alg = alg
2827
self.algs = None
29-
self.setupUi()
28+
self.table = QtGui.QTableWidget(None)
29+
AlgorithmExecutionDialog.__init__(self, alg, self.table)
30+
self.setModal(True)
3031
self.algEx = None
31-
32-
def setupUi(self):
3332
self.resize(800, 500)
3433
self.setWindowTitle("Batch Processing - " + self.alg.name)
35-
self.horizontalLayout = QtGui.QVBoxLayout(self)
36-
self.horizontalLayout.setSpacing(10)
37-
self.horizontalLayout.setMargin(10)
38-
self.buttonBox = QtGui.QDialogButtonBox(self)
39-
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
40-
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
4134
self.addRowButton = QtGui.QPushButton()
4235
self.addRowButton.setText("Add row")
4336
self.buttonBox.addButton(self.addRowButton, QtGui.QDialogButtonBox.ActionRole)
4437
self.deleteRowButton = QtGui.QPushButton()
4538
self.deleteRowButton.setText("Delete row")
4639
self.buttonBox.addButton(self.addRowButton, QtGui.QDialogButtonBox.ActionRole)
4740
self.buttonBox.addButton(self.deleteRowButton, QtGui.QDialogButtonBox.ActionRole)
48-
self.table = QtGui.QTableWidget(self)
4941
self.table.setColumnCount(len(self.alg.parameters) + len(self.alg.outputs))
5042
self.setTableContent()
5143
self.table.horizontalHeader().setStretchLastSection(True)
5244
self.table.verticalHeader().setVisible(False)
5345
self.table.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
5446
self.progress = QtGui.QProgressBar()
55-
self.progress.setMinimum(0)
56-
self.horizontalLayout.addWidget(self.table)
57-
self.horizontalLayout.addWidget(self.progress)
58-
self.horizontalLayout.addWidget(self.buttonBox)
59-
self.setLayout(self.horizontalLayout)
60-
QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed)
61-
QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed)
62-
QObject.connect(self.addRowButton, QtCore.SIGNAL("clicked()"), self.addRow)
63-
QObject.connect(self.deleteRowButton, QtCore.SIGNAL("clicked()"), self.deleteRow)
64-
QtCore.QMetaObject.connectSlotsByName(self)
47+
self.addRowButton.clicked.connect(self.addRow)
48+
self.deleteRowButton.clicked.connect(self.deleteRow)
6549

6650
def setTableContent(self):
6751
i = 0
@@ -77,7 +61,7 @@ def setTableContent(self):
7761
for i in range(3):
7862
self.addRow()
7963

80-
def okPressed(self):
64+
def accept(self):
8165
self.algs = []
8266
for row in range(self.table.rowCount()):
8367
alg = self.alg.getCopy()#copy.deepcopy(self.alg)
@@ -128,7 +112,7 @@ def loadHTMLResults(self, alg, i):
128112
if isinstance(out, OutputHTML):
129113
SextanteResults.addResult(out.description + "[" + str(i) + "]", out.value)
130114

131-
def cancelPressed(self):
115+
def cancel(self):
132116
self.algs = None
133117
if self.algEx:
134118
self.algEx.terminate()

src/sextante/gui/ParametersDialog.py

-141
Original file line numberDiff line numberDiff line change
@@ -46,144 +46,3 @@ def __init__(self, alg):
4646
self.paramTable = ParametersPanel(self, alg)
4747
AlgorithmExecutionDialog.__init__(self, alg, self.paramTable)
4848
self.executed = False
49-
50-
51-
def setParamValues(self):
52-
params = self.alg.parameters
53-
outputs = self.alg.outputs
54-
55-
for param in params:
56-
if not self.setParamValue(param, self.paramTable.valueItems[param.name]):
57-
return False
58-
59-
for output in outputs:
60-
if output.hidden:
61-
continue
62-
output.value = self.paramTable.valueItems[output.name].getValue()
63-
if not SextanteConfig.getSetting(SextanteConfig.TABLE_LIKE_PARAM_PANEL):
64-
if isinstance(output, (OutputRaster, OutputVector, OutputTable, OutputHTML)):
65-
output.open = self.paramTable.checkBoxes[output.name].isChecked()
66-
67-
return True
68-
69-
def setParamValue(self, param, widget):
70-
if isinstance(param, ParameterRaster):
71-
return param.setValue(widget.getValue())
72-
elif isinstance(param, (ParameterVector, ParameterTable)):
73-
try:
74-
return param.setValue(widget.itemData(widget.currentIndex()).toPyObject())
75-
except:
76-
return param.setValue(widget.getValue())
77-
elif isinstance(param, ParameterBoolean):
78-
return param.setValue(widget.currentIndex() == 0)
79-
elif isinstance(param, ParameterSelection):
80-
return param.setValue(widget.currentIndex())
81-
elif isinstance(param, ParameterFixedTable):
82-
return param.setValue(widget.table)
83-
elif isinstance(param, ParameterRange):
84-
return param.setValue(widget.getValue())
85-
if isinstance(param, ParameterTableField):
86-
return param.setValue(widget.currentText())
87-
elif isinstance(param, ParameterMultipleInput):
88-
if param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
89-
options = QGisLayers.getVectorLayers()
90-
else:
91-
options = QGisLayers.getRasterLayers()
92-
value = []
93-
for index in widget.selectedoptions:
94-
value.append(options[index])
95-
return param.setValue(value)
96-
elif isinstance(param, (ParameterNumber, ParameterFile, ParameterCrs, ParameterExtent)):
97-
return param.setValue(widget.getValue())
98-
else:
99-
return param.setValue(str(widget.text()))
100-
101-
@pyqtSlot()
102-
def accept(self):
103-
#~ try:
104-
if self.setParamValues():
105-
msg = self.alg.checkParameterValuesBeforeExecuting()
106-
if msg:
107-
QMessageBox.critical(self, "Unable to execute algorithm", msg)
108-
return
109-
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
110-
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(False)
111-
buttons = self.paramTable.iterateButtons
112-
iterateParam = None
113-
114-
for i in range(len(buttons.values())):
115-
button = buttons.values()[i]
116-
if button.isChecked():
117-
iterateParam = buttons.keys()[i]
118-
break
119-
120-
self.progress.setMaximum(0)
121-
self.progressLabel.setText("Processing algorithm...")
122-
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
123-
useThread = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
124-
if useThread:
125-
if iterateParam:
126-
self.algEx = AlgorithmExecutor(self.alg, iterateParam)
127-
else:
128-
command = self.alg.getAsCommand()
129-
if command:
130-
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
131-
self.algEx = AlgorithmExecutor(self.alg)
132-
self.algEx.finished.connect(self.finish)
133-
self.algEx.error.connect(self.error)
134-
self.algEx.percentageChanged.connect(self.setPercentage)
135-
self.algEx.textChanged.connect(self.setText)
136-
self.algEx.iterated.connect(self.iterate)
137-
self.algEx.start()
138-
SextanteLog.addToLog(SextanteLog.LOG_INFO,
139-
"Algorithm %s started" % self.alg.name)
140-
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(True)
141-
self.finish()
142-
else:
143-
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
144-
if iterateParam:
145-
UnthreadedAlgorithmExecutor.runalgIterating(self.alg, iterateParam, self)
146-
else:
147-
command = self.alg.getAsCommand()
148-
if command:
149-
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
150-
if UnthreadedAlgorithmExecutor.runalg(self.alg, self):
151-
SextantePostprocessing.handleAlgorithmResults(self.alg, not keepOpen)
152-
self.executed = True
153-
QApplication.restoreOverrideCursor()
154-
if not keepOpen:
155-
self.close()
156-
else:
157-
self.progressLabel.setText("")
158-
self.progress.setMaximum(100)
159-
self.progress.setValue(0)
160-
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
161-
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
162-
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)
163-
164-
165-
else:
166-
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")
167-
168-
@pyqtSlot()
169-
def finish(self):
170-
self.executed = True
171-
SextanteLog.addToLog(SextanteLog.LOG_INFO,
172-
"Algorithm %s finished correctly" % self.alg.name)
173-
QApplication.restoreOverrideCursor()
174-
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
175-
if not keepOpen:
176-
self.close()
177-
else:
178-
self.progressLabel.setText("")
179-
self.progress.setMaximum(100)
180-
self.progress.setValue(0)
181-
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
182-
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
183-
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)
184-
185-
@pyqtSlot(int)
186-
def iterate(self, i):
187-
SextanteLog.addToLog(SextanteLog.LOG_INFO,
188-
"Algorithm %s iteration #%i completed" % (self.alg.name, i))
189-

0 commit comments

Comments
 (0)