Skip to content

Commit

Permalink
[sextante] more work on updating to new SIP API
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Jun 9, 2013
1 parent 1d2117f commit ca6e399
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 129 deletions.
22 changes: 10 additions & 12 deletions python/plugins/sextante/algs/ftools/ConvexHull.py
Expand Up @@ -16,6 +16,7 @@
* *
***************************************************************************
"""
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = []
Expand All @@ -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")

2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/Delaunay.py
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/algs/ftools/MeanCoords.py
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/algs/mmqgisx/MMQGISXAlgorithms.py
Expand Up @@ -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())
Expand Down
10 changes: 8 additions & 2 deletions python/plugins/sextante/gdal/GdalUtils.py
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions python/plugins/sextante/gui/AlgorithmExecutionDialog.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/BatchOutputSelectionPanel.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/ExtentSelectionPanel.py
Expand Up @@ -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]
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/sextante/gui/FixedTablePanel.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/InputLayerSelectorPanel.py
Expand Up @@ -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())
7 changes: 0 additions & 7 deletions python/plugins/sextante/gui/MultipleInputPanel.py
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/OutputSelectionPanel.py
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions python/plugins/sextante/gui/ParametersDialog.py
Expand Up @@ -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]"
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/gui/ParametersPanel.py
Expand Up @@ -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]
Expand Down
4 changes: 0 additions & 4 deletions python/plugins/sextante/gui/SextanteToolbox.py
Expand Up @@ -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):

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/modeler/ModelerGraphicItem.py
Expand Up @@ -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
Expand Down
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions python/plugins/sextante/modeler/ModelerParametersDialog.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
8 changes: 2 additions & 6 deletions python/plugins/sextante/modeler/MultilineTextPanel.py
Expand Up @@ -25,10 +25,6 @@

from PyQt4 import QtCore, QtGui

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

class MultilineTextPanel(QtGui.QWidget):

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/tests/GdalTest.py
Expand Up @@ -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()))
Expand All @@ -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()))
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/sextante/tests/GeoAlgorithmTest.py
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions python/plugins/sextante/tests/ModelerAlgorithmTest.py
Expand Up @@ -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()))
Expand Down Expand Up @@ -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()))
Expand All @@ -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()))
Expand Down

0 comments on commit ca6e399

Please sign in to comment.