Skip to content
Permalink
Browse files

Use correct file filters for processing vector/raster input selectors

  • Loading branch information
nyalldawson committed Aug 5, 2017
1 parent d4ad063 commit 470afbebbe7063828cb0e2222c7e6ba4c16ae692
Showing with 15 additions and 9 deletions.
  1. +14 −7 python/plugins/processing/gui/ParameterGuiUtils.py
  2. +1 −2 python/plugins/processing/gui/wrappers.py
@@ -27,7 +27,7 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessing,
QgsProcessingParameterDefinition,
QgsProviderRegistry,
QgsProcessingFeatureSourceDefinition,
QgsVectorFileWriter)
from qgis.PyQt.QtCore import QCoreApplication
@@ -55,22 +55,29 @@ def getFileFilter(param):
exts = QgsVectorFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterMultipleLayers').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
elif param.type() in ('raster', 'rasterDestination'):
return tr('All files (*.*)') + ';;' + ';;'.join(exts)
elif param.type() == 'raster':
return QgsProviderRegistry.instance().fileRasterFilters()
elif param.type() == 'rasterDestination':
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'QgsProcessingParameterRasterDestination').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
return tr('All files (*.*)') + ';;' + ';;'.join(exts)
elif param.type() == 'table':
exts = ['csv', 'dbf']
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'ParameterTable').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
return tr('All files (*.*)') + ';;' + ';;'.join(exts)
elif param.type() == 'sink':
exts = QgsVectorFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = tr('{0} files (*.{1})', 'ParameterVector').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
return tr('All files (*.*)') + ';;' + ';;'.join(exts)
elif param.type() == 'source':
return QgsProviderRegistry.instance().fileVectorFilters()
elif param.type() == 'vector':
return QgsProviderRegistry.instance().fileVectorFilters()
elif param.type() == 'fileOut':
return param.fileFilter()
return tr('All files (*.*)') + ';;' + param.fileFilter()

return ''
@@ -218,8 +218,7 @@ def getFileName(self, initial_value=''):
path = ''

filename, selected_filter = QFileDialog.getOpenFileName(self.widget, self.tr('Select file'),
path, self.tr(
'All files (*.*);;') + getFileFilter(self.param))
path, getFileFilter(self.param))
if filename:
settings.setValue('/Processing/LastInputPath',
os.path.dirname(str(filename)))

0 comments on commit 470afbe

Please sign in to comment.
You can’t perform that action at this time.