Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use correct file filters for processing vector/raster input selectors
  • Loading branch information
nyalldawson committed Aug 5, 2017
1 parent d4ad063 commit 470afbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 14 additions & 7 deletions python/plugins/processing/gui/ParameterGuiUtils.py
Expand Up @@ -27,7 +27,7 @@
__revision__ = '$Format:%H$'

from qgis.core import (QgsProcessing,
QgsProcessingParameterDefinition,
QgsProviderRegistry,
QgsProcessingFeatureSourceDefinition,
QgsVectorFileWriter)
from qgis.PyQt.QtCore import QCoreApplication
Expand Down Expand Up @@ -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 ''
3 changes: 1 addition & 2 deletions python/plugins/processing/gui/wrappers.py
Expand Up @@ -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)))
Expand Down

0 comments on commit 470afbe

Please sign in to comment.