Skip to content

Commit 732709c

Browse files
author
volayaf
committed
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
1 parent 00ca86d commit 732709c

7 files changed

+262
-36
lines changed

src/sextante/SextantePlugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initGui(self):
3333
Sextante.addAlgListListener(self.toolbox)
3434

3535
self.menu = QMenu(self.iface.mainWindow())
36-
self.menu.setTitle("SEXTANTE")
36+
self.menu.setTitle("Analysis")
3737

3838
icon = QIcon(os.path.dirname(__file__) + "/images/toolbox.png")
3939
self.toolboxAction = QAction(icon, \

src/sextante/core/SextanteConfig.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class SextanteConfig():
1313
SHOW_RECENT_ALGORITHMS = "SHOW_RECENT_ALGORITHMS"
1414
USE_SELECTED = "USE_SELECTED"
1515
USE_FILENAME_AS_LAYER_NAME = "USE_FILENAME_AS_LAYER_NAME"
16+
KEEP_DIALOG_OPEN = "KEEP_DIALOG_OPEN"
1617

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

src/sextante/gui/HelpEditionDialog.py

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
from PyQt4.QtCore import *
2+
from PyQt4.QtGui import *
3+
from PyQt4 import QtCore, QtGui, QtWebKit
4+
import os
5+
import pickle
6+
7+
class HelpEditionDialog(QtGui.QDialog):
8+
9+
ALG_DESC = "ALG_DESC"
10+
ALG_CREATOR = "ALG_CREATOR"
11+
ALG_HELP_CREATOR = "ALG_HELP_CREATOR"
12+
13+
def __init__(self, alg):
14+
self.alg = alg
15+
QtGui.QDialog.__init__(self)
16+
self.setModal(True)
17+
self.descriptions = {}
18+
if self.alg.descriptionFile:
19+
helpfile = alg.descriptionFile + ".help"
20+
if os.path.exists(helpfile):
21+
f = open(helpfile, "rb")
22+
self.descriptions = pickle.load(f)
23+
self.currentName = self.ALG_DESC
24+
self.setupUi()
25+
26+
def setupUi(self):
27+
self.resize(700, 500)
28+
self.tree = QtGui.QTreeWidget()
29+
self.tree.setHeaderHidden(True)
30+
self.tree.setMinimumWidth(300)
31+
QObject.connect(self.tree, QtCore.SIGNAL("itemClicked(QTreeWidgetItem*, int)"), self.changeItem)
32+
self.groupIcon = QtGui.QIcon()
33+
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirClosedIcon),
34+
QtGui.QIcon.Normal, QtGui.QIcon.Off)
35+
self.groupIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_DirOpenIcon),
36+
QtGui.QIcon.Normal, QtGui.QIcon.On)
37+
self.keyIcon = QtGui.QIcon()
38+
self.keyIcon.addPixmap(self.style().standardPixmap(QtGui.QStyle.SP_FileIcon))
39+
self.fillTree()
40+
self.setWindowTitle("Help editor")
41+
self.horizontalLayout= QtGui.QHBoxLayout()
42+
self.horizontalLayout.setSpacing(15)
43+
self.horizontalLayout.setMargin(0)
44+
self.label = QtGui.QLabel()
45+
self.label.setText("Select elements on the tree and fill their description in the text box below")
46+
self.labelName = QtGui.QLabel()
47+
self.labelName.setText("Algorithm description")
48+
self.text = QtGui.QTextEdit()
49+
self.text.setMinimumHeight(200)
50+
self.verticalLayout= QtGui.QVBoxLayout()
51+
self.verticalLayout.setSpacing(5)
52+
self.verticalLayout.setMargin(0)
53+
self.verticalLayout.addWidget(self.tree)
54+
self.verticalLayout.addSpacing(20)
55+
self.verticalLayout.addWidget(self.label)
56+
self.verticalLayout.addSpacing(20)
57+
self.verticalLayout.addWidget(self.labelName)
58+
self.verticalLayout.addWidget(self.text)
59+
self.horizontalLayout.addLayout(self.verticalLayout)
60+
self.webView = QtWebKit.QWebView()
61+
self.webView.setMinimumWidth(300)
62+
self.webView.setHtml(self.getHtml())
63+
self.horizontalLayout.addWidget(self.webView)
64+
self.closeButton = QtGui.QPushButton()
65+
self.closeButton.setText("Cancel")
66+
self.saveButton = QtGui.QPushButton()
67+
self.saveButton.setText("OK")
68+
self.horizontalLayout2= QtGui.QHBoxLayout()
69+
self.horizontalLayout2.setSpacing(2)
70+
self.horizontalLayout2.setMargin(0)
71+
self.horizontalLayout2.addStretch(1000)
72+
self.horizontalLayout2.addWidget(self.saveButton)
73+
self.horizontalLayout2.addWidget(self.closeButton)
74+
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
75+
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveHelp)
76+
self.verticalLayout2= QtGui.QVBoxLayout()
77+
self.verticalLayout2.setSpacing(2)
78+
self.verticalLayout2.setMargin(0)
79+
self.verticalLayout2.addLayout(self.horizontalLayout)
80+
self.verticalLayout2.addLayout(self.horizontalLayout2)
81+
self.setLayout(self.verticalLayout2)
82+
QtCore.QMetaObject.connectSlotsByName(self)
83+
self.updateHtmlView()
84+
85+
def closeWindow(self):
86+
self.descriptions = None
87+
self.close()
88+
89+
def saveHelp(self):
90+
self.descriptions[self.currentName] = str(self.text.toPlainText())
91+
if self.alg.descriptionFile:
92+
f = open(self.alg.descriptionFile + ".help", "wb")
93+
pickle.dump(self.descriptions, f)
94+
f.close()
95+
self.close()
96+
97+
def getHtml(self):
98+
s = "<h2>Algorithm description</h2>\n"
99+
s += "<p>" + self.getDescription(self.ALG_DESC) + "</p>\n"
100+
s += "<h2>Input parameters</h2>\n"
101+
for param in self.alg.parameters:
102+
s += "<h3>" + param.description + "</h3>\n"
103+
s += "<p>" + self.getDescription(param.name) + "</p>\n"
104+
s += "<h2>Outputs</h2>\n"
105+
for out in self.alg.outputs:
106+
s += "<h3>" + out.description + "</h3>\n"
107+
s += "<p>" + self.getDescription(out.name) + "</p>\n"
108+
return s
109+
110+
def fillTree(self):
111+
item = TreeDescriptionItem("Algorithm description", self.ALG_DESC)
112+
self.tree.addTopLevelItem(item)
113+
parametersItem = TreeDescriptionItem("Input parameters", None)
114+
self.tree.addTopLevelItem(parametersItem)
115+
for param in self.alg.parameters:
116+
item = TreeDescriptionItem(param.description, param.name)
117+
parametersItem.addChild(item)
118+
outputsItem = TreeDescriptionItem("Outputs", None)
119+
self.tree.addTopLevelItem(outputsItem)
120+
for out in self.alg.outputs:
121+
item = TreeDescriptionItem(out.description, out.name)
122+
outputsItem.addChild(item)
123+
item = TreeDescriptionItem("Algorithm created by", self.ALG_CREATOR)
124+
self.tree.addTopLevelItem(item)
125+
item = TreeDescriptionItem("Algorithm help written by", self.ALG_HELP_CREATOR)
126+
self.tree.addTopLevelItem(item)
127+
128+
def changeItem(self):
129+
item = self.tree.currentItem()
130+
if isinstance(item, TreeDescriptionItem):
131+
if self.currentName:
132+
self.descriptions[self.currentName] = str(self.text.toPlainText())
133+
name = item.name
134+
if name:
135+
self.updateHtmlView()
136+
self.currentName = name
137+
self.labelName.setText(item.description)
138+
if name in self.descriptions:
139+
self.text.setText(self.descriptions[name])
140+
else:
141+
self.text.setText("")
142+
143+
def updateHtmlView(self):
144+
self.webView.setHtml(self.getHtml())
145+
146+
def getDescription(self, name):
147+
if name in self.descriptions :
148+
return self.descriptions[name]
149+
else:
150+
return ""
151+
152+
class TreeDescriptionItem(QtGui.QTreeWidgetItem):
153+
def __init__(self, description, name):
154+
QTreeWidgetItem.__init__(self)
155+
self.name = name
156+
self.description = description
157+
self.setText(0, description)

