def __init__(self,iface): GenericTool.__init__(self, iface) self.labelName = "Hagens Filter" self.dlg = HagensFilterDialog() self.dlg.lineEditImages.clear() self.dlg.lineEditFlags.clear() self.dlg.lineEditOut.clear() self.dlg.lineEditOutComposite.clear() self.dlg.pushButtonImages.clicked.connect(self.InputFolder) self.dlg.pushButtonFlags.clicked.connect(self.InputFolderFlags) self.dlg.pushButtonOut.clicked.connect(self.OutputImage)
class HagensFilter(GenericTool): """QGIS Plugin Implementation.""" def __init__(self,iface): GenericTool.__init__(self, iface) self.labelName = "Hagens Filter" self.dlg = HagensFilterDialog() self.dlg.lineEditImages.clear() self.dlg.lineEditFlags.clear() self.dlg.lineEditOut.clear() self.dlg.lineEditOutComposite.clear() self.dlg.pushButtonImages.clicked.connect(self.InputFolder) self.dlg.pushButtonFlags.clicked.connect(self.InputFolderFlags) self.dlg.pushButtonOut.clicked.connect(self.OutputImage) def run(self): """Run method that performs all the real work""" # show the dialog self.dlg.show() # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result: iFolder = self.dlg.lineEditImages.text() iFlag = self.dlg.lineEditFlags.text() oFolder = self.dlg.lineEditOut.text() Composite = self.dlg.lineEditOutComposite.text() if (len(Composite)==0) or (len(iFolder)==0) or (len(iFlag)==0) or (len(oFolder)==0): QMessageBox.warning(qgis.utils.iface.mainWindow(),"Hagens Filter"," Fields empty ") else: ListInput = sorted(glob.glob(os.path.join(iFolder,"*.tif"))) ListFlags = sorted(glob.glob(os.path.join(iFlag,"*.tif"))) Nbands = len(ListInput) NbandsFlags = len(ListFlags) if Nbands == NbandsFlags: try: Composite = int(Composite) self.startWorker(ListInput,ListFlags,oFolder,Composite) except: QMessageBox.warning(qgis.utils.iface.mainWindow(),"Hagens Filter","Image fo Year is not integer") else: QMessageBox.warning(qgis.utils.iface.mainWindow(),"Hagens Filter","Number of input images is higher or lower than the images flags") #Function input folder images def InputFolder(self): iFolder = QFileDialog.getExistingDirectory(self.dlg,'Insert Folder Images','',QFileDialog.ShowDirsOnly) self.dlg.lineEditImages.setText(iFolder) #Function input folder flags def InputFolderFlags(self): iFolder = QFileDialog.getExistingDirectory(self.dlg,'Insert Folder Flags','',QFileDialog.ShowDirsOnly) self.dlg.lineEditFlags.setText(iFolder) #Function output folder images def OutputImage(self): oFolder = QFileDialog.getExistingDirectory(self.dlg,'Output Folder','',QFileDialog.ShowDirsOnly) self.dlg.lineEditOut.setText(oFolder) #Function Start thread processing def startWorker(self, inFolder, inFlag, outFolder,Composite): # create a new worker instance worker = Worker(inFolder, inFlag, outFolder,Composite) #Create Progressbar qgis.utils.iface.messageBar().clearWidgets() progressMessageBar = qgis.utils.iface.messageBar().createMessage('Executing Hagens Filter...') progressBar = QProgressBar() progressBar.setMaximum(100) progressMessageBar.layout().addWidget(progressBar) qgis.utils.iface.messageBar().pushWidget(progressMessageBar) self.progressMessageBar = progressMessageBar # start the worker in a new thread thread = QThread() worker.moveToThread(thread) worker.finished.connect(self.workerFinished) worker.error.connect(self.workerError) worker.progress.connect(progressBar.setValue) thread.started.connect(worker.HagensFilterCalc) thread.start() self.thread = thread self.worker = worker #Function to finished thread processing def workerFinished(self,value): # clean up the worker and thread self.worker.deleteLater() self.thread.quit() self.thread.wait() self.thread.deleteLater() qgis.utils.iface.messageBar().clearWidgets() if value == 0: QMessageBox.information(qgis.utils.iface.mainWindow(),"Hagens Filter","Processing sucessfully...") else: QMessageBox.warning(qgis.utils.iface.mainWindow(),"Hagens Filter","Error in the images. Please, check the error log on:"+'\n'+os.path.join(self.dlg.lineEditImages.text(),"LogErros.txt")) #Function report error in work def workerError(self, e, exception_string): QgsMessageLog.logMessage('Worker thread raised an exception:\n'.format(exception_string), level=QgsMessageLog.CRITICAL)