Skip to content
Permalink
Browse files

[sextante] more work on updating to new SIP API

  • Loading branch information
volaya committed Jun 9, 2013
1 parent 1d2117f commit ca6e39929732a0bf64a946635bff755bdbcad877
Showing with 103 additions and 129 deletions.
  1. +10 −12 python/plugins/sextante/algs/ftools/ConvexHull.py
  2. +1 −1 python/plugins/sextante/algs/ftools/Delaunay.py
  3. +1 −1 python/plugins/sextante/algs/ftools/MeanCoords.py
  4. +2 −2 python/plugins/sextante/algs/mmqgisx/MMQGISXAlgorithms.py
  5. +8 −2 python/plugins/sextante/gdal/GdalUtils.py
  6. +1 −6 python/plugins/sextante/gui/AlgorithmExecutionDialog.py
  7. +1 −1 python/plugins/sextante/gui/BatchOutputSelectionPanel.py
  8. +1 −1 python/plugins/sextante/gui/ExtentSelectionPanel.py
  9. +0 −5 python/plugins/sextante/gui/FixedTablePanel.py
  10. +1 −1 python/plugins/sextante/gui/InputLayerSelectorPanel.py
  11. +0 −7 python/plugins/sextante/gui/MultipleInputPanel.py
  12. +1 −1 python/plugins/sextante/gui/OutputSelectionPanel.py
  13. +0 −5 python/plugins/sextante/gui/ParametersDialog.py
  14. +1 −1 python/plugins/sextante/gui/ParametersPanel.py
  15. +0 −4 python/plugins/sextante/gui/SextanteToolbox.py
  16. +1 −1 python/plugins/sextante/modeler/ModelerGraphicItem.py
  17. +1 −1 python/plugins/sextante/modeler/ModelerParameterDefinitionDialog.py
  18. +6 −6 python/plugins/sextante/modeler/ModelerParametersDialog.py
  19. +2 −6 python/plugins/sextante/modeler/MultilineTextPanel.py
  20. +2 −2 python/plugins/sextante/tests/GdalTest.py
  21. +2 −2 python/plugins/sextante/tests/GeoAlgorithmTest.py
  22. +3 −3 python/plugins/sextante/tests/ModelerAlgorithmTest.py
  23. +53 −53 python/plugins/sextante/tests/QgisAlgsTest.py
  24. +1 −1 python/plugins/sextante/tests/RunAlgTest.py
  25. +2 −2 python/plugins/sextante/tests/SagaTest.py
  26. +2 −2 python/plugins/sextante/tests/ScriptTest.py
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -68,14 +69,16 @@ def processAlgorithm(self, progress):
fieldName = self.getParameterValue(ConvexHull.FIELD)
layer = QGisLayers.getObjectFromUri(self.getParameterValue(ConvexHull.INPUT))

GEOS_EXCEPT = True
FEATURE_EXCEPT = True


f = QgsField("value")
f.setType(QVariant.String)
f.setLength(255)
if useField:
from threading import settrace

import sys
sys.path.append("D:\eclipse_old\plugins\org.python.pydev_2.6.0.2012062818\pysrc")
from pydevd import *
settrace()
index = layer.fieldNameIndex(fieldName)
fType = layer.pendingFields()[index].type()
if fType == QVariant.Int:
@@ -134,8 +137,7 @@ def processAlgorithm(self, progress):
outFeat.setAttributes([fid,val,area,perim])
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
continue
raise GeoAlgorithmExecutionException("Exception while computing convex hull")
fid += 1
else:
hull = []
@@ -156,11 +158,7 @@ def processAlgorithm(self, progress):
outFeat.setAttributes([0, "all", area, perim])
writer.addFeature(outFeat)
except:
GEOS_EXCEPT = False
raise GeoAlgorithmExecutionException("Exception while computing convex hull")

del writer

if not GEOS_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Geometry exception while computing convex hull")
if not FEATURE_EXCEPT:
SextanteLog.addToLog(SextanteLog.LOG_WARNING, "Feature exception while computing convex hull")

