Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move getFileFilter from params to gui wrappers
- Loading branch information
1 parent
379d060
commit 7683b25
Showing
5 changed files
with
114 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
""" | |||
*************************************************************************** | |||
ParameterGuiUtils.py | |||
--------------------- | |||
Date : June 2017 | |||
Copyright : (C) 2017 by Nyall Dawson | |||
Email : nyall dot dawson at gmail dot com | |||
*************************************************************************** | |||
* * | |||
* This program is free software; you can redistribute it and/or modify * | |||
* it under the terms of the GNU General Public License as published by * | |||
* the Free Software Foundation; either version 2 of the License, or * | |||
* (at your option) any later version. * | |||
* * | |||
*************************************************************************** | |||
""" | |||
|
|||
|
|||
__author__ = 'Nyall Dawson' | |||
__date__ = 'June 2017' | |||
__copyright__ = '(C) 2017, Nyall Dawson' | |||
|
|||
# This will get replaced with a git SHA1 when you do a git archive | |||
|
|||
__revision__ = '$Format:%H$' | |||
|
|||
from qgis.core import ( | |||
QgsProcessingParameterDefinition, | |||
QgsProcessingFeatureSourceDefinition, | |||
QgsVectorFileWriter) | |||
from qgis.PyQt.QtCore import QCoreApplication | |||
from processing.tools import dataobjects | |||
|
|||
|
|||
def tr(string, context=''): | |||
if context == '': | |||
context = 'Processing' | |||
return QCoreApplication.translate(context, string) | |||
|
|||
|
|||
def getFileFilter(param): | |||
""" | |||
Returns a suitable file filter pattern for the specified parameter definition | |||
:param param: | |||
:return: | |||
""" | |||
if param.type() == 'multilayer': | |||
if param.layerType() == QgsProcessingParameterDefinition.TypeRaster: | |||
exts = dataobjects.getSupportedOutputRasterLayerExtensions() | |||
elif param.layerType() == QgsProcessingParameterDefinition.TypeFile: | |||
return tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers') | |||
else: | |||
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() == 'raster': | |||
exts = dataobjects.getSupportedOutputRasterLayerExtensions() | |||
for i in range(len(exts)): | |||
exts[i] = tr('{0} files (*.{1})', 'ParameterRaster').format(exts[i].upper(), exts[i].lower()) | |||
return ';;'.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) | |||
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 '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters