I've got a Plugin widget box I'm trying to configure. In one step the user defines the path to where they will export the final layout as a .pdf file. I'm using the following code to configure the box:
class CreatePrintLayoutAndExportMap(QgsProcessingAlgorithm): OUTPUT_PDF_PATH = 'OUTPUT_PDF_PATH' OUTPUT_PDF_FILENAME_DEFAULT = 'Choose file path for pdf output' def initAlgorithm(self, config): self.addParameter( QgsProcessingParameterFileDestination( self.OUTPUT_PDF_PATH, self.tr(self.OUTPUT_PDF_FILENAME_DEFAULT), ".pdf"))
This is good. The issue here is when a user specifies the destination, the file extension is not included and they must type "...filename.pdf" and the file extension is not manually included. Here is what it looks like in action:
If I run the tool, the file is saved as some weird file with no file type. If I explicitly include .pdf at the end of the filename (ex: "...filename.pdf"), I get a .pdf file
I've been looking at documentation for QgsProcessingParameterFileDestination as well as for QgsProcessingParameterRasterDestination as a comparison. The interesting thing is that if I export a raster file using the RasterDestination class, the .tif file extension is automatically included, removing confusion for the user.
Is there a way to automatically include a file extension when using QgsProcessingParameterFileDestination class?