@@ -111,7 +111,7 @@ def processAlgorithm(self, progress):
point = QgsPoint(geom.asPoint())
polygon.append(point)
if step <= 3:
attrs.append(QVariant(ids[index]))
attrs.append(ids[index])
step += 1
feat.setAttributes(attrs)
geometry = QgsGeometry().fromPolygon([polygon])
@@ -79,7 +79,7 @@ def processAlgorithm(self, progress):
for feat in features:
current += 1
progress.setPercentage(current * total)
clazz = feat.attributes()[uniqueIndex].strip()
clazz = str(feat.attributes()[uniqueIndex]).strip()
if weightIndex == -1:
weight = 1.00
else:
@@ -789,8 +789,8 @@ def processAlgorithm(self, progress):
outputtype = QGis.WKBLineString

outfields = layersource.pendingFields()
outfields.append(QgsField(QString("HubName"), QVariant.String))
outfields.append(QgsField(QString("HubDist"), QVariant.Double))
outfields.append(QgsField("HubName", QVariant.String))
outfields.append(QgsField("HubDist", QVariant.Double))

output = self.getOutputFromName(self.SAVENAME)
out = output.getVectorWriter(outfields, outputtype, layersource.crs())
@@ -79,8 +79,14 @@ def getSupportedRasters():
driver = gdal.GetDriver(i)
if driver == None:
continue

shortName = str(QString(driver.ShortName).remove( QRegExp( '\(.*$' ) ).trimmed())
from threading import settrace

import sys
sys.path.append("D:\eclipse_old\plugins\org.python.pydev_2.6.0.2012062818\pysrc")
from pydevd import *
settrace()

shortName = driver.ShortName#.remove( QRegExp( '\(.*$' ) ).trimmed())
metadata = driver.GetMetadata()
if not metadata.has_key(gdal.DCAP_CREATE) or metadata[gdal.DCAP_CREATE] != 'YES':
continue
@@ -55,11 +55,6 @@
from sextante.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor
from sextante.parameters.ParameterString import ParameterString

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class AlgorithmExecutionDialog(QtGui.QDialog):
class InvalidParameterValue(Exception):
def __init__(self, param, widget):
@@ -164,7 +159,7 @@ def setParamValue(self, param, widget):
return param.setValue(widget.getValue())
elif isinstance(param, (ParameterVector, ParameterTable)):
try:
return param.setValue(widget.itemData(widget.currentIndex()).toPyObject())
return param.setValue(widget.itemData(widget.currentIndex()))
except:
return param.setValue(widget.getValue())
elif isinstance(param, ParameterBoolean):
@@ -60,7 +60,7 @@ def __init__(self, output, alg, row, col, batchDialog):

def showSelectionDialog(self):
filefilter = self.output.getFileFilter(self.alg)
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", QtCore.QString(), filefilter)
filename = QtGui.QFileDialog.getSaveFileName(self, "Save file", "", filefilter)
if filename:
filename = unicode(filename)
dlg = AutofillDialog(self.alg)
@@ -130,7 +130,7 @@ def addToRegion(self, layer, first):
self.ymax = max(self.ymax, layer.extent().yMaximum())

def useLayerExtent(self):
CANVAS_KEY = QtCore.QString("Use canvas extent")
CANVAS_KEY = "Use canvas extent"
extentsDict = {}
extentsDict[CANVAS_KEY] = QGisLayers.iface.mapCanvas().extent()
extents = [CANVAS_KEY]
@@ -26,11 +26,6 @@
from PyQt4 import QtCore, QtGui
from sextante.gui.FixedTableDialog import FixedTableDialog

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class FixedTablePanel(QtGui.QWidget):

def __init__(self, param, parent = None):
@@ -64,4 +64,4 @@ def showSelectionDialog(self):
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(unicode(filename)))

def getValue(self):
return self.text.itemData(self.text.currentIndex()).toPyObject()
return self.text.itemData(self.text.currentIndex())
@@ -25,13 +25,6 @@

