11
11
from sextante .parameters .ParameterTableField import ParameterTableField
12
12
from sextante .parameters .ParameterTable import ParameterTable
13
13
from sextante .gui .AlgorithmExecutor import AlgorithmExecutor
14
- from sextante .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
15
14
from sextante .core .SextanteLog import SextanteLog
16
15
from sextante .gui .SextantePostprocessing import SextantePostprocessing
17
16
from sextante .parameters .ParameterRange import ParameterRange
18
- from sextante .gui .HTMLViewerDialog import HTMLViewerDialog
19
17
from sextante .parameters .ParameterNumber import ParameterNumber
20
18
21
19
from sextante .gui .ParametersPanel import ParametersPanel
@@ -52,7 +50,10 @@ def setupUi(self, dialog, alg):
52
50
dialog .resize (650 , 450 )
53
51
self .buttonBox = QtGui .QDialogButtonBox ()
54
52
self .buttonBox .setOrientation (QtCore .Qt .Horizontal )
55
- self .buttonBox .setStandardButtons (QtGui .QDialogButtonBox .Cancel | QtGui .QDialogButtonBox .Ok )
53
+ self .buttonBox .setStandardButtons (
54
+ QtGui .QDialogButtonBox .Cancel | QtGui .QDialogButtonBox .Close | QtGui .QDialogButtonBox .Ok )
55
+ self .buttonBox .button (QtGui .QDialogButtonBox .Cancel ).setEnabled (False )
56
+
56
57
self .paramTable = ParametersPanel (self .alg , self .dialog )
57
58
self .scrollArea = QtGui .QScrollArea ()
58
59
self .scrollArea .setWidget (self .paramTable )
@@ -93,8 +94,9 @@ def setupUi(self, dialog, alg):
93
94
self .verticalLayout .addWidget (self .progress )
94
95
self .verticalLayout .addWidget (self .buttonBox )
95
96
dialog .setLayout (self .verticalLayout )
96
- QtCore .QObject .connect (self .buttonBox , QtCore .SIGNAL (_fromUtf8 ("accepted()" )), self .accept )
97
- QtCore .QObject .connect (self .buttonBox , QtCore .SIGNAL (_fromUtf8 ("rejected()" )), self .reject )
97
+ self .buttonBox .accepted .connect (self .accept )
98
+ self .buttonBox .rejected .connect (self .dialog .close )
99
+ self .buttonBox .button (QtGui .QDialogButtonBox .Cancel ).clicked .connect (self .cancel )
98
100
QtCore .QMetaObject .connectSlotsByName (dialog )
99
101
100
102
@@ -148,67 +150,76 @@ def setParamValue(self, param, widget):
148
150
else :
149
151
return param .setValue (str (widget .text ()))
150
152
151
-
153
+ @ pyqtSlot ()
152
154
def accept (self ):
153
- try :
154
- keepOpen = SextanteConfig .getSetting (SextanteConfig .KEEP_DIALOG_OPEN )
155
- if self .setParamValues ():
156
- msg = self .alg .checkParameterValuesBeforeExecuting ()
157
- if msg :
158
- QMessageBox .critical (self .dialog , "Unable to execute algorithm" , msg )
159
- return
160
- keepOpen = SextanteConfig .getSetting (SextanteConfig .KEEP_DIALOG_OPEN )
161
- self .buttonBox .button (QtGui .QDialogButtonBox .Ok ).setEnabled (False )
162
- buttons = self .paramTable .iterateButtons
163
- iterateParam = None
164
- for i in range (len (buttons .values ())):
165
- button = buttons .values ()[i ]
166
- if button .isChecked ():
167
- iterateParam = buttons .keys ()[i ]
168
- break
169
-
170
-
171
- self .progress .setMaximum (0 )
172
- self .progressLabel .setText ("Processing algorithm..." )
173
- if iterateParam :
174
- QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
175
- AlgorithmExecutor .runalgIterating (self .alg , iterateParam , self )
176
- QApplication .restoreOverrideCursor ()
177
- else :
178
- QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
179
- command = self .alg .getAsCommand ()
180
- if command :
181
- SextanteLog .addToLog (SextanteLog .LOG_ALGORITHM , command )
182
- ret = AlgorithmExecutor .runalg (self .alg , self )
183
- QApplication .restoreOverrideCursor ()
184
- if ret :
185
- SextantePostprocessing .handleAlgorithmResults (self .alg , not keepOpen )
186
-
187
- self .dialog .executed = True
188
- if not keepOpen :
189
- self .dialog .close ()
190
- else :
191
- self .progressLabel .setText ("" )
192
- self .progress .setValue (0 )
193
- self .buttonBox .button (QtGui .QDialogButtonBox .Ok ).setEnabled (True )
194
-
195
- else :
196
- QMessageBox .critical (self .dialog , "Unable to execute algorithm" , "Wrong or missing parameter values" )
155
+ #~ try:
156
+ if self .setParamValues ():
157
+ msg = self .alg .checkParameterValuesBeforeExecuting ()
158
+ if msg :
159
+ QMessageBox .critical (self .dialog , "Unable to execute algorithm" , msg )
197
160
return
198
- except GeoAlgorithmExecutionException , e :
199
- QApplication .restoreOverrideCursor ()
200
- QMessageBox .critical (self , "Error" ,e .msg )
201
- SextanteLog .addToLog (SextanteLog .LOG_ERROR , e .msg )
202
- if not keepOpen :
203
- self .dialog .close ()
161
+ self .buttonBox .button (QtGui .QDialogButtonBox .Ok ).setEnabled (False )
162
+ buttons = self .paramTable .iterateButtons
163
+ iterateParam = None
164
+
165
+ for i in range (len (buttons .values ())):
166
+ button = buttons .values ()[i ]
167
+ if button .isChecked ():
168
+ iterateParam = buttons .keys ()[i ]
169
+ break
170
+
171
+ self .progress .setMaximum (0 )
172
+ self .progressLabel .setText ("Processing algorithm..." )
173
+ QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
174
+ if iterateParam :
175
+ self .algEx = AlgorithmExecutor (self .alg , iterateParam )
204
176
else :
205
- self .progressLabel .setText ("" )
206
- self .progress .setValue (0 )
207
- self .buttonBox .button (QtGui .QDialogButtonBox .Ok ).setEnabled (True )
177
+ command = self .alg .getAsCommand ()
178
+ if command :
179
+ SextanteLog .addToLog (SextanteLog .LOG_ALGORITHM , command )
180
+ self .algEx = AlgorithmExecutor (self .alg )
181
+ self .algEx .finished .connect (self .finish )
182
+ self .algEx .percentageChanged .connect (self .setPercentage )
183
+ self .algEx .textChanged .connect (self .setText )
184
+ self .algEx .start ()
185
+ self .buttonBox .button (QtGui .QDialogButtonBox .Cancel ).setEnabled (True )
186
+ else :
187
+ QMessageBox .critical (self .dialog , "Unable to execute algorithm" , "Wrong or missing parameter values" )
208
188
189
+ @pyqtSlot ()
190
+ def finish (self ):
191
+ self .dialog .executed = True
192
+ QApplication .restoreOverrideCursor ()
209
193
210
- def reject (self ):
211
- self .dialog .close ()
194
+ keepOpen = SextanteConfig .getSetting (SextanteConfig .KEEP_DIALOG_OPEN )
195
+
196
+ if not keepOpen :
197
+ self .dialog .close ()
198
+ else :
199
+ self .progressLabel .setText ("" )
200
+ self .progress .setValue (0 )
201
+ self .buttonBox .button (QtGui .QDialogButtonBox .Ok ).setEnabled (True )
202
+ self .buttonBox .button (QtGui .QDialogButtonBox .Cancel ).setEnabled (False )
203
+ SextantePostprocessing .handleAlgorithmResults (self .alg , not keepOpen )
204
+
205
+ #~ except GeoAlgorithmExecutionException, e :
206
+ #~ QApplication.restoreOverrideCursor()
207
+ #~ QMessageBox.critical(self, "Error",e.msg)
208
+ #~ SextanteLog.addToLog(SextanteLog.LOG_ERROR, e.msg)
209
+ #~ if not keepOpen:
210
+ #~ self.dialog.close()
211
+ #~ else:
212
+ #~ self.progressLabel.setText("")
213
+ #~ self.progress.setValue(0)
214
+ #~ self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
215
+
216
+ @pyqtSlot ()
217
+ def cancel (self ):
218
+ try :
219
+ self .algEx .finished .disconnect ()
220
+ self .buttonBox .button (QtGui .QDialogButtonBox .Cancel ).setEnabled (False )
221
+ except :
222
+ pass
212
223
213
224
def setPercentage (self , i ):
214
225
if self .progress .maximum () == 0 :
@@ -217,5 +228,3 @@ def setPercentage(self, i):
217
228
218
229
def setText (self , text ):
219
230
self .progressLabel .setText (text )
220
-
221
-
0 commit comments