Skip to content

Commit 6ab1f52

Browse files
author
volayaf@gmail.com
committed
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
1 parent c3dd363 commit 6ab1f52

File tree

453 files changed

+18921
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

453 files changed

+18921
-359
lines changed

src/sextante/SextantePlugin.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from sextante.gui.SextanteToolbox import SextanteToolbox
1010
from sextante.core.QGisLayers import QGisLayers
1111
from sextante.gui.HistoryDialog import HistoryDialog
12+
from sextante.core.SextanteUtils import SextanteUtils
13+
from sextante.gui.ConfigDialog import ConfigDialog
14+
from sextante.gui.ModelerDialog import ModelerDialog
1215

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

52+
icon = QIcon(os.path.dirname(__file__) + "/config.png")
53+
self.configAction = QAction(icon, \
54+
"&SEXTANTE options and configuration", self.iface.mainWindow())
55+
QObject.connect(self.configAction, SIGNAL("triggered()"), self.openConfig)
56+
self.menu.addAction(self.configAction)
57+
58+
4959
menuBar = self.iface.mainWindow().menuBar()
5060
menuBar.insertMenu(menuBar.actions()[-1], self.menu)
5161

5262
def unload(self):
5363
self.toolbox.setVisible(False)
5464
self.menu.deleteLater()
65+
#delete temporary output files
66+
folder = SextanteUtils.tempFolder()
67+
for f in os.listdir(folder):
68+
path = os.path.join(folder,f)
69+
try:
70+
os.unlink(path)
71+
except:
72+
#leave files that could not be deleted
73+
pass
74+
5575

5676
def openToolbox(self):
5777
self.toolbox.setVisible(True)
5878

5979
def openModeler(self):
60-
pass
80+
dlg = ModelerDialog()
81+
dlg.exec_()
82+
6183

6284
def openHistory(self):
6385
dlg = HistoryDialog()
6486
dlg.exec_()
6587

88+
def openConfig(self):
89+
dlg = ConfigDialog(self.toolbox)
90+
dlg.exec_()
91+
92+

src/sextante/SextantePlugin.py.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file 'D:\projects\sextante\workspaces\qgis-plugin\sextante\src\sextante\SextantePlugin.py'
4+
#
5+
# Created: Thu Feb 09 09:36:35 2012
6+
# by: PyQt4 UI code generator 4.9
7+
#
8+
# WARNING! All changes made in this file will be lost!
9+

src/sextante/config.png

611 Bytes
Loading

src/sextante/core/GeoAlgorithm.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ def __init__(self):
1616
self.providerName = ""
1717
self.crs = None
1818

19+
#methods to overwrite when creating a custom geoalgorithm
20+
#=========================================================
21+
def processAlgorithm(self):
22+
pass
23+
24+
def defineCharacteristics(self):
25+
pass
26+
#=========================================================
27+
1928
def execute(self, progress):
2029
self.setOutputCRSFromInputLayers()
2130
self.processAlgorithm(progress)
@@ -34,12 +43,6 @@ def setOutputCRSFromInputLayers(self):
3443
return
3544

3645

37-
def defineCharacteristics(self):
38-
pass
39-
40-
def processAlgorithm(self):
41-
pass
42-
4346
def putOutput(self, output):
4447
#TODO: check that name does not exist
4548
if isinstance(output, Output):
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from sextante.core.GeoAlgorithm import GeoAlgorithm
2+
3+
class ModelerAlgorithm(GeoAlgorithm):
4+
5+
algs = []
6+
algParameters = []
7+
paramValues = {}
8+
9+
def __init__(self):
10+
GeoAlgorithm.__init__(self)
11+
self.providerName = "model:"
12+
13+
def openModel(self, filename):
14+
pass
15+
16+
def addAlgorithm(self, algName, parametersMap):
17+
self.algs.append(algName)
18+
self.parameters.append(parametersMap)
19+
20+
def addParameterValue(self, value):
21+
name = "HARD_CODE_PARAM_VALUE" + str(len(self.paramValues))
22+
self.paramValues[name] = value
23+
return name
24+
25+
def __str__(self):
26+
s=""
27+
for i in range(len(self.algs)):
28+
s+="ALGORITHM:" + self.algs[i]+"\n"
29+
for param in self.algParameters[i]:
30+
s+=str(param.value)
31+
for param in self.parameters:
32+
s += "PARAMETER:" + param.serialize() + "\n"
33+
for key in self.paramValues.keys():
34+
s += "VALUE:" + key + "=" + str(self.paramValues[key]) + "\n"
35+
36+
return s

src/sextante/core/Sextante.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,26 @@
99
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
1010
from sextante.core.SextanteUtils import SextanteUtils
1111
from sextante.mmqgis.MMQGISAlgorithmProvider import MMQGISAlgorithmProvider
12+
from sextante.core.SextanteConfig import SextanteConfig
13+
from sextante.core.SextanteLog import SextanteLog
1214

1315
class Sextante:
1416

15-
providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider(),MMQGISAlgorithmProvider()]
17+
providers = [SagaAlgorithmProvider(), ScriptAlgorithmProvider()]#,MMQGISAlgorithmProvider()]
1618
algs = {}
1719
actions = {}
1820
contextMenuActions = []
1921

2022

21-
def __init__(self):
22-
pass
23-
2423
@staticmethod
2524
def initialize():
25+
SextanteLog.startLogging()
26+
SextanteConfig.initialize()
27+
SextanteConfig.loadSettings()
2628
Sextante.loadAlgorithms()
2729
Sextante.loadActions()
2830
Sextante.loadContextMenuActions()
31+
SextanteConfig.loadSettings()
2932

3033

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

3740
@staticmethod
3841
def loadAlgorithms():
42+
Sextante.updateProviders()
3943
for provider in Sextante.providers:
4044
providerAlgs = provider.algs
4145
algs = {}
@@ -115,15 +119,15 @@ def runalg(name, *args):
115119
return
116120
i = i +1
117121

118-
SextanteUtils.addToLog(SextanteUtils.LOG_ALGORITHM, alg.getAsCommand())
122+
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, alg.getAsCommand())
119123

120124
try:
121125
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
122126
AlgorithmExecutor.runalg(alg, SilentProgress())
123127
QApplication.restoreOverrideCursor()
124128
return alg.getOuputsChannelsAsMap()
125129
except GeoAlgorithmExecutionException, e:
126-
print "*****Error executing algoritm*****"
130+
print "*****Error executing algorithm*****"
127131
print e.msg
128132

129133
@staticmethod
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from sextante.core.SextanteUtils import SextanteUtils
2+
import os.path
3+
4+
class SextanteConfig():
5+
6+
OUTPUT_FOLDER = "OUTPUT_FOLDER"
7+
8+
settings = {}
9+
10+
@staticmethod
11+
def initialize():
12+
SextanteConfig.addSetting(Setting("General", SextanteConfig.OUTPUT_FOLDER,
13+
"Output folder", os.path.join(SextanteUtils.userFolder(),"outputs" )))
14+
15+
16+
@staticmethod
17+
def addSetting(setting):
18+
SextanteConfig.settings[setting.name] = setting
19+
20+
@staticmethod
21+
def getSettings():
22+
settings={}
23+
for setting in SextanteConfig.settings.values():
24+
if not setting.group in settings:
25+
group = []
26+
settings[setting.group] = group
27+
else:
28+
group = settings[setting.group]
29+
group.append(setting)
30+
return settings
31+
32+
@staticmethod
33+
def configFile():
34+
return os.path.join(SextanteUtils.userFolder(), "sextante_qgis.conf")
35+
36+
@staticmethod
37+
def loadSettings():
38+
lines = open(SextanteConfig.configFile())
39+
line = lines.readline().strip("\n")
40+
while line != "":
41+
tokens = line.split("=")
42+
if tokens[0] in SextanteConfig.settings.keys():
43+
setting = SextanteConfig.settings[tokens[0]]
44+
if isinstance(setting.value, bool):
45+
setting.value = bool(tokens[1])
46+
else:
47+
setting.value = tokens[1]
48+
SextanteConfig.addSetting(setting)
49+
line = lines.readline().strip("\n")
50+
lines.close()
51+
52+
@staticmethod
53+
def saveSettings():
54+
fout = open(SextanteConfig.configFile(), "w")
55+
for setting in SextanteConfig.settings.values():
56+
fout.write(str(setting) + "\n")
57+
fout.close()
58+
59+
@staticmethod
60+
def getSetting(name):
61+
if name in SextanteConfig.settings.keys():
62+
return SextanteConfig.settings[name].value
63+
else:
64+
return None
65+
66+
67+
68+
class Setting():
69+
70+
def __init__(self, group, name, description, default):
71+
self.group=group
72+
self.name = name
73+
self.description = description
74+
self.default = default
75+
self.value = default
76+
77+
def __str__(self):
78+
return self.name + "=" + str(self.value)

