Skip to content
Permalink
Browse files

fix buildVRT dialog

  • Loading branch information
etiennesky committed Jun 4, 2013
1 parent 097536c commit 54b2efde668fb0eecfa0239f26052176439ca075
@@ -116,16 +116,16 @@ def getRasterExtensions():
formats = FileFilter.allRastersFilter().split( ";;" )
extensions = []
for f in formats:
if f.contains( "*.bt" ) or f.contains( "*.mpr" ): # Binary Terrain or ILWIS
if string.find(f, "*.bt" ) is not -1 or string.find(f, "*.mpr" ) is not -1: # Binary Terrain or ILWIS
continue
extensions << FileFilter.getFilterExtensions( f )
extensions.extend( FileFilter.getFilterExtensions( f ) )
return extensions

def getVectorExtensions():
formats = FileFilter.allVectorsFilter().split( ";;" )
extensions = []
for f in formats:
extensions.append(FileFilter.getFilterExtensions( f ))
extensions.extend( FileFilter.getFilterExtensions( f ) )
return extensions

class LayerRegistry(QObject):
@@ -201,23 +201,24 @@ def getRasterFiles(path, recursive=False):
if not QFileInfo(path).exists():
return rasters

filter = getRasterExtensions()
# TODO remove *.aux.xml
_filter = getRasterExtensions()
workDir = QDir( path )
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
workDir.setNameFilters( filter )
workDir.setNameFilters( _filter )
files = workDir.entryList()
for f in files:
rasters << path + "/" + f
rasters.append( path + "/" + f )

if recursive:
for myRoot, myDirs, myFiles in os.walk( unicode(path) ):
for dir in myDirs:
workDir = QDir( myRoot + "/" + dir )
workDir.setFilter( QDir.Files | QDir.NoSymLinks | QDir.NoDotAndDotDot )
workDir.setNameFilters( filter )
workDir.setNameFilters( _filter )
workFiles = workDir.entryList()
for f in workFiles:
rasters << myRoot + "/" + dir + "/" + f
rasters.append( myRoot + "/" + dir + "/" + f )

return rasters

