1717***************************************************************************
1818"""
1919from sextante .gui .CrsSelectionPanel import CrsSelectionPanel
20+ from sextante .outputs .OutputNumber import OutputNumber
21+ from sextante .outputs .OutputString import OutputString
22+ from sextante .core .SextanteUtils import SextanteUtils
2023
2124__author__ = 'Victor Olaya'
2225__date__ = 'August 2012'
@@ -79,12 +82,14 @@ def __init__(self, alg):
7982 self .deleteRowButton .setText ("Delete row" )
8083 self .buttonBox .addButton (self .addRowButton , QtGui .QDialogButtonBox .ActionRole )
8184 self .buttonBox .addButton (self .deleteRowButton , QtGui .QDialogButtonBox .ActionRole )
82- self .table .setColumnCount (len (self .alg .parameters ) + len (self .alg .outputs ))
85+
86+ self .table .setColumnCount (self .alg .getVisibleParametersCount () + self .alg .getVisibleOutputsCount ())
8387 self .setTableContent ()
8488 self .table .horizontalHeader ().setStretchLastSection (True )
8589 self .table .verticalHeader ().setVisible (False )
8690 self .table .setSizePolicy (QtGui .QSizePolicy .Expanding , QtGui .QSizePolicy .Expanding )
87- self .progress = QtGui .QProgressBar ()
91+ #self.progress = QtGui.QProgressBar()
92+ #self.progress.setMaximum(100)
8893 self .addRowButton .clicked .connect (self .addRow )
8994 self .deleteRowButton .clicked .connect (self .deleteRow )
9095
@@ -110,13 +115,17 @@ def accept(self):
110115 alg = self .alg .getCopy ()#copy.deepcopy(self.alg)
111116 col = 0
112117 for param in alg .parameters :
118+ if param .hidden :
119+ continue
113120 widget = self .table .cellWidget (row , col )
114121 if not self .setParameterValueFromWidget (param , widget , alg ):
115122 QMessageBox .critical (self .dialog , "Unable to execute batch process" , "Wrong or missing parameter values" )
116123 self .algs = None
117124 return
118125 col += 1
119126 for out in alg .outputs :
127+ if out .hidden :
128+ continue
120129 widget = self .table .cellWidget (row , col )
121130 text = widget .getValue ()
122131 if text .strip () != "" :
@@ -129,18 +138,19 @@ def accept(self):
129138 self .algs .append (alg )
130139
131140 QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
132- self .progress .setMaximum (len (self .algs ))
141+ # self.progress.setMaximum(len(self.algs))
133142 self .table .setEnabled (False )
134143 if SextanteConfig .getSetting (SextanteConfig .USE_THREADS ):
135- self .progress .setValue (0 )
144+ # self.progress.setValue(0)
136145 self .nextAlg (0 )
137146 else :
138147 i = 1
139148 self .progress .setMaximum (len (self .algs ))
140149 for alg in self .algs :
141- if UnthreadedAlgorithmExecutor .runalg (alg , SilentProgress ()):
142- self .progress .setValue (i )
143- self .loadHTMLResults (alg , i )
150+ self .setBaseText ("Processing algorithm " + str (i ) + "/" + str (len (self .algs )) + "..." )
151+ if UnthreadedAlgorithmExecutor .runalg (alg , self ):#SilentProgress()):
152+ #self.progress.setValue(i)
153+ #self.loadHTMLResults(alg, i)
144154 i += 1
145155 else :
146156 QApplication .restoreOverrideCursor ()
@@ -164,31 +174,53 @@ def cancel(self):
164174 @pyqtSlot ()
165175 def finish (self , i ):
166176 i += 1
167- self .progress .setValue (i )
177+ self .progress .setValue (i )
168178 if len (self .algs ) == i :
169179 self .finishAll ()
170180 self .algEx = None
171181 else :
172182 self .nextAlg (i )
173-
183+
174184 @pyqtSlot ()
175185 def error (self , msg ):
176186 QApplication .restoreOverrideCursor ()
177187 QMessageBox .critical (self , "Error" , msg )
178188 SextanteLog .addToLog (SextanteLog .LOG_ERROR , msg )
179189 self .close ()
180-
190+
191+
181192 def nextAlg (self , i ):
193+ self .setBaseText ("Processing algorithm " + str (i ) + "/" + str (len (self .algs )) + "..." )
182194 self .algEx = AlgorithmExecutor (self .algs [i ]);
195+ self .algEx .percentageChanged .connect (self .setPercentage )
196+ self .algEx .textChanged .connect (self .setText )
183197 self .algEx .error .connect (self .error )
184198 self .algEx .finished .connect (lambda : self .finish (i ))
185199 self .algEx .start ()
186200
201+ def createSummaryTable (self ):
202+ createTable = False
203+ for out in self .algs [0 ].outputs :
204+ if isinstance (out , (OutputNumber ,OutputString )):
205+ createTable = True
206+ break
207+ if not createTable :
208+ return
209+ outputFile = SextanteUtils .getTempFilename ("html" )
210+ f = open (outputFile , "w" )
211+ for alg in self .algs :
212+ for out in alg .outputs :
213+ if isinstance (out , (OutputNumber ,OutputString )):
214+ f .write ("<p>" + out .description + ": " + str (out .value ) + "</p>\n " )
215+ f .close ()
216+ SextanteResults .addResult (self .algs [0 ].name + "[summary]" , outputFile )
217+
187218 def finishAll (self ):
188219 i = 0
189220 for alg in self .algs :
190221 self .loadHTMLResults (alg , i )
191222 i = i + 1
223+ self .createSummaryTable ()
192224 QApplication .restoreOverrideCursor ()
193225 self .table .setEnabled (True )
194226 QMessageBox .information (self , "Batch processing" , "Batch processing successfully completed!" )
@@ -266,4 +298,10 @@ def showAdvancedParametersClicked(self):
266298 for param in self .alg .parameters :
267299 if param .isAdvanced :
268300 self .table .setColumnHidden (i , not self .showAdvanced )
269- i += 1
301+ i += 1
302+
303+ def setText (self , text ):
304+ self .progressLabel .setText (self .baseText + " --- [" + text + "]" )
305+
306+ def setBaseText (self , text ):
307+ self .baseText = text
0 commit comments