src/sextante/core/SextanteLog.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import datetime
2+
import os
3+
from sextante.core.SextanteUtils import SextanteUtils
4+
class SextanteLog():
5+
6+
LOG_ERROR = "ERROR"
7+
LOG_INFO = "INFO"
8+
LOG_WARNING = "WARNING"
9+
LOG_ALGORITHM = "ALGORITHM"
10+
11+
@staticmethod
12+
def startLogging():
13+
logfile = open(SextanteLog.logFilename(), "w")
14+
logfile.write("Started logging at " + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S"))
15+
logfile.close()
16+
17+
@staticmethod
18+
def logFilename():
19+
batchfile = SextanteUtils.userFolder() + os.sep + "sextante_qgis.log"
20+
return batchfile
21+
22+
23+
@staticmethod
24+
def addToLog(msgtype, msg):
25+
if isinstance(msg, list):
26+
text=""
27+
for i in range(0, len(msg)):
28+
text+=msg[i] + "|"
29+
text = text[:-1]
30+
else:
31+
text = str(msg)
32+
line = msgtype + "|" + datetime.datetime.now().strftime("%a %b %d %Y %H:%M:%S") + "|" + text + "\n"
33+
logfile = open(SextanteLog.logFilename(), "a")
34+
logfile.write(line)
35+
logfile.close()
36+
37+
@staticmethod
38+
def getLogEntries():
39+
entries={}
40+
errors=[]
41+
algorithms=[]
42+
warnings=[]
43+
info=[]
44+
lines = open(SextanteLog.logFilename())
45+
line = lines.readline()
46+
while line != "":
47+
line = line.strip("\n").strip()
48+
tokens = line.split("|")
49+
text=""
50+
for i in range(2, len(tokens)):
51+
text+=tokens[i] + "|"
52+
if line.startswith(SextanteLog.LOG_ERROR):
53+
errors.append(LogEntry(tokens[1], text))
54+
elif line.startswith(SextanteLog.LOG_ALGORITHM):
55+
algorithms.append(LogEntry(tokens[1], tokens[2]))
56+
elif line.startswith(SextanteLog.LOG_WARNING):
57+
warnings.append(LogEntry(tokens[1], text))
58+
elif line.startswith(SextanteLog.LOG_INFO):
59+
info.append(LogEntry(tokens[1], text))
60+
line = lines.readline()
61+
lines.close()
62+
entries[SextanteLog.LOG_ERROR] = errors
63+
entries[SextanteLog.LOG_ALGORITHM] = algorithms
64+
entries[SextanteLog.LOG_INFO] = info
65+
entries[SextanteLog.LOG_WARNING] = warnings
66+
return entries
67+
68+
class LogEntry():
69+
def __init__(self, date, text):
70+
self.date = date
71+
self.text = text

0 commit comments

Comments
 (0)