Skip to content

Commit

Permalink
added option not to close dialog after execution
Browse files Browse the repository at this point in the history
added help editing dialogs

git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@142 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Apr 23, 2012
1 parent 00ca86d commit 732709c
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/sextante/SextantePlugin.py
Expand Up @@ -33,7 +33,7 @@ def initGui(self):
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, \
Expand Down
2 changes: 2 additions & 0 deletions src/sextante/core/SextanteConfig.py
Expand Up @@ -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= {}
Expand All @@ -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))
Expand Down
157 changes: 157 additions & 0 deletions src/sextante/gui/HelpEditionDialog.py
@@ -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)
18 changes: 11 additions & 7 deletions src/sextante/gui/ParametersDialog.py
Expand Up @@ -21,6 +21,7 @@
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
Expand Down Expand Up @@ -59,12 +60,10 @@ def setupUi(self, dialog, alg):
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)
Expand Down Expand Up @@ -136,15 +135,15 @@ def setParamValue(self, param, widget):
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())):
button = buttons.values()[i]
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)
Expand All @@ -158,7 +157,12 @@ def accept(self):
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")
Expand All @@ -172,7 +176,7 @@ def accept(self):


def reject(self):
self.dialog.executed = False
#self.dialog.executed = False
self.dialog.close()

def setPercentage(self, i):
Expand Down
23 changes: 23 additions & 0 deletions src/sextante/modeler/ModelerDialog.py
Expand Up @@ -10,6 +10,8 @@
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):
Expand All @@ -28,6 +30,7 @@ def __init__(self, alg=None):
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):
Expand Down Expand Up @@ -112,8 +115,12 @@ def setupUi(self):

#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)
Expand All @@ -126,6 +133,7 @@ def setupUi(self):
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)
Expand All @@ -140,6 +148,14 @@ def setupUi(self):
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")
Expand Down Expand Up @@ -173,6 +189,13 @@ def saveModel(self):
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:
Expand Down
44 changes: 29 additions & 15 deletions src/sextante/r/EditRScriptDialog.py
Expand Up @@ -2,6 +2,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.r.RUtils import RUtils
import pickle

class EditRScriptDialog(QtGui.QDialog):
def __init__(self, alg):
Expand All @@ -12,27 +13,33 @@ def __init__(self, alg):
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
Expand All @@ -46,6 +53,13 @@ def saveAlgorithm(self):
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()

0 comments on commit 732709c

Please sign in to comment.