added option not to close dialog after execution

added help editing dialogs

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@142 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
This commit is contained in:
volayaf 2012-04-23 13:03:27 +00:00
parent 00ca86dca8
commit 732709c035
7 changed files with 262 additions and 36 deletions

View File

@ -33,7 +33,7 @@ class SextantePlugin:
Sextante.addAlgListListener(self.toolbox)
self.menu = QMenu(self.iface.mainWindow())
self.menu.setTitle("SEXTANTE")
self.menu.setTitle("Analysis")
icon = QIcon(os.path.dirname(__file__) + "/images/toolbox.png")
self.toolboxAction = QAction(icon, \

View File

@ -13,6 +13,7 @@ class SextanteConfig():
SHOW_RECENT_ALGORITHMS = "SHOW_RECENT_ALGORITHMS"
USE_SELECTED = "USE_SELECTED"
USE_FILENAME_AS_LAYER_NAME = "USE_FILENAME_AS_LAYER_NAME"
KEEP_DIALOG_OPEN = "KEEP_DIALOG_OPEN"
settings = {}
settingIcons= {}
@ -21,6 +22,7 @@ class SextanteConfig():
def initialize():
icon = QtGui.QIcon(os.path.dirname(__file__) + "/../images/alg.png")
SextanteConfig.settingIcons["General"] = icon
SextanteConfig.addSetting(Setting("General", SextanteConfig.KEEP_DIALOG_OPEN, "Keep dialog open after running an algorithm", False))
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_SELECTED, "Use only selected features in external applications", True))
SextanteConfig.addSetting(Setting("General", SextanteConfig.TABLE_LIKE_PARAM_PANEL, "Show table-like parameter panels", False))
SextanteConfig.addSetting(Setting("General", SextanteConfig.USE_FILENAME_AS_LAYER_NAME, "Use filename as layer name", True))

View File

