From ed13b42fbc04b8835a41dbcd6724c2a8949076be Mon Sep 17 00:00:00 2001 From: Sergio Botero Date: Tue, 25 Feb 2014 16:18:45 -0500 Subject: [PATCH] Clean after success In this changes I clean the output layer field after a successful execution, closes #16 This change also disables the OK button while the algorithm is running but the Cancel button is still enabled, this is related to #6 --- clusterpy_lightdialog.py | 62 ++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/clusterpy_lightdialog.py b/clusterpy_lightdialog.py index 46bcd3a..2b92ba6 100644 --- a/clusterpy_lightdialog.py +++ b/clusterpy_lightdialog.py @@ -108,38 +108,50 @@ def addToCanvas(self): addShapeToCanvas(self.layer_path.text()) def accept(self): - layerindex = self.layer_combo.currentIndex() - if layerindex < 0: - return - layer = self.mc.layer(layerindex) - info = { - 'attrname' : self.attribute_combo.currentText(), - 'thresholdattr' : self.threshold_attr_combo.currentText(), - 'threshold' : self.threshold_spin.value(), - 'maxit' : self.maxit_spin.value(), - 'tabumax' : self.tabumax_spin.value(), - 'tabusize' : self.tabulength_spin.value(), - 'output_path' : self.layer_path.text(), - 'layer' : layer - } - worker = workers.MaxPWorker(info) - thread = QtCore.QThread(self) - worker.moveToThread(thread) - worker.finished.connect(self.finishRun) - worker.progress.connect(self.updateProgress) - thread.started.connect(worker.run) - self.thread = thread - self.worker = worker - thread.start() + if self.layer_path.text() == "": + QtGui.QMessageBox.warning(self, + "Clusterpy", + "Please specify output shapefile") + else: + self.okbutton = self.buttonBox.button( QtGui.QDialogButtonBox.Ok ) + self.okbutton.setEnabled(False) + layerindex = self.layer_combo.currentIndex() + if layerindex < 0: + return + layer = self.mc.layer(layerindex) + info = { + 'attrname' : self.attribute_combo.currentText(), + 'thresholdattr' : self.threshold_attr_combo.currentText(), + 'threshold' : self.threshold_spin.value(), + 'maxit' : self.maxit_spin.value(), + 'tabumax' : self.tabumax_spin.value(), + 'tabusize' : self.tabulength_spin.value(), + 'output_path' : self.layer_path.text(), + 'layer' : layer + } + worker = workers.MaxPWorker(info) + thread = QtCore.QThread(self) + worker.moveToThread(thread) + worker.finished.connect(self.finishRun) + worker.progress.connect(self.updateProgress) + thread.started.connect(worker.run) + self.thread = thread + self.worker = worker + thread.start() def finishRun(self, success, outputmsg): self.worker.deleteLater() self.thread.quit() self.thread.wait() self.thread.deleteLater() + self.okbutton.setEnabled(True) if success: self.addToCanvas() - self.showMessage("Clusterpy", "Success. File:" + outputmsg ) + self.showMessage("Clusterpy", "Success. File:" + outputmsg, + duration=10 ) + self.layer_path.clear() + self.add_canvas.setChecked(Qt.Unchecked) + self.updateProgress(0) else: self.showMessage("Clusterpy: Error", outputmsg, @@ -149,7 +161,7 @@ def updateProgress(self, value): self.progressBar.setValue(value) def showMessage(self, msgtype, msgtext, level=QgsMessageBar.INFO, - duration=5): + duration=30): messagebar = self.iface.messageBar() messagebar.pushMessage(msgtype, msgtext, level=level, duration=duration)