src/sextante/gui/ParametersDialog.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from sextante.gui.ParametersPanel import ParametersPanel
2222
from sextante.parameters.ParameterFile import ParameterFile
2323
from sextante.parameters.ParameterCrs import ParameterCrs
24+
from sextante.core.SextanteConfig import SextanteConfig
2425

2526
try:
2627
_fromUtf8 = QtCore.QString.fromUtf8
@@ -59,12 +60,10 @@ def setupUi(self, dialog, alg):
5960
self.scrollArea.setWidgetResizable(True)
6061
dialog.setWindowTitle(self.alg.name)
6162
self.progressLabel = QtGui.QLabel()
62-
self.progressLabel.setText("Processing algorithm...")
63-
self.progressLabel.setVisible(False)
6463
self.progress = QtGui.QProgressBar()
65-
self.progress.setVisible(False)
6664
self.progress.setMinimum(0)
6765
self.progress.setMaximum(100)
66+
self.progress.setValue(0)
6867
self.verticalLayout = QtGui.QVBoxLayout(dialog)
6968
self.verticalLayout.setSpacing(2)
7069
self.verticalLayout.setMargin(0)
@@ -136,15 +135,15 @@ def setParamValue(self, param, widget):
136135
def accept(self):
137136
try:
138137
if self.setParamValues():
138+
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
139139
buttons = self.paramTable.iterateButtons
140140
iterateParam = None
141141
for i in range(len(buttons.values())):
142142
button = buttons.values()[i]
143143
if button.isChecked():
144144
iterateParam = buttons.keys()[i]
145145
break
146-
self.progress.setVisible(True)
147-
self.progressLabel.setVisible(True)
146+
self.progressLabel.setText("Processing algorithm...")
148147
if iterateParam:
149148
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
150149
AlgorithmExecutor.runalgIterating(self.alg, iterateParam, self)
@@ -158,7 +157,12 @@ def accept(self):
158157
SextantePostprocessing.handleAlgorithmResults(self.alg)
159158