@ -0,0 +1,157 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui, QtWebKit
import os
import pickle
class HelpEditionDialog(QtGui.QDialog):
ALG_DESC = "ALG_DESC"
ALG_CREATOR = "ALG_CREATOR"
ALG_HELP_CREATOR = "ALG_HELP_CREATOR"
def __init__(self, alg):
self.alg = alg
QtGui.QDialog.__init__(self)
self.setModal(True)
self.descriptions = {}
if self.alg.descriptionFile:
helpfile = alg.descriptionFile + ".help"
if os.path.exists(helpfile):
f = open(helpfile, "rb")
self.descriptions = pickle.load(f)
self.currentName = self.ALG_DESC
self.setupUi()
def setupUi(self):
self.resize(700, 500)
self.tree = QtGui.QTreeWidget()
self.tree.setHeaderHidden(True)
self.tree.setMinimumWidth(300)
QObject.connect(self.tree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*, int)"), self.changeItem)
self.groupIcon = QtGui.QIcon()
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirClosedIcon),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirOpenIcon),
QtGui.QIcon.Normal, QtGui.QIcon.On)
self.keyIcon = QtGui.QIcon()
self.keyIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_FileIcon))
self.fillTree()
self.setWindowTitle("Help editor")
self.horizontalLayout= QtGui.QHBoxLayout()
self.horizontalLayout.setSpacing(15)
self.horizontalLayout.setMargin(0)
self.label = QtGui.QLabel()
self.label.setText("Select elements on the tree and fill their description in the text box below")
self.labelName = QtGui.QLabel()
self.labelName.setText("Algorithm description")
self.text = QtGui.QTextEdit()
self.text.setMinimumHeight(200)
self.verticalLayout= QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(5)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.tree)
self.verticalLayout.addSpacing(20)
self.verticalLayout.addWidget(self.label)
self.verticalLayout.addSpacing(20)
self.verticalLayout.addWidget(self.labelName)
self.verticalLayout.addWidget(self.text)
self.horizontalLayout.addLayout(self.verticalLayout)
self.webView = QtWebKit.QWebView()
self.webView.setMinimumWidth(300)
self.webView.setHtml(self.getHtml())
self.horizontalLayout.addWidget(self.webView)
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Cancel")
self.saveButton = QtGui.QPushButton()
self.saveButton.setText("OK")
self.horizontalLayout2= QtGui.QHBoxLayout()
self.horizontalLayout2.setSpacing(2)
self.horizontalLayout2.setMargin(0)
self.horizontalLayout2.addStretch(1000)
self.horizontalLayout2.addWidget(self.saveButton)
self.horizontalLayout2.addWidget(self.closeButton)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveHelp)
self.verticalLayout2= QtGui.QVBoxLayout()
self.verticalLayout2.setSpacing(2)
self.verticalLayout2.setMargin(0)
self.verticalLayout2.addLayout(self.horizontalLayout)
self.verticalLayout2.addLayout(self.horizontalLayout2)
self.setLayout(self.verticalLayout2)
QtCore.QMetaObject.connectSlotsByName(self)
self.updateHtmlView()
def closeWindow(self):
self.descriptions = None
self.close()
def saveHelp(self):
self.descriptions[self.currentName] = str(self.text.toPlainText())
if self.alg.descriptionFile:
f = open(self.alg.descriptionFile + ".help", "wb")
pickle.dump(self.descriptions, f)
f.close()
self.close()
def getHtml(self):
s = "<h2>Algorithm description</h2>\n"
s += "<p>" + self.getDescription(self.ALG_DESC) + "</p>\n"
s += "<h2>Input parameters</h2>\n"
for param in self.alg.parameters:
s += "<h3>" + param.description + "</h3>\n"
s += "<p>" + self.getDescription(param.name) + "</p>\n"
s += "<h2>Outputs</h2>\n"
for out in self.alg.outputs:
s += "<h3>" + out.description + "</h3>\n"
s += "<p>" + self.getDescription(out.name) + "</p>\n"
return s
def fillTree(self):
item = TreeDescriptionItem("Algorithm description", self.ALG_DESC)
self.tree.addTopLevelItem(item)
parametersItem = TreeDescriptionItem("Input parameters", None)
self.tree.addTopLevelItem(parametersItem)
for param in self.alg.parameters:
item = TreeDescriptionItem(param.description, param.name)
parametersItem.addChild(item)
outputsItem = TreeDescriptionItem("Outputs", None)
self.tree.addTopLevelItem(outputsItem)
for out in self.alg.outputs:
item = TreeDescriptionItem(out.description, out.name)
outputsItem.addChild(item)
item = TreeDescriptionItem("Algorithm created by", self.ALG_CREATOR)
self.tree.addTopLevelItem(item)
item = TreeDescriptionItem("Algorithm help written by", self.ALG_HELP_CREATOR)
self.tree.addTopLevelItem(item)
def changeItem(self):
item = self.tree.currentItem()
if isinstance(item, TreeDescriptionItem):
if self.currentName:
self.descriptions[self.currentName] = str(self.text.toPlainText())
name = item.name
if name:
self.updateHtmlView()
self.currentName = name
self.labelName.setText(item.description)
if name in self.descriptions:
self.text.setText(self.descriptions[name])
else:
self.text.setText("")
def updateHtmlView(self):
self.webView.setHtml(self.getHtml())
def getDescription(self, name):
if name in self.descriptions :
return self.descriptions[name]
else:
return ""
class TreeDescriptionItem(QtGui.QTreeWidgetItem):
def __init__(self, description, name):
QTreeWidgetItem.__init__(self)
self.name = name
self.description = description
self.setText(0, description)

View File

