3 changes: 2 additions & 1 deletion python/plugins/sextante/core/GeoAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def __init__(self):
self.provider = None

self.defineCharacteristics()

def getCopy(self):
'''returns a new instance of this algorithm, ready to be used for being executed'''
newone = copy.copy(self)
newone.parameters = copy.deepcopy(self.parameters)
newone.outputs = copy.deepcopy(self.outputs)
Expand Down
3 changes: 0 additions & 3 deletions python/plugins/sextante/gui/AlgorithmExecutionDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ def __init__(self, alg, mainWidget):
self.verticalLayout.addWidget(self.tabWidget)
self.logText = QTextEdit()
self.logText.readOnly = True
useThreads = SextanteConfig.getSetting(SextanteConfig.USE_THREADS)
keepOpen = SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN)
#if useThreads or keepOpen:
self.tabWidget.addTab(self.logText, "Log")
self.webView = QtWebKit.QWebView()
cssUrl = QtCore.QUrl(os.path.join(os.path.dirname(__file__), "help", "help.css"))
Expand Down
1 change: 1 addition & 0 deletions python/plugins/sextante/r/EditRScriptAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def isEnabled(self):

def execute(self):
dlg = EditRScriptDialog(self.alg)
dlg.show()
dlg.exec_()
if dlg.update:
self.toolbox.updateTree()
31 changes: 28 additions & 3 deletions python/plugins/sextante/r/EditRScriptDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* *
***************************************************************************
"""
from sextante.gui.ParametersDialog import ParametersDialog
from sextante.core.QGisLayers import QGisLayers
from sextante.modeler.Providers import Providers

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand All @@ -39,11 +42,11 @@ def __init__(self, alg):
else:
self.filename = None
QtGui.QDialog.__init__(self)
self.setModal(True)
self.setModal(False)
self.setupUi()
self.update = False
self.help = None

def setupUi(self):
self.resize(600,400)
self.setWindowTitle("Edit script")
Expand All @@ -62,9 +65,13 @@ def setupUi(self):
self.saveButton = QtGui.QPushButton()
self.saveButton.setText("Save")
self.buttonBox.addButton(self.saveButton, QtGui.QDialogButtonBox.ActionRole)
self.runButton = QtGui.QPushButton()
self.runButton.setText("Run")
self.buttonBox.addButton(self.runButton, QtGui.QDialogButtonBox.ActionRole)
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Close")
self.buttonBox.addButton(self.closeButton, QtGui.QDialogButtonBox.ActionRole)
QObject.connect(self.runButton, QtCore.SIGNAL("clicked()"), self.runAlgorithm)
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveAlgorithm)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.cancelPressed)
layout.addWidget(self.text)
Expand All @@ -75,7 +82,7 @@ def setupUi(self):

def editHelp(self):
if self.alg is None:
alg = RAlgorithm(None, unicode(self.text.toPlainText()))
alg = RAlgorithm(None, unicode(self.text.toPlainText()))
else:
alg = self.alg
dlg = HelpEditionDialog(alg)
Expand All @@ -86,6 +93,24 @@ def editHelp(self):
self.help = dlg.descriptions


def runAlgorithm(self):
alg = RAlgorithm(None, unicode(self.text.toPlainText()))
alg.provider = Providers.providers['r']
dlg = alg.getCustomParametersDialog()
if not dlg:
dlg = ParametersDialog(alg)
canvas = QGisLayers.iface.mapCanvas()
prevMapTool = canvas.mapTool()
dlg.show()
dlg.exec_()
if canvas.mapTool()!=prevMapTool:
try:
canvas.mapTool().reset()
except:
pass
canvas.setMapTool(prevMapTool)


def saveAlgorithm(self):
if self.filename is None:
self.filename = str(QtGui.QFileDialog.getSaveFileName(self, "Save Script", RUtils.RScriptsFolder(), "SEXTANTE R script (*.rsx)"))
Expand Down
41 changes: 21 additions & 20 deletions python/plugins/sextante/r/RAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,30 @@ def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/r.png")

def defineCharacteristicsFromScript(self):
lines = self.script.split("\n")
self.silentOutputs = []
lines = self.script.split("\n")
self.name = "[Unnamed algorithm]"
self.group = "User R scripts"
for line in lines:
if line.startswith("##"):
try:
self.processParameterLine(line.strip("\n"))
except:
pass

def defineCharacteristicsFromFile(self):
self.parseDescription(iter(lines))


def defineCharacteristicsFromFile(self):
filename = os.path.basename(self.descriptionFile)
self.name = filename[:filename.rfind(".")].replace("_", " ")
self.group = "User R scripts"
with open(self.descriptionFile, 'r') as f:
lines = [line.strip() for line in f]
self.parseDescription(iter(lines))

def parseDescription(self, lines):
self.script = ""
self.commands=[]
self.showPlots = False
self.showConsoleOutput = False
self.useRasterPackage = True
self.passFileNames = False
self.verboseCommands = []
filename = os.path.basename(self.descriptionFile)
self.name = filename[:filename.rfind(".")].replace("_", " ")
self.group = "User R scripts"
ender = 0
lines = open(self.descriptionFile)
line = lines.readline().strip("\n").strip("\r")
ender = 0
line = lines.next().strip("\n").strip("\r")
while ender < 10:
if line.startswith("##"):
try:
Expand All @@ -119,8 +118,10 @@ def defineCharacteristicsFromFile(self):
ender=0
self.commands.append(line)
self.script += line + "\n"
line = lines.readline().strip("\n").strip("\r")
lines.close()
try:
line = lines.next().strip("\n").strip("\r")
except:
break

def getVerboseCommands(self):
return self.verboseCommands
Expand Down Expand Up @@ -280,7 +281,7 @@ def getImportCommands(self):
commands.append(
'tryCatch(find.package("rgdal"), error=function(e) install.packages("rgdal", dependencies=TRUE, lib="%s"))' % rLibDir)
commands.append("library(\"rgdal\")");
if self.useRasterPackage or self.passFileNames:
if not self.useRasterPackage or self.passFileNames:
commands.append(
'tryCatch(find.package("raster"), error=function(e) install.packages("raster", dependencies=TRUE, lib="%s"))' % rLibDir)
commands.append("library(\"raster\")");
Expand Down Expand Up @@ -376,7 +377,7 @@ def getRCommands(self):
return self.commands

def helpFile(self):
helpfile = self.descriptionFile + ".help"
helpfile = unicode(self.descriptionFile) + ".help"
if os.path.exists(helpfile):
h2h = Help2Html()
return h2h.getHtmlFile(self, helpfile)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/sextante/r/RAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def loadFromFolder(self, folder):
except WrongScriptException,e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR,e.msg)
except Exception, e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR,"Could not load R script:" + descriptionFile)
SextanteLog.addToLog(SextanteLog.LOG_ERROR,"Could not load R script:" + descriptionFile + "\n" + str(e))