Skip to content

Commit

Permalink
[processing] added extension option to ParameterFile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Jun 16, 2014
1 parent 3d15239 commit 72d3385
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions python/plugins/processing/gui/FileSelectionPanel.py
Expand Up @@ -32,8 +32,9 @@

class FileSelectionPanel(QtGui.QWidget):

def __init__(self, isFolder):
def __init__(self, isFolder, ext = None):
super(FileSelectionPanel, self).__init__(None)
self.ext = ext or '*'
self.isFolder = isFolder
self.horizontalLayout = QtGui.QHBoxLayout(self)
self.horizontalLayout.setSpacing(2)
Expand Down Expand Up @@ -70,7 +71,7 @@ def showSelectionDialog(self):
os.path.dirname(unicode(folder)))
else:
filenames = QtGui.QFileDialog.getOpenFileNames(self, 'Open file',
path, '*.*')
path, '*.' + self.ext)
if filenames:
self.text.setText(u';'.join(filenames))
settings.setValue('/Processing/LastInputPath',
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ParametersPanel.py
Expand Up @@ -277,7 +277,7 @@ def getWidgetFromParameter(self, param):
elif isinstance(param, ParameterRange):
item = RangePanel(param)
elif isinstance(param, ParameterFile):
item = FileSelectionPanel(param.isFolder)
item = FileSelectionPanel(param.isFolder, param.ext)
elif isinstance(param, ParameterMultipleInput):
if param.datatype == ParameterMultipleInput.TYPE_FILE:
item = MultipleFileInputPanel()
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/parameters/ParameterFile.py
Expand Up @@ -30,9 +30,10 @@

class ParameterFile(Parameter):

def __init__(self, name='', description='', isFolder=False, optional=True):
def __init__(self, name='', description='', isFolder=False, optional=True, ext = None):
Parameter.__init__(self, name, description)
self.value = None
self.ext = ext
self.isFolder = isFolder
self.optional = optional

Expand All @@ -51,6 +52,8 @@ def setValue(self, obj):
return False
else:
self.value = ''
if self.ext is not None and self.value != '':
return self.value.endswith(self.ext)
return True

def deserialize(self, s):
Expand Down

0 comments on commit 72d3385

Please sign in to comment.