Added run button to modeler

Added tool to define grass region on canvas

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@147 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
This commit is contained in:
volayaf 2012-04-24 08:39:15 +00:00
parent 88053cc623
commit 0023d04d46
6 changed files with 77 additions and 4 deletions

View File

@ -230,7 +230,8 @@ class GeoAlgorithm:
return None
def getAsCommand(self):
'''Returns the command that would run this same algorithm from the console'''
'''Returns the command that would run this same algorithm from the console.
Should return null if the algorithm can be run from the console.'''
s="Sextante.runalg(\"" + self.commandLineName() + "\","
for param in self.parameters:
s+=param.getValueAsCommandLineParameter() + ","

View File

@ -0,0 +1,39 @@
import os
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.gui.ToolboxAction import ToolboxAction
from sextante.core.QGisLayers import QGisLayers
from sextante.gui.RectangleMapTool import RectangleMapTool
from sextante.core.SextanteConfig import SextanteConfig
from sextante.grass.GrassUtils import GrassUtils
class DefineGrassRegionAction(ToolboxAction):
def __init__(self):
self.name="Define GRASS region on canvas"
self.group="Tools"
canvas = QGisLayers.iface.mapCanvas()
self.prevMapTool = canvas.mapTool()
self.tool = RectangleMapTool(canvas)
QtCore.QObject.connect(self.tool, SIGNAL("rectangleCreated()"), self.fillCoords)
def getIcon(self):
return QtGui.QIcon(os.path.dirname(__file__) + "/../images/grass.png")
def execute(self):
QtGui.QMessageBox.information(None, "GRASS Region", "Click and drag onto map canvas to define GRASS region")
canvas = QGisLayers.iface.mapCanvas()
canvas.setMapTool(self.tool)
def fillCoords(self):
r = self.tool.rectangle()
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMIN, r.xMinimum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMIN, r.yMinimum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_XMAX, r.xMaximum())
SextanteConfig.setSettingValue(GrassUtils.GRASS_REGION_YMAX, r.yMaximum())
s = str(r.xMinimum()) + "," + str(r.xMaximum()) + "," + str(r.yMinimum()) + "," + str(r.yMaximum())
self.tool.reset()
canvas = QGisLayers.iface.mapCanvas()
canvas.setMapTool(self.prevMapTool)
QtGui.QMessageBox.information(None, "GRASS Region", "GRASS region set to:\n" + s)

View File

@ -7,11 +7,13 @@ from sextante.core.SextanteLog import SextanteLog
from sextante.grass.GrassUtils import GrassUtils
from sextante.grass.GrassAlgorithm import GrassAlgorithm
from sextante.core.SextanteUtils import SextanteUtils
from sextante.grass.DefineGrassRegionAction import DefineGrassRegionAction
class GrassAlgorithmProvider(AlgorithmProvider):
def __init__(self):
AlgorithmProvider.__init__(self)
self.actions.append(DefineGrassRegionAction())
self.createAlgsList() #preloading algorithms to speed up
def initializeSettings(self):

View File

@ -151,7 +151,9 @@ class Ui_ParametersDialog(object):
QApplication.restoreOverrideCursor()
else:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, self.alg.getAsCommand())
command = self.alg.getAsCommand()
if command:
SextanteLog.addToLog(SextanteLog.LOG_ALGORITHM, command)
ret = AlgorithmExecutor.runalg(self.alg, self)
QApplication.restoreOverrideCursor()
if ret:

View File

@ -153,8 +153,8 @@ class ModelerAlgorithm(GeoAlgorithm):
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(len(self.algs))
def serialize(self):
s="NAME:" + self.name + "\n"
s +="GROUP:" + self.group + "\n"
s="NAME:" + str(self.name) + "\n"
s +="GROUP:" + str(self.group) + "\n"
i = 0
for param in self.parameters:
@ -326,6 +326,12 @@ class ModelerAlgorithm(GeoAlgorithm):
return False
def getAsCommand(self):
if self.descriptionFile:
return GeoAlgorithm.getAsCommand(self)
else:
return None
def commandLineName(self):
return "modeler:" + os.path.basename(self.descriptionFile)[:-5].lower()

View File

@ -12,6 +12,8 @@ from sextante.modeler.Providers import Providers
from sextante.script.ScriptUtils import ScriptUtils
from sextante.gui.HelpEditionDialog import HelpEditionDialog
import pickle
from sextante.gui.ParametersDialog import ParametersDialog
from sextante.core.SextanteUtils import SextanteUtils
class ModelerDialog(QtGui.QDialog):
def __init__(self, alg=None):
@ -121,6 +123,9 @@ class ModelerDialog(QtGui.QDialog):
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit model help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
self.runButton = QtGui.QPushButton()
self.runButton.setText("Run")
self.buttonBox.addButton(self.runButton, QtGui.QDialogButtonBox.ActionRole)
self.openButton = QtGui.QPushButton()
self.openButton.setText("Open")
self.buttonBox.addButton(self.openButton, QtGui.QDialogButtonBox.ActionRole)
@ -133,6 +138,7 @@ class ModelerDialog(QtGui.QDialog):
QObject.connect(self.openButton, QtCore.SIGNAL("clicked()"), self.openModel)
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveModel)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
QObject.connect(self.runButton, QtCore.SIGNAL("clicked()"), self.runModel)
QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
self.globalLayout = QtGui.QVBoxLayout()
@ -168,6 +174,23 @@ class ModelerDialog(QtGui.QDialog):
fout.close()
self.update = True
def runModel(self):
##TODO: enable alg cloning without saving to file
if self.alg.descriptionFile is None:
self.alg.descriptionFile = SextanteUtils.getTempFilename("model")
text = self.alg.serialize()
fout = open(self.alg.descriptionFile, "w")
fout.write(text)
fout.close()
self.alg.provider = Providers.providers["Modeler"]
alg = copy.deepcopy(self.alg)
self.alg.descriptionFile = None
alg.descriptionFile = None
else:
alg = copy.deepcopy(self.alg)
dlg = ParametersDialog(alg)
dlg.exec_()
def saveModel(self):
if str(self.textGroup.text()).strip() == "" or str(self.textName.text()).strip() == "":
QMessageBox.warning(self, "Warning", "Please enter group and model names before saving")