mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
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:
parent
88053cc623
commit
0023d04d46
@ -230,7 +230,8 @@ class GeoAlgorithm:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def getAsCommand(self):
|
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() + "\","
|
s="Sextante.runalg(\"" + self.commandLineName() + "\","
|
||||||
for param in self.parameters:
|
for param in self.parameters:
|
||||||
s+=param.getValueAsCommandLineParameter() + ","
|
s+=param.getValueAsCommandLineParameter() + ","
|
||||||
|
39
src/sextante/grass/DefineGrassRegionAction.py
Normal file
39
src/sextante/grass/DefineGrassRegionAction.py
Normal 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)
|
@ -7,11 +7,13 @@ from sextante.core.SextanteLog import SextanteLog
|
|||||||
from sextante.grass.GrassUtils import GrassUtils
|
from sextante.grass.GrassUtils import GrassUtils
|
||||||
from sextante.grass.GrassAlgorithm import GrassAlgorithm
|
from sextante.grass.GrassAlgorithm import GrassAlgorithm
|
||||||
from sextante.core.SextanteUtils import SextanteUtils
|
from sextante.core.SextanteUtils import SextanteUtils
|
||||||
|
from sextante.grass.DefineGrassRegionAction import DefineGrassRegionAction
|
||||||
|
|
||||||
class GrassAlgorithmProvider(AlgorithmProvider):
|
class GrassAlgorithmProvider(AlgorithmProvider):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
AlgorithmProvider.__init__(self)
|
AlgorithmProvider.__init__(self)
|
||||||
|
self.actions.append(DefineGrassRegionAction())
|
||||||
self.createAlgsList() #preloading algorithms to speed up
|
self.createAlgsList() #preloading algorithms to speed up
|
||||||
|
|
||||||
def initializeSettings(self):
|
def initializeSettings(self):
|
||||||
|
@ -151,7 +151,9 @@ class Ui_ParametersDialog(object):
|
|||||||
QApplication.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
else:
|
else:
|
||||||
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
|
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)
|
ret = AlgorithmExecutor.runalg(self.alg, self)
|
||||||
QApplication.restoreOverrideCursor()
|
QApplication.restoreOverrideCursor()
|
||||||
if ret:
|
if ret:
|
||||||
|
@ -153,8 +153,8 @@ class ModelerAlgorithm(GeoAlgorithm):
|
|||||||
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(len(self.algs))
|
return "HARDCODEDPARAMVALUE_" + param.name + "_" + str(len(self.algs))
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
s="NAME:" + self.name + "\n"
|
s="NAME:" + str(self.name) + "\n"
|
||||||
s +="GROUP:" + self.group + "\n"
|
s +="GROUP:" + str(self.group) + "\n"
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for param in self.parameters:
|
for param in self.parameters:
|
||||||
@ -326,6 +326,12 @@ class ModelerAlgorithm(GeoAlgorithm):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def getAsCommand(self):
|
||||||
|
if self.descriptionFile:
|
||||||
|
return GeoAlgorithm.getAsCommand(self)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
def commandLineName(self):
|
def commandLineName(self):
|
||||||
return "modeler:" + os.path.basename(self.descriptionFile)[:-5].lower()
|
return "modeler:" + os.path.basename(self.descriptionFile)[:-5].lower()
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ from sextante.modeler.Providers import Providers
|
|||||||
from sextante.script.ScriptUtils import ScriptUtils
|
from sextante.script.ScriptUtils import ScriptUtils
|
||||||
from sextante.gui.HelpEditionDialog import HelpEditionDialog
|
from sextante.gui.HelpEditionDialog import HelpEditionDialog
|
||||||
import pickle
|
import pickle
|
||||||
|
from sextante.gui.ParametersDialog import ParametersDialog
|
||||||
|
from sextante.core.SextanteUtils import SextanteUtils
|
||||||
|
|
||||||
class ModelerDialog(QtGui.QDialog):
|
class ModelerDialog(QtGui.QDialog):
|
||||||
def __init__(self, alg=None):
|
def __init__(self, alg=None):
|
||||||
@ -121,6 +123,9 @@ class ModelerDialog(QtGui.QDialog):
|
|||||||
self.editHelpButton = QtGui.QPushButton()
|
self.editHelpButton = QtGui.QPushButton()
|
||||||
self.editHelpButton.setText("Edit model help")
|
self.editHelpButton.setText("Edit model help")
|
||||||
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
|
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 = QtGui.QPushButton()
|
||||||
self.openButton.setText("Open")
|
self.openButton.setText("Open")
|
||||||
self.buttonBox.addButton(self.openButton, QtGui.QDialogButtonBox.ActionRole)
|
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.openButton, QtCore.SIGNAL("clicked()"), self.openModel)
|
||||||
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveModel)
|
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveModel)
|
||||||
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
|
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)
|
QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
|
||||||
|
|
||||||
self.globalLayout = QtGui.QVBoxLayout()
|
self.globalLayout = QtGui.QVBoxLayout()
|
||||||
@ -168,6 +174,23 @@ class ModelerDialog(QtGui.QDialog):
|
|||||||
fout.close()
|
fout.close()
|
||||||
self.update = True
|
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):
|
def saveModel(self):
|
||||||
if str(self.textGroup.text()).strip() == "" or str(self.textName.text()).strip() == "":
|
if str(self.textGroup.text()).strip() == "" or str(self.textName.text()).strip() == "":
|
||||||
QMessageBox.warning(self, "Warning", "Please enter group and model names before saving")
|
QMessageBox.warning(self, "Warning", "Please enter group and model names before saving")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user