Skip to content
Permalink
Browse files
added alternative organization in sextante toolbox
  • Loading branch information
volaya committed Dec 7, 2012
1 parent cb7d1ec commit 7b61b83
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 118 deletions.
@@ -0,0 +1,59 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
SextanteToolbox.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf 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. *
* *
***************************************************************************
"""
from sextante.core.SextanteUtils import SextanteUtils

__author__ = 'Victor Olaya'
__date__ = 'November 2012'
__copyright__ = '(C) 2012, Victor Olaya'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os

class AlgorithmDecorator():

classification = {};

@staticmethod
def loadClassification():
if not os.path.isfile(AlgorithmDecorator.classificationFile()):
return
lines = open(AlgorithmDecorator.classificationFile())
line = lines.readline().strip("\n")
while line != "":
tokens = line.split("\t")
AlgorithmDecorator.classification[tokens[0]] = (tokens[1], tokens[2]);
line = lines.readline().strip("\n")
lines.close()

@staticmethod
def classificationFile():
return os.path.join(SextanteUtils.userFolder(), "sextante_qgis_algclass.txt")

@staticmethod
def getGroupAndName(alg):
if alg.commandLineName() in AlgorithmDecorator.classification:
return AlgorithmDecorator.classification[alg.commandLineName]
else:
return (alg.group, alg.name)





@@ -25,23 +25,20 @@ def __init__(self):
self.parameters = list()
#outputs generated by the algorithm
self.outputs = list()
#name and group for normal toolbox display
self.name = ""
self.group = ""
self.group = ""
#the crs taken from input layers (if possible), and used when loading output layers
self.crs = None
#change any of the following if your algorithm should not appear in the toolbox or modeler
self.showInToolbox = True
self.showInModeler = True
#true if the algorithm has been canceled while it was being executed
#default value is false, so it should be changed in processAlgorithm only if the algorithm
#gets canceled
#self.canceled = False

#to be set by the provider when it loads the algorithm
self.provider = None

self.defineCharacteristics()



def getCopy(self):
newone = copy.copy(self)
newone.parameters = copy.deepcopy(self.parameters)
@@ -52,6 +49,10 @@ def getCopy(self):
#=========================================================
def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")

@staticmethod
def getDefaultIcon():
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")

def helpFile(self):
'''Returns the path to the help file with the description of this algorithm.
@@ -60,9 +61,7 @@ def helpFile(self):

def processAlgorithm(self):
'''Here goes the algorithm itself
There is no return value from this method. If the algorithm gets canceled
while running this method, the self.canceled value should be set to false
instead to indicate it.
There is no return value from this method.
A GeoAlgorithmExecutionException should be raised in case something goes wrong.
'''
pass
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
@@ -29,7 +30,7 @@
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.SextanteLog import SextanteLog

from sextante.core.AlgorithmClassification import AlgorithmDecorator
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor
from sextante.gui.RenderingStyles import RenderingStyles
from sextante.gui.SextantePostprocessing import SextantePostprocessing
@@ -132,9 +133,10 @@ def initialize():
Sextante.modeler.initializeSettings();
#and initialize
SextanteLog.startLogging()
SextanteConfig.initialize()
SextanteConfig.initialize()
SextanteConfig.loadSettings()
RenderingStyles.loadStyles()
AlgorithmDecorator.loadClassification()
Sextante.loadFromProviders()

@staticmethod
@@ -29,6 +29,7 @@

class SextanteConfig():

USE_CATEGORIES = "USE_CATEGORIES"
TABLE_LIKE_PARAM_PANEL = "TABLE_LIKE_PARAM_PANEL"
OUTPUT_FOLDER = "OUTPUT_FOLDER"
RASTER_STYLE = "RASTER_STYLE"
@@ -57,6 +58,7 @@ def initialize():
SextanteConfig.addSetting(Setting("General", SextanteConfig.TABLE_LIKE_PARAM_PANEL, "Show table-like parameter panels", False))
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", True))
SextanteConfig.addSetting(Setting("General", SextanteConfig.SHOW_RECENT_ALGORITHMS, "Show recently executed algorithms", True))
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_CATEGORIES, "Use categories to classify algorithms, instead of providers", False))
SextanteConfig.addSetting(Setting("General", SextanteConfig.OUTPUT_FOLDER,
"Output folder", SextanteUtils.tempFolder()))
SextanteConfig.addSetting(Setting("General", SextanteConfig.RASTER_STYLE,"Style for raster layers",""))
@@ -213,14 +213,14 @@ def processAlgorithm(self, progress):
if layer in self.exportedLayers.keys():
continue
else:
self.setSessionProjection(value, commands)
self.setSessionProjection(layer, commands)
commands.append(self.exportRasterLayer(layer))
elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY:
for layer in layers:
if layer in self.exportedLayers.keys():
continue
else:
self.setSessionProjection(value, commands)
self.setSessionProjection(layer, commands)
commands.append(self.exportVectorLayer(layer))

region = str(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER))
@@ -272,7 +272,7 @@ def processAlgorithm(self, progress):
#an output name to make sure it is unique if the session uses this algorithm several times
uniqueOutputName = out.name + uniqueSufix
command += (" " + out.name + "=" + uniqueOutputName)
# add output file to exported layers, to indicate that they are present in GRASS
# add output file to exported layers, to indicate that they are present in GRASS
self.exportedLayers[out.value]= uniqueOutputName


@@ -285,7 +285,7 @@ def processAlgorithm(self, progress):
filename = out.value
#Raster layer output: adjust region to layer before exporting
commands.append("g.region rast=" + out.name + uniqueSufix)
outputCommands.append("g.region rast=" + out.name)
outputCommands.append("g.region rast=" + out.name + uniqueSufix)
command = "r.out.gdal -c createopt=\"TFW=YES,COMPRESS=LZW\""
command += " input="
command += out.name + uniqueSufix
@@ -301,7 +301,7 @@ def processAlgorithm(self, progress):
command += " olayer=" + os.path.basename(out.value)[:-4]
command += " type=auto"
commands.append(command)
outputCommands.append("g.region rast=" + out.name)
outputCommands.append(command)

#4 Run GRASS
loglines = []
@@ -255,7 +255,7 @@ def prepareGrassExecution(commands):
return command

@staticmethod
def executeGrass(commands, progress, outputCommands ):
def executeGrass(commands, progress, outputCommands = None):
loglines = []
loglines.append("GRASS execution console output")
grassOutDone = False
@@ -34,14 +34,7 @@ class ResultsDialog(QDialog, Ui_DlgResults):
def __init__(self):
QDialog.__init__(self)
self.setupUi(self)

# seems not used and can be removed
#self.groupIcon = QIcon()
#self.groupIcon.addPixmap(self.style().standardPixmap(QStyle.SP_DirClosedIcon),
# QIcon.Normal, QIcon.Off)
#self.groupIcon.addPixmap(self.style().standardPixmap(QStyle.SP_DirOpenIcon),
# QIcon.Normal, QIcon.On)


self.keyIcon = QIcon()
self.keyIcon.addPixmap(self.style().standardPixmap(QStyle.SP_FileIcon))

0 comments on commit 7b61b83

Please sign in to comment.