Skip to content
Permalink
Browse files
Batch processing already working
Scripting already working
Started with modeler
added saga descriptions to saga folder
added configuration dialog

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@23 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf@gmail.com committed Feb 12, 2012
1 parent c3dd363 commit 6ab1f522bd338f9e6567b53da7e27f391e1edcc4
Showing 453 changed files with 18,921 additions and 359 deletions.
@@ -9,6 +9,9 @@
from sextante.gui.SextanteToolbox import SextanteToolbox
from sextante.core.QGisLayers import QGisLayers
from sextante.gui.HistoryDialog import HistoryDialog
from sextante.core.SextanteUtils import SextanteUtils
from sextante.gui.ConfigDialog import ConfigDialog
from sextante.gui.ModelerDialog import ModelerDialog

cmd_folder = os.path.split(inspect.getfile( inspect.currentframe() ))[0]
if cmd_folder not in sys.path:
@@ -46,20 +49,44 @@ def initGui(self):
QObject.connect(self.historyAction, SIGNAL("triggered()"), self.openHistory)
self.menu.addAction(self.historyAction)

icon = QIcon(os.path.dirname(__file__) + "/config.png")
self.configAction = QAction(icon, \
"&SEXTANTE options and configuration", self.iface.mainWindow())
QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig)
self.menu.addAction(self.configAction)


menuBar = self.iface.mainWindow().menuBar()
menuBar.insertMenu(menuBar.actions()[-1], self.menu)

def unload(self):
self.toolbox.setVisible(False)
self.menu.deleteLater()
#delete temporary output files
folder = SextanteUtils.tempFolder()
for f in os.listdir(folder):
path = os.path.join(folder,f)
try:
os.unlink(path)
except:
#leave files that could not be deleted
pass


def openToolbox(self):
self.toolbox.setVisible(True)

def openModeler(self):
pass
dlg = ModelerDialog()
dlg.exec_()


def openHistory(self):
dlg = HistoryDialog()
dlg.exec_()

def openConfig(self):
dlg = ConfigDialog(self.toolbox)
dlg.exec_()


@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'D:\projects\sextante\workspaces\qgis-plugin\sextante\src\sextante\SextantePlugin.py'
#
# Created: Thu Feb 09 09:36:35 2012
# by: PyQt4 UI code generator 4.9
#
# WARNING! All changes made in this file will be lost!

BIN +611 Bytes src/sextante/config.png
Binary file not shown.
@@ -16,6 +16,15 @@ def __init__(self):
self.providerName = ""
self.crs = None

#methods to overwrite when creating a custom geoalgorithm
#=========================================================
def processAlgorithm(self):
pass

def defineCharacteristics(self):
pass
#=========================================================

def execute(self, progress):
self.setOutputCRSFromInputLayers()
self.processAlgorithm(progress)
@@ -34,12 +43,6 @@ def setOutputCRSFromInputLayers(self):
return


def defineCharacteristics(self):
pass

def processAlgorithm(self):
pass

def putOutput(self, output):
#TODO: check that name does not exist
if isinstance(output, Output):
@@ -0,0 +1,36 @@
from sextante.core.GeoAlgorithm import GeoAlgorithm

class ModelerAlgorithm(GeoAlgorithm):

algs = []
algParameters = []
paramValues = {}

def __init__(self):
GeoAlgorithm.__init__(self)
self.providerName = "model:"

def openModel(self, filename):
pass

def addAlgorithm(self, algName, parametersMap):
self.algs.append(algName)
self.parameters.append(parametersMap)

def addParameterValue(self, value):
name = "HARD_CODE_PARAM_VALUE" + str(len(self.paramValues))
self.paramValues[name] = value
return name

def __str__(self):
s=""
for i in range(len(self.algs)):
s+="ALGORITHM:" + self.algs[i]+"\n"
for param in self.algParameters[i]:
s+=str(param.value)
for param in self.parameters:
s += "PARAMETER:" + param.serialize() + "\n"
for key in self.paramValues.keys():
s += "VALUE:" + key + "=" + str(self.paramValues[key]) + "\n"

return s
@@ -9,23 +9,26 @@
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from sextante.core.SextanteUtils import SextanteUtils
from sextante.mmqgis.MMQGISAlgorithmProvider import MMQGISAlgorithmProvider
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.SextanteLog import SextanteLog

class Sextante:

providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider(),MMQGISAlgorithmProvider()]
providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider()]#,MMQGISAlgorithmProvider()]
algs = {}
actions = {}
contextMenuActions = []


def __init__(self):
pass

@staticmethod
def initialize():
SextanteLog.startLogging()
SextanteConfig.initialize()
SextanteConfig.loadSettings()
Sextante.loadAlgorithms()
Sextante.loadActions()
Sextante.loadContextMenuActions()
SextanteConfig.loadSettings()


@staticmethod
@@ -36,6 +39,7 @@ def updateProviders():

@staticmethod
def loadAlgorithms():
Sextante.updateProviders()
for provider in Sextante.providers:
providerAlgs = provider.algs
algs = {}
@@ -115,15 +119,15 @@ def runalg(name, *args):
return
i = i +1

SextanteUtils.addToLog(SextanteUtils.LOG_ALGORITHM, alg.getAsCommand())
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, alg.getAsCommand())

try:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalg(alg, SilentProgress())
QApplication.restoreOverrideCursor()
return alg.getOuputsChannelsAsMap()
except GeoAlgorithmExecutionException, e:
print "*****Error executing algoritm*****"
print "*****Error executing algorithm*****"
print e.msg

@staticmethod
@@ -0,0 +1,78 @@
from sextante.core.SextanteUtils import SextanteUtils
import os.path

class SextanteConfig():

OUTPUT_FOLDER = "OUTPUT_FOLDER"

settings = {}

@staticmethod
def initialize():
SextanteConfig.addSetting(Setting("General", SextanteConfig.OUTPUT_FOLDER,
"Output folder", os.path.join(SextanteUtils.userFolder(),"outputs" )))


@staticmethod
def addSetting(setting):
SextanteConfig.settings[setting.name] = setting

@staticmethod
def getSettings():
settings={}
for setting in SextanteConfig.settings.values():
if not setting.group in settings:
group = []
settings[setting.group] = group
else:
group = settings[setting.group]
group.append(setting)
return settings

@staticmethod
def configFile():
return os.path.join(SextanteUtils.userFolder(), "sextante_qgis.conf")

@staticmethod
def loadSettings():
lines = open(SextanteConfig.configFile())
line = lines.readline().strip("\n")
while line != "":
tokens = line.split("=")
if tokens[0] in SextanteConfig.settings.keys():
setting = SextanteConfig.settings[tokens[0]]
if isinstance(setting.value, bool):
setting.value = bool(tokens[1])
else:
setting.value = tokens[1]
SextanteConfig.addSetting(setting)
line = lines.readline().strip("\n")
lines.close()

@staticmethod
def saveSettings():
fout = open(SextanteConfig.configFile(), "w")
for setting in SextanteConfig.settings.values():
fout.write(str(setting) + "\n")
fout.close()

@staticmethod
def getSetting(name):
if name in SextanteConfig.settings.keys():
return SextanteConfig.settings[name].value
else:
return None



class Setting():

def __init__(self, group, name, description, default):
self.group=group
self.name = name
self.description = description
self.default = default
self.value = default

def __str__(self):
return self.name + "=" + str(self.value)
@@ -0,0 +1,71 @@
import datetime
import os
from sextante.core.SextanteUtils import SextanteUtils
class SextanteLog():

LOG_ERROR = "ERROR"
LOG_INFO = "INFO"
LOG_WARNING = "WARNING"
LOG_ALGORITHM = "ALGORITHM"

@staticmethod
def startLogging():
logfile = open(SextanteLog.logFilename(), "w")
logfile.write("Started logging at " + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S"))
logfile.close()

@staticmethod
def logFilename():
batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log"
return batchfile


@staticmethod
def addToLog(msgtype, msg):
if isinstance(msg, list):
text=""
for i in range(0, len(msg)):
text+=msg[i] + "|"
text = text[:-1]
else:
text = str(msg)
line = msgtype + "|" + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "|" + text + "\n"
logfile = open(SextanteLog.logFilename(), "a")
logfile.write(line)
logfile.close()

@staticmethod
def getLogEntries():
entries={}
errors=[]
algorithms=[]
warnings=[]
info=[]
lines = open(SextanteLog.logFilename())
line = lines.readline()
while line != "":
line = line.strip("\n").strip()
tokens = line.split("|")
text=""
for i in range(2, len(tokens)):
text+=tokens[i] + "|"
if line.startswith(SextanteLog.LOG_ERROR):
errors.append(LogEntry(tokens[1], text))
elif line.startswith(SextanteLog.LOG_ALGORITHM):
algorithms.append(LogEntry(tokens[1], tokens[2]))
elif line.startswith(SextanteLog.LOG_WARNING):
warnings.append(LogEntry(tokens[1], text))
elif line.startswith(SextanteLog.LOG_INFO):
info.append(LogEntry(tokens[1], text))
line = lines.readline()
lines.close()
entries[SextanteLog.LOG_ERROR] = errors
entries[SextanteLog.LOG_ALGORITHM] = algorithms
entries[SextanteLog.LOG_INFO] = info
entries[SextanteLog.LOG_WARNING] = warnings
return entries

class LogEntry():
def __init__(self, date, text):
self.date = date
self.text = text

0 comments on commit 6ab1f52

Please sign in to comment.