@@ -382,8 +383,8 @@ def getDialog(self, parent = None, caption = '', acceptMode = QFileDialog.Accept
firstExt = ext

if firstExt != None:
if firstExt.startsWith('*'):
files.append( firstExt[1:] )
if firstExt.startswith('*'):
files += firstExt[1:]

if useEncoding:
encoding = dialog.encoding()
@@ -403,8 +404,6 @@ def getOpenFileName(self, parent = None, caption = '', filter = '', selectedFilt

@classmethod
def getSaveFileName(self, parent = None, caption = '', filter = '', selectedFilter = None, useEncoding = False):
print("filter:")
print(str(filter))
return self.getDialog(parent, caption, QFileDialog.AcceptSave, QFileDialog.AnyFile, filter, selectedFilter, useEncoding)

@classmethod
@@ -473,7 +472,7 @@ def getFilterExtensions(self, aFilter):
# if there is no extensions or the filter matches all, then return an empty list
# otherwise return the list of estensions
if exts != '' and exts != "*" and exts != "*.*":
extList.append(exts.split(" "))
extList.extend(exts.split(" "))
return extList

@classmethod
@@ -482,13 +481,7 @@ def getFilterName(self, aFilter):

@classmethod
def filenameMatchesFilterExt(self, fileName, ext):
regex = QRegExp(ext)
# use the wildcard matching
regex.setPatternSyntax(QRegExp.Wildcard)

if regex.exactMatch(fileName):
return True
return False
return re.match( '.'+str(ext), fileName ) is not None

# Retrieves gdal information
class GdalConfig:
@@ -66,7 +66,7 @@ def __init__(self, parent, iface, pluginBase, pluginName, pluginCommand):
self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)

self.plugin = pluginBase
self.connect(self.plugin, SIGNAL("valuesChanged(const QStringList &)"), self.refreshArgs)
self.connect(self.plugin, SIGNAL("valuesChanged(PyQt_PyObject)"), self.refreshArgs)

self.pluginLayout.addWidget(self.plugin)
self.plugin.setFocus()
@@ -45,7 +45,7 @@ def __init__(self, iface):
self.inSelector.setType( self.inSelector.FILE )
self.outSelector.setType( self.outSelector.FILE )
self.recurseCheck.hide()
self.visibleRasterLayers = QStringList()
self.visibleRasterLayers = []

self.setParamsStatus(
[
@@ -82,10 +82,10 @@ def onClosing(self):

def onVisibleLayersChanged(self):
# refresh list of visible raster layers
self.visibleRasterLayers = QStringList()
self.visibleRasterLayers = []
for layer in self.iface.mapCanvas().layers():
if Utils.LayerRegistry.isRaster( layer ):
self.visibleRasterLayers << layer.source()
self.visibleRasterLayers.append( layer.source() )

# refresh the text in the command viewer
self.someValueChanged()
@@ -115,42 +115,42 @@ def switchLayerMode(self):
def fillInputFilesEdit(self):
lastUsedFilter = Utils.FileFilter.lastUsedRasterFilter()
files = Utils.FileDialog.getOpenFileNames(self, self.tr( "Select the files for VRT" ), Utils.FileFilter.allRastersFilter(), lastUsedFilter)
if files.isEmpty():
if files == '':
return
Utils.FileFilter.setLastUsedRasterFilter(lastUsedFilter)
self.inSelector.setFilename(files.join(","))
self.inSelector.setFilename(",".join(files))

def fillOutputFileEdit(self):
outputFile = Utils.FileDialog.getSaveFileName(self, self.tr( "Select where to save the VRT" ), self.tr( "VRT (*.vrt)" ))
if outputFile.isEmpty():
if outputFile == '':
return
self.outSelector.setFilename(outputFile)

def fillInputDir( self ):
inputDir = Utils.FileDialog.getExistingDirectory( self, self.tr( "Select the input directory with files for VRT" ))
if inputDir.isEmpty():
if inputDir == '':
return
self.inSelector.setFilename( inputDir )

def getArguments(self):
arguments = QStringList()
arguments = []
if self.resolutionCheck.isChecked() and self.resolutionComboBox.currentIndex() >= 0:
arguments << "-resolution"
arguments << self.resolutions[self.resolutionComboBox.currentIndex()]
arguments.append("-resolution")
arguments.append(self.resolutions[self.resolutionComboBox.currentIndex()])
if self.separateCheck.isChecked():
arguments << "-separate"
arguments.append("-separate")
if self.srcNoDataCheck.isChecked():
arguments << "-srcnodata"
arguments << str(self.srcNoDataSpin.value())
arguments.append("-srcnodata")
arguments.append(str(self.srcNoDataSpin.value()))
if self.allowProjDiffCheck.isChecked():
arguments << "-allow_projection_difference"
arguments << self.getOutputFileName()
arguments.append("-allow_projection_difference")
arguments.append(self.getOutputFileName())
if self.inputSelLayersCheck.isChecked():
arguments << self.visibleRasterLayers
arguments.extend(self.visibleRasterLayers)
elif self.inputDirCheck.isChecked():
arguments << Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() )
arguments.extend(Utils.getRasterFiles( self.getInputFileName(), self.recurseCheck.isChecked() ))
else:
arguments << self.getInputFileName()
arguments.extend(self.getInputFileName())
return arguments

def getOutputFileName(self):
@@ -49,7 +49,8 @@ def __init__(self, iface, commandName):
self.connect(self.base, SIGNAL("refreshArgs()"), self.someValueChanged)

def someValueChanged(self):
self.emit(SIGNAL("valuesChanged(const QStringList &)"), self.getArguments())
if self.initialized:
self.emit(SIGNAL("valuesChanged(PyQt_PyObject)"), self.getArguments())

def onLayersChanged(self):
pass
@@ -79,6 +80,7 @@ def onRun(self):
def onClosing(self):
self.disconnect(Utils.LayerRegistry.instance(), SIGNAL("layersChanged"), self.onLayersChanged)
self.base.onClosing()
self.initialized = False

def onHelp(self):
self.base.onHelp()
@@ -116,7 +118,8 @@ def finished(self, load):
self.addLayerIntoCanvas(fileInfo)
QMessageBox.information(self, self.tr( "Finished" ), self.tr( "Processing completed." ) )
else:
QMessageBox.warning(self, self.tr( "Warning" ), self.tr( "%1 not created." ).arg( outFn ) )
#QMessageBox.warning(self, self.tr( "Warning" ), self.tr( "%1 not created." ).arg( outFn ) )
QMessageBox.warning(self, self.tr( "Warning" ), self.tr( "%s not created." ) % outFn )

# This method is useful to set up options for the command. It sets for each passed widget:
# 1. its passed signals to connect to the BasePluginWidget.someValueChanged() slot,

0 comments on commit 54b2efd

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