@ -21,6 +21,7 @@ from sextante.parameters.ParameterNumber import ParameterNumber
from sextante.gui.ParametersPanel import ParametersPanel
from sextante.parameters.ParameterFile import ParameterFile
from sextante.parameters.ParameterCrs import ParameterCrs
from sextante.core.SextanteConfig import SextanteConfig
try:
_fromUtf8 = QtCore.QString.fromUtf8
@ -59,12 +60,10 @@ class Ui_ParametersDialog(object):
self.scrollArea.setWidgetResizable(True)
dialog.setWindowTitle(self.alg.name)
self.progressLabel = QtGui.QLabel()
self.progressLabel.setText("Processing algorithm...")
self.progressLabel.setVisible(False)
self.progress = QtGui.QProgressBar()
self.progress.setVisible(False)
self.progress.setMinimum(0)
self.progress.setMaximum(100)
self.progress.setValue(0)
self.verticalLayout = QtGui.QVBoxLayout(dialog)
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
@ -136,6 +135,7 @@ class Ui_ParametersDialog(object):
def accept(self):
try:
if self.setParamValues():
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
buttons = self.paramTable.iterateButtons
iterateParam = None
for i in range(len(buttons.values())):
@ -143,8 +143,7 @@ class Ui_ParametersDialog(object):
if button.isChecked():
iterateParam = buttons.keys()[i]
break
self.progress.setVisible(True)
self.progressLabel.setVisible(True)
self.progressLabel.setText("Processing algorithm...")
if iterateParam:
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
AlgorithmExecutor.runalgIterating(self.alg, iterateParam, self)
@ -158,7 +157,12 @@ class Ui_ParametersDialog(object):
SextantePostprocessing.handleAlgorithmResults(self.alg)
self.dialog.executed = True
self.dialog.close()
if not SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN):
self.dialog.close()
else:
self.progressLabel.setText("")
self.progress.setValue(0)
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
else:
QMessageBox.critical(self.dialog, "Unable to execute algorithm", "Wrong or missing parameter values")
@ -172,7 +176,7 @@ class Ui_ParametersDialog(object):
def reject(self):
self.dialog.executed = False
#self.dialog.executed = False
self.dialog.close()
def setPercentage(self, i):

View File

@ -10,6 +10,8 @@ from sextante.modeler.ModelerScene import ModelerScene
import copy
from sextante.modeler.Providers import Providers
from sextante.script.ScriptUtils import ScriptUtils
from sextante.gui.HelpEditionDialog import HelpEditionDialog
import pickle
class ModelerDialog(QtGui.QDialog):
def __init__(self, alg=None):
@ -28,6 +30,7 @@ class ModelerDialog(QtGui.QDialog):
else:
self.alg = ModelerAlgorithm()
self.alg.setModelerView(self)
self.help = None
self.update = False #indicates whether to update or not the toolbox after closing this dialog
def setupUi(self):
@ -112,8 +115,12 @@ class ModelerDialog(QtGui.QDialog):
#And the whole layout
#==========================
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit model help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
self.openButton = QtGui.QPushButton()
self.openButton.setText("Open")
self.buttonBox.addButton(self.openButton, QtGui.QDialogButtonBox.ActionRole)
@ -126,6 +133,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.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
self.globalLayout = QtGui.QVBoxLayout()
self.globalLayout.setSpacing(2)
@ -140,6 +148,14 @@ class ModelerDialog(QtGui.QDialog):
def closeWindow(self):
self.close()
def editHelp(self):
dlg = HelpEditionDialog(self.alg)
dlg.exec_()
#We store the description string in case there were not saved because there was no
#filename defined yet
if self.alg.descriptionFile is None and dlg.descriptions:
self.help = dlg.descriptions
def createScript(self):
if str(self.textGroup.text()).strip() == "":
QMessageBox.warning(self, "Warning", "Please enter group name before saving")
@ -173,6 +189,13 @@ class ModelerDialog(QtGui.QDialog):
fout.close()
self.update = True
#if help strings were defined before saving the model for the first time, we do it here
if self.help:
f = open(self.alg.descriptionFile + ".help", "wb")
pickle.dump(self.help, f)
f.close()
self.help = None
def openModel(self):
filename = QtGui.QFileDialog.getOpenFileName(self, "Open Model", ModelerUtils.modelsFolder(), "SEXTANTE models (*.model)")
if filename:

View File