from PyQt4 import QtCore, QtGui
from sextante.gui.MultipleInputDialog import MultipleInputDialog
from sextante.parameters.ParameterMultipleInput import ParameterMultipleInput
from sextante.core.QGisLayers import QGisLayers

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class MultipleInputPanel(QtGui.QWidget):

@@ -81,7 +81,7 @@ def saveToFile(self):
else:
path = SextanteConfig.getSetting(SextanteConfig.OUTPUT_FOLDER)
lastEncoding = settings.value("/SextanteQGIS/encoding", "System")
fileDialog = QgsEncodingFileDialog(self, "Save file", QString(path), filefilter, lastEncoding)
fileDialog = QgsEncodingFileDialog(self, "Save file", path, filefilter, lastEncoding)
fileDialog.setFileMode(QFileDialog.AnyFile)
fileDialog.setAcceptMode(QFileDialog.AcceptSave)
fileDialog.setConfirmOverwrite(True)
@@ -30,11 +30,6 @@
from PyQt4 import QtCore


try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class ParametersDialog(AlgorithmExecutionDialog):

NOT_SELECTED = "[Not selected]"
@@ -310,7 +310,7 @@ def updateDependentFields(self):
return
if not sender.name in self.dependentItems:
return
layer = sender.itemData(sender.currentIndex()).toPyObject()
layer = sender.itemData(sender.currentIndex())
children = self.dependentItems[sender.name]
for child in children:
widget = self.valueItems[child]
@@ -40,10 +40,6 @@
from sextante.gui.EditRenderingStylesDialog import EditRenderingStylesDialog
from sextante.ui.ui_SextanteToolbox import Ui_SextanteToolbox

try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class SextanteToolbox(QDockWidget, Ui_SextanteToolbox):

@@ -262,7 +262,7 @@ def getLinkPointForOutput(self, outputIndex):
text = self.getAdjustedText(self.element.outputs[outputIndex].description)
font = QtGui.QFont("Verdana", 8)
fm = QtGui.QFontMetricsF(font)
w = fm.width(QtCore.QString(text))
w = fm.width(text)
h = (fm.height() * 1.2) * (outputIndex + 3 + numParams) - fm.height() / 2.0
y = h + ModelerGraphicItem.BOX_HEIGHT / 2.0 + 2
x = -(ModelerGraphicItem.BOX_WIDTH)/2 + 33 + w + 5 if not self.outputFolded else 10
@@ -237,7 +237,7 @@ def okPressed(self):
if self.parentCombo.currentIndex() < 0:
QMessageBox.critical(self, "Unable to define parameter", "Wrong or missing parameter values")
return
parent = self.parentCombo.itemData(self.parentCombo.currentIndex()).toPyObject()
parent = self.parentCombo.itemData(self.parentCombo.currentIndex())
self.param = ParameterTableField(name, description, parent)
elif self.paramType == ModelerParameterDefinitionDialog.PARAMETER_RASTER or isinstance(self.param, ParameterRaster):
self.param = ParameterRaster(name, description, self.yesNoCombo.currentIndex() == 1)
@@ -512,7 +512,7 @@ def setTableContent(self):


def setComboBoxValue(self, combo, value, param):
items = [combo.itemData(i).toPyObject() for i in range(combo.count())]
items = [combo.itemData(i) for i in range(combo.count())]
idx = 0
for item in items:
if item and value:
@@ -632,7 +632,7 @@ def setParamValueLayerOrTable(self, param, widget):
if idx < 0:
return False
else:
value = widget.itemData(widget.currentIndex()).toPyObject()
value = widget.itemData(widget.currentIndex())
self.params[param.name] = value
return True

@@ -643,7 +643,7 @@ def setParamBooleanValue(self, param, widget):
self.params[param.name] = value
self.values[name] = str(widget.currentIndex() == 0)
else:
value = widget.itemData(widget.currentIndex()).toPyObject()
value = widget.itemData(widget.currentIndex())
self.params[param.name] = value
return True

@@ -664,7 +664,7 @@ def setParamTableFieldValue(self, param, widget):
self.values[name] = str(widget.currentText())
return True
else:
value = widget.itemData(widget.currentIndex()).toPyObject()
value = widget.itemData(widget.currentIndex())
self.params[param.name] = value
return True

@@ -705,7 +705,7 @@ def setParamStringValue(self, param, widget):
else:
self.values[name] = str(widget.currentText())
else:
value = widget.itemData(widget.currentIndex()).toPyObject()
value = widget.itemData(widget.currentIndex())
self.params[param.name] = value
return True

@@ -718,7 +718,7 @@ def setParamFileValue(self, param, widget):
s = str(widget.currentText())
self.values[name] = s
else:
value = widget.itemData(widget.currentIndex()).toPyObject()
value = widget.itemData(widget.currentIndex())
self.params[param.name] = value
return True

@@ -25,10 +25,6 @@

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

class MultilineTextPanel(QtGui.QWidget):

@@ -61,10 +57,10 @@ def getValue(self):
if self.combo.currentIndex() == 0:
return unicode(self.textBox.toPlainText())
else:
return self.combo.itemData(self.combo.currentIndex()).toPyObject()
return self.combo.itemData(self.combo.currentIndex())

def setValue(self, value):
items = [self.combo.itemData(i).toPyObject() for i in range(1,self.combo.count())]
items = [self.combo.itemData(i) for i in range(1,self.combo.count())]
idx = 0
for item in items:
idx += 1
@@ -83,7 +83,7 @@ def test_gdalogrogr2ogr(self):
feature=features.next()
attrs=feature.attributes()
expectedvalues=["1","1.1","string a","2","1","string a"]
values=[str(attr.toString()) for attr in attrs]
values=[str(attr) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
@@ -104,7 +104,7 @@ def test_gdalogrogr2ogrWrongExtension(self):
feature=features.next()
attrs=feature.attributes()
expectedvalues=["1","1.1","string a","2","1","string a"]
values=[str(attr.toString()) for attr in attrs]
values=[str(attr) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
@@ -48,8 +48,8 @@ def testWrongformat(self):
self.assertEqual(2, len(features))
feature=features.next()
attrs=feature.attributes()
expectedvalues=["1","1.1","string a","6"]
values=[str(attr.toString()) for attr in attrs]
expectedvalues=["1","1.1","string a","6.0"]
values=[str(attr) for attr in attrs]
self.assertEqual(expectedvalues, values)


@@ -118,7 +118,7 @@ def test_modelersagagrass(self):
feature=features.next()
attrs=feature.attributes()
expectedvalues=["1"]
values=[str(attr.toString()) for attr in attrs]
values=[str(attr) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POINT(270839.65586926 4458983.16267036)'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
@@ -163,7 +163,7 @@ def test_modeleroptionalfield(self):
feature=features.next()
attrs=feature.attributes()
expectedvalues=["0","all","3592.818848","230.989919"]
values=[str(attr.toString()) for attr in attrs]
values=[str(attr) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270839.46818665 4458921.97813894,270778.60197966 4458935.96883677,270786.54279065 4458980.04784113,270803.15756434 4458983.84880322,270839.65586926 4458983.16267036,270855.74530134 4458940.79948673,270839.46818665 4458921.97813894))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))
@@ -184,7 +184,7 @@ def test_modeleremptystring(self):
feature=features.next()
attrs=feature.attributes()
expectedvalues=["1","1.1","string a","2","1","string a","10"]
values=[str(attr.toString()) for attr in attrs]
values=[str(attr) for attr in attrs]
self.assertEqual(expectedvalues, values)
wkt='POLYGON((270807.08580285 4458940.1594565,270798.42294527 4458914.62661676,270780.81854858 4458914.21983449,270763.52289518 4458920.715993,270760.3449542 4458926.6570575,270763.78234766 4458958.22561242,270794.30290024 4458942.16424502,270807.08580285 4458940.1594565))'
self.assertEqual(wkt, str(feature.geometry().exportToWkt()))

0 comments on commit ca6e399

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