Skip to content
Permalink
Browse files

Move getFileFilter from params to gui wrappers

  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent 379d060 commit 7683b25f81462c0f375a5afd419fecdaab2c1084
@@ -428,17 +428,6 @@ def getAsString(self, value):
return str(layer.source())
return s

def getFileFilter(self):
if self.datatype == dataobjects.TYPE_RASTER:
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
elif self.datatype == dataobjects.TYPE_FILE:
return self.tr('All files (*.*)', 'ParameterMultipleInput')
else:
exts = QgsVectorFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = self.tr('{0} files (*.{1})', 'ParameterMultipleInput').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)

def dataType(self):
if self.datatype == dataobjects.TYPE_VECTOR_POINT:
return 'points'
@@ -627,12 +616,6 @@ def getSafeExportedLayer(self):
self.exported = self.value
return self.exported

def getFileFilter(self):
exts = dataobjects.getSupportedOutputRasterLayerExtensions()
for i in range(len(exts)):
exts[i] = self.tr('{0} files (*.{1})', 'ParameterRaster').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)

def getAsScriptCode(self):
param_type = ''
if self.flags() & QgsProcessingParameterDefinition.FlagOptional:
@@ -821,12 +804,6 @@ def getSafeExportedTable(self):
self.exported = self.value
return self.exported

def getFileFilter(self):
exts = ['csv', 'dbf']
for i in range(len(exts)):
exts[i] = self.tr('{0} files (*.{1})', 'ParameterTable').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)

def getAsScriptCode(self):
param_type = ''
if self.flags() & QgsProcessingParameterDefinition.FlagOptional:
@@ -951,12 +928,6 @@ def getSafeExportedLayer(self):
self.exported = self.value
return self.exported

def getFileFilter(self):
exts = QgsVectorFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = self.tr('{0} files (*.{1})', 'ParameterVector').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)

def dataType(self):
return dataobjects.vectorDataType(self)

@@ -44,7 +44,7 @@
from processing.core.parameters import ParameterRaster
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTable

from processing.gui.ParameterGuiUtils import getFileFilter
from processing.tools import dataobjects


@@ -145,7 +145,7 @@ def showFileSelectionDialog(self):
path = ''

ret, selected_filter = QFileDialog.getOpenFileNames(self, self.tr('Open file'), path,
self.tr('All files (*.*);;') + self.param.getFileFilter())
self.tr('All files (*.*);;') + getFileFilter(self.param))
if ret:
files = list(ret)
settings.setValue('/Processing/LastInputPath',
@@ -42,6 +42,7 @@
from processing.core.outputs import OutputVector
from processing.core.outputs import OutputDirectory
from processing.gui.PostgisTableSelector import PostgisTableSelector
from processing.gui.ParameterGuiUtils import getFileFilter

pluginPath = os.path.split(os.path.dirname(__file__))[0]
WIDGET, BASE = uic.loadUiType(
@@ -187,7 +188,7 @@ def saveToSpatialite(self):
self.leText.setText("spatialite:" + uri.uri())

def selectFile(self):
fileFilter = self.parameter.getFileFilter(self.alg)
fileFilter = getFileFilter(self.parameter)

settings = QgsSettings()
if settings.contains('/Processing/LastOutputPath'):
@@ -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 ''
@@ -111,7 +111,7 @@
from processing.gui.BatchInputSelectionPanel import BatchInputSelectionPanel
from processing.gui.FixedTablePanel import FixedTablePanel
from processing.gui.ExtentSelectionPanel import ExtentSelectionPanel

from processing.gui.ParameterGuiUtils import getFileFilter
DIALOG_STANDARD = 'standard'
DIALOG_BATCH = 'batch'
DIALOG_MODELER = 'modeler'
@@ -207,7 +207,7 @@ def getFileName(self, initial_value=''):

filename, selected_filter = QFileDialog.getOpenFileName(self.widget, self.tr('Select file'),
path, self.tr(
'All files (*.*);;') + self.param.getFileFilter())
'All files (*.*);;') + getFileFilter(self.param))
if filename:
settings.setValue('/Processing/LastInputPath',
os.path.dirname(str(filename)))
@@ -1217,6 +1217,40 @@ def validator(v):
return self.comboValue(validator)


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 self.tr('All files (*.*)', 'QgsProcessingParameterMultipleLayers')
else:
exts = QgsVectorFileWriter.supportedFormatExtensions()
for i in range(len(exts)):
exts[i] = self.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] = self.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] = self.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] = self.tr('{0} files (*.{1})', 'ParameterVector').format(exts[i].upper(), exts[i].lower())
return ';;'.join(exts)
return ''


class WidgetWrapperFactory:

"""

0 comments on commit 7683b25

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