160159
self.dialog.executed = True
161-
self.dialog.close()
160+
if not SextanteConfig.getSetting(SextanteConfig.KEEP_DIALOG_OPEN):
161+
self.dialog.close()
162+
else:
163+
self.progressLabel.setText("")
164+
self.progress.setValue(0)
165+
self.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
162166

163167
else:
164168
QMessageBox.critical(self.dialog, "Unable to execute algorithm", "Wrong or missing parameter values")
@@ -172,7 +176,7 @@ def accept(self):
172176

173177

174178
def reject(self):
175-
self.dialog.executed = False
179+
#self.dialog.executed = False
176180
self.dialog.close()
177181

178182
def setPercentage(self, i):

src/sextante/modeler/ModelerDialog.py

+23
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import copy
1111
from sextante.modeler.Providers import Providers
1212
from sextante.script.ScriptUtils import ScriptUtils
13+
from sextante.gui.HelpEditionDialog import HelpEditionDialog
14+
import pickle
1315

1416
class ModelerDialog(QtGui.QDialog):
1517
def __init__(self, alg=None):
@@ -28,6 +30,7 @@ def __init__(self, alg=None):
2830
else:
2931
self.alg = ModelerAlgorithm()
3032
self.alg.setModelerView(self)
33+
self.help = None
3134
self.update = False #indicates whether to update or not the toolbox after closing this dialog
3235

3336
def setupUi(self):
@@ -112,8 +115,12 @@ def setupUi(self):
112115

113116
#And the whole layout
114117
#==========================
118+
115119
self.buttonBox = QtGui.QDialogButtonBox()
116120
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
121+
self.editHelpButton = QtGui.QPushButton()
122+
self.editHelpButton.setText("Edit model help")
123+
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
117124
self.openButton = QtGui.QPushButton()
118125
self.openButton.setText("Open")
119126
self.buttonBox.addButton(self.openButton, QtGui.QDialogButtonBox.ActionRole)
@@ -126,6 +133,7 @@ def setupUi(self):
126133
QObject.connect(self.openButton, QtCore.SIGNAL("clicked()"), self.openModel)
127134
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveModel)
128135
QObject.connect(self.closeButton, QtCore.SIGNAL("clicked()"), self.closeWindow)
136+
QObject.connect(self.editHelpButton, QtCore.SIGNAL("clicked()"), self.editHelp)
129137

130138
self.globalLayout = QtGui.QVBoxLayout()
131139
self.globalLayout.setSpacing(2)
@@ -140,6 +148,14 @@ def setupUi(self):
140148
def closeWindow(self):
141149
self.close()
142150

151+
def editHelp(self):
152+
dlg = HelpEditionDialog(self.alg)
153+
dlg.exec_()
154+
#We store the description string in case there were not saved because there was no
155+
#filename defined yet
156+
if self.alg.descriptionFile is None and dlg.descriptions:
157+
self.help = dlg.descriptions
158+
143159
def createScript(self):
144160
if str(self.textGroup.text()).strip() == "":
145161
QMessageBox.warning(self, "Warning", "Please enter group name before saving")
@@ -173,6 +189,13 @@ def saveModel(self):
173189
fout.close()
174190
self.update = True
175191

192+
#if help strings were defined before saving the model for the first time, we do it here
193+
if self.help:
194+
f = open(self.alg.descriptionFile + ".help", "wb")
195+
pickle.dump(self.help, f)
196+
f.close()
197+
self.help = None
198+
176199
def openModel(self):
177200
filename = QtGui.QFileDialog.getOpenFileName(self, "Open Model", ModelerUtils.modelsFolder(), "SEXTANTE models (*.model)")
178201
if filename:

src/sextante/r/EditRScriptDialog.py

+29-15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from PyQt4.QtCore import *
33
from PyQt4.QtGui import *
44
from sextante.r.RUtils import RUtils
5+
import pickle
56

67
class EditRScriptDialog(QtGui.QDialog):
78
def __init__(self, alg):
@@ -12,27 +13,33 @@ def __init__(self, alg):
1213
self.update = False
1314

1415
def setupUi(self):
15-
self.setObjectName("Dialog")
16-
self.resize(655, 360)
1716
self.setWindowTitle("Edit script")
18-
self.text = QtGui.QTextEdit(self)
19-
self.text.setGeometry(QtCore.QRect(5, 5, 550, 350))
17+
layout = QVBoxLayout()
18+
self.text = QtGui.QTextEdit()
2019
self.text.setObjectName("text")
2120
self.text.setEnabled(True)
2221
if self.alg != None:
2322
self.text.setText(self.alg.script)
24-
self.saveButton = QtGui.QPushButton(self)
25-
self.saveButton.setGeometry(QtCore.QRect(570, 300, 80, 23))
26-
self.saveButton.setObjectName("saveButton")
27-
self.saveButton.setText("Save")
28-
self.cancelButton = QtGui.QPushButton(self)
29-
self.cancelButton.setGeometry(QtCore.QRect(570, 327, 80, 23))
30-
self.cancelButton.setObjectName("cancelButton")
31-
self.cancelButton.setText("Cancel")
32-
QObject.connect(self.saveButton, QtCore.SIGNAL("clicked()"), self.saveAlgorithm)
33-
QObject.connect(self.cancelButton, QtCore.SIGNAL("clicked()"), self.cancel)
23+
self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close)
24+
self.editHelpButton = QtGui.QPushButton()
25+
self.editHelpButton.setText("Edit model help")
26+
self.buttonBox.addButton(self.editHelpButton, QtGui.QDialogButtonBox.ActionRole)
27+
layout.addWidget(self.text)
28+
layout.addWidget(self.buttonBox)
29+
self.setLayout(layout)
30+
self.connect(self.buttonBox, SIGNAL("accepted()"), self.saveAlgorithm)
31+
self.connect(self.buttonBox, SIGNAL("rejected()"), self.cancelPressed)
32+
self.connect(self.editHelpButton, SIGNAL("clicked()"), self.editHelp)
3433
QtCore.QMetaObject.connectSlotsByName(self)
3534

35+
def editHelp(self):
36+
dlg = HelpEditionDialog(self.alg)
37+
dlg.exec_()
38+
#We store the description string in case there were not saved because there was no
39+
#filename defined yet
40+
if self.alg.descriptionFile is None and dlg.descriptions:
41+
self.help = dlg.descriptions
42+
3643
def saveAlgorithm(self):
3744
if self.alg!=None:
3845
filename = self.alg.descriptionFile
@@ -46,6 +53,13 @@ def saveAlgorithm(self):
4653
self.update = True
4754
self.close()
4855

49-
def cancel(self):
56+
#if help strings were defined before saving the model for the first time, we do it here
57+
if self.help:
58+
f = open(self.alg.descriptionFile + ".help", "wb")
59+
pickle.dump(self.help, f)
60+
f.close()
61+
self.help = None
62+
63+
def cancelPressed(self):
5064
self.update = False
5165
self.close()

0 commit comments

Comments
 (0)