@ -2,6 +2,7 @@ from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.r.RUtils import RUtils
import pickle
class EditRScriptDialog(QtGui.QDialog):
def __init__(self, alg):
@ -12,27 +13,33 @@ class EditRScriptDialog(QtGui.QDialog):
self.update = False
def setupUi(self):
self.setObjectName("Dialog")
self.resize(655, 360)
self.setWindowTitle("Edit script")
self.text = QtGui.QTextEdit(self)
self.text.setGeometry(QtCore.QRect(5, 5, 550, 350))
layout = QVBoxLayout()
self.text = QtGui.QTextEdit()
self.text.setObjectName("text")
self.text.setEnabled(True)
if self.alg != None:
self.text.setText(self.alg.script)
self.saveButton = QtGui.QPushButton(self)
self.saveButton.setGeometry(QtCore.QRect(570, 300, 80, 23))
self.saveButton.setObjectName("saveButton")
self.saveButton.setText("Save")
self.cancelButton = QtGui.QPushButton(self)
self.cancelButton.setGeometry(QtCore.QRect(570, 327, 80, 23))
self.cancelButton.setObjectName("cancelButton")
self.cancelButton.setText("Cancel")
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveAlgorithm)
QObject.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), self.cancel)
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close)
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit model help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
layout.addWidget(self.text)
layout.addWidget(self.buttonBox)
self.setLayout(layout)
self.connect(self.buttonBox, SIGNAL("accepted()"), self.saveAlgorithm)
self.connect(self.buttonBox, SIGNAL("rejected()"), self.cancelPressed)
self.connect(self.editHelpButton, SIGNAL("clicked()"), self.editHelp)
QtCore.QMetaObject.connectSlotsByName(self)
def editHelp(self):
dlg = HelpEditionDialog(self.alg)
dlg.exec_()
#We store the description string in case there were not saved because there was no
#filename defined yet
if self.alg.descriptionFile is None and dlg.descriptions:
self.help = dlg.descriptions
def saveAlgorithm(self):
if self.alg!=None:
filename = self.alg.descriptionFile
@ -46,6 +53,13 @@ class EditRScriptDialog(QtGui.QDialog):
self.update = True
self.close()
def cancel(self):
#if help strings were defined before saving the model for the first time, we do it here
if self.help:
f = open(self.alg.descriptionFile + ".help", "wb")
pickle.dump(self.help, f)
f.close()
self.help = None
def cancelPressed(self):
self.update = False
self.close()

View File

@ -2,6 +2,8 @@ from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.script.ScriptUtils import ScriptUtils
from sextante.gui.HelpEditionDialog import HelpEditionDialog
import pickle
class EditScriptDialog(QtGui.QDialog):
def __init__(self, alg):
@ -10,29 +12,46 @@ class EditScriptDialog(QtGui.QDialog):
self.setModal(True)
self.setupUi()
self.update = False
self.help = None
def setupUi(self):
self.setObjectName("Dialog")
self.resize(655, 360)
self.resize(600,400)
self.setWindowTitle("Edit script")
self.text = QtGui.QTextEdit(self)
self.text.setGeometry(QtCore.QRect(5, 5, 550, 350))
layout = QVBoxLayout()
self.text = QtGui.QTextEdit()
self.text.setObjectName("text")
self.text.setEnabled(True)
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
if self.alg != None:
self.text.setText(self.alg.script)
self.saveButton = QtGui.QPushButton(self)
self.saveButton.setGeometry(QtCore.QRect(570, 300, 80, 23))
self.saveButton.setObjectName("saveButton")
self.editHelpButton = QtGui.QPushButton()
self.editHelpButton.setText("Edit model help")
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
self.saveButton = QtGui.QPushButton()
self.saveButton.setText("Save")
self.cancelButton = QtGui.QPushButton(self)
self.cancelButton.setGeometry(QtCore.QRect(570, 327, 80, 23))
self.cancelButton.setObjectName("cancelButton")
self.cancelButton.setText("Cancel")
self.buttonBox.addButton(self.saveButton, QtGui.QDialogButtonBox.ActionRole)
self.closeButton = QtGui.QPushButton()
self.closeButton.setText("Close")
self.buttonBox.addButton(self.closeButton, QtGui.QDialogButtonBox.ActionRole)
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveAlgorithm)
QObject.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), self.cancel)
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.cancelPressed)
layout.addWidget(self.text)
layout.addWidget(self.buttonBox)
self.setLayout(layout)
QtCore.QMetaObject.connectSlotsByName(self)
def editHelp(self):
dlg = HelpEditionDialog(self.alg)
dlg.exec_()
#We store the description string in case there were not saved because there was no
#filename defined yet
if self.alg.descriptionFile is None and dlg.descriptions:
self.help = dlg.descriptions
def saveAlgorithm(self):
if self.alg!=None:
filename = self.alg.descriptionFile
@ -46,6 +65,13 @@ class EditScriptDialog(QtGui.QDialog):
self.update = True
self.close()
def cancel(self):
#if help strings were defined before saving the model for the first time, we do it here
if self.help:
f = open(self.alg.descriptionFile + ".help", "wb")
pickle.dump(self.help, f)
f.close()
self.help = None
def cancelPressed(self):
self.update = False
self.close()