def start_raster_upload(self) -> None: """ Use the API to (asynchronously) upload files to Picterra. Default callback for clicking on CTO (default virtual slot for "OK") 1. Parse file list to obtain array of file paths, size and contents 2. For each file launch the async API upload and setup callback The upload and processing is done in parallel by a set of worker threads. In case of errors from the API wrapper it shows an error dialog. https://qgis.org/pyqgis/3.2/gui/File/QgsFileWidget.html#qgis.gui.QgsFileWidget.filePath """ self.upload_type = 'raster' self.ui.label_select.show() self.ui.file_selector.show() file_paths = QgsFileWidget.splitFilePaths( self.ui.file_selector.filePath()) self.file_num = len(file_paths) if self.file_num == 0: self.err_box = error_box("Please select at least one file") self.err_box.show() return # Shows progress bar self.ui.progress_bar.show() self.ui.progress_bar_label.show() # Shows spinner spn_lbl = self.ui.progress_label movie = QMovie(':/plugins/picterra/assets/spinner.gif') spn_lbl.setMovie(movie) spn_lbl.show() movie.start() self.ui.label_select.hide() self.ui.file_selector.hide() self.ui.start_upload_button.setEnabled(False) logger.debug("%s files to upload" % str(self.file_num)) # Loop over files for file_path in file_paths: # Check whether or not file exists info = get_file_info(file_path) if not info: continue # Open image file as binary with open(file_path, 'rb') as f: content = f.read() f.close() # Note the name is the one of the file, not the layer logger.debug("Uploading %s .." % info["name"]) # Launch upload thread try: self.api.upload_raster(info["name"], info["mime"], content, info["size"], self._upload_callback) except ApiError as e: error = str(e) logger.error(error) self.err_box = error_box(error) self.err_box.show() self._reset()
def accept(self): """Method invoked when OK button is clicked.""" paths = self.select_points_action.filePath() file_points = QgsFileWidget.splitFilePaths(paths) crs_selected = self.mQgsProjectionSelectionWidget.crs() crs = crs_selected.authid() import_points(file_points, crs) self.close()
def accept(self): """Method invoked when OK button is clicked.""" name_operator = self.operator_name.value().upper() paths = self.select_pdf_action.filePath() file_operator = QgsFileWidget.splitFilePaths(paths) QgsMessageLog.logMessage( "Ajouter un exploitant: {} avec PDF: {}".format( name_operator, ','.join(file_operator)), 'UnderMap', Qgis.Info) create_operator(name_operator, file_operator, None) self.close()
def accept(self): paths = self.select_pdf_action.filePath() file_operator = QgsFileWidget.splitFilePaths(paths) root_dir = dirname(file_operator[0]) to_dir = join(root_dir, "PDF DECOUPE") """QgsMessageLog.logMessage('UnderMap', "pdf dans: {} avec PDF: {}" .format(to_dir, ','.join(file_operator)), Qgis.Info)""" for item_file in file_operator: split_pdf(item_file, to_dir) self.close()
def accept(self): """Method invoked when OK button is clicked.""" input_layer = self.layer.currentLayer() out = self.result.filePath() file_out = QgsFileWidget.splitFilePaths(out) count_overlap_action(input_layer, out) QgsMessageLog.logMessage( "Input layer: {} and Output: {}".format(input_layer.name(), file_out), 'Footprint', Qgis.Info) self.close()
def _on_raster_selection_changed(self) -> None: """ Executed when the user select one or more files, shows upload CTO. Once at least one file is selected when can proceed with the upload. """ # Show CTO, reset progress bar self.ui.start_upload_button.setEnabled(True) self.ui.progress_bar.setValue(0) # create model/view for file list file_paths = QgsFileWidget.splitFilePaths( self.ui.file_selector.filePath()) self.model.setStringList(get_file_info(f)["name"] for f in file_paths) self.ui.label_filelist.setText( "%s (%d):" % (tr("Selected images"), self.model.rowCount()))
def accept(self): from qgis.utils import iface name_exploitant = iface.activeLayer().name() paths = self.select_pdf_action.filePath() file_operator = QgsFileWidget.splitFilePaths(paths) project_path = get_project_path() to_dir = join(project_path, PROJECT_GROUP[2], name_exploitant, OPERATOR_SUB_DIR[0]) print(file_operator) QgsMessageLog.logMessage( 'UnderMap', "Ajout pdf dans: {} avec PDF: {}".format(name_exploitant, ','.join(file_operator)), Qgis.Info) copy_file(file_operator, to_dir, None) self.close()