Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed problem when editing help and saving R scripts
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@230 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
- Loading branch information
volayaf
committed
Jun 7, 2012
1 parent
9c84243
commit 15dfeff
Showing
4 changed files
with
61 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,88 @@ | ||
from PyQt4 import QtCore, QtGui | ||
from PyQt4.QtCore import * | ||
from PyQt4.QtGui import * | ||
from sextante.r.RUtils import RUtils | ||
import pickle | ||
from sextante.gui.HelpEditionDialog import HelpEditionDialog | ||
import pickle | ||
from sextante.r.RAlgorithm import RAlgorithm | ||
from sextante.r.RUtils import RUtils | ||
|
||
class EditRScriptDialog(QtGui.QDialog): | ||
def __init__(self, alg): | ||
self.alg = alg | ||
if self.alg is not None: | ||
self.filename = self.alg.descriptionFile | ||
else: | ||
self.filename = None | ||
QtGui.QDialog.__init__(self) | ||
self.setModal(True) | ||
self.setupUi() | ||
self.update = False | ||
self.help = None | ||
|
||
def setupUi(self): | ||
self.resize(600,400) | ||
self.setWindowTitle("Edit script") | ||
self.resize(600, 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.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Close) | ||
self.editHelpButton = QtGui.QPushButton() | ||
self.editHelpButton.setText("Edit model help") | ||
self.editHelpButton.setText("Edit script 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.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.closeButton, QtCore.SIGNAL("clicked()"), self.cancelPressed) | ||
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) | ||
if self.alg is None: | ||
alg = RAlgorithm(None, unicode(self.text.toPlainText())) | ||
else: | ||
alg = self.alg | ||
dlg = HelpEditionDialog(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: | ||
if self.alg is None and dlg.descriptions: | ||
self.help = dlg.descriptions | ||
|
||
|
||
def saveAlgorithm(self): | ||
if self.alg!=None: | ||
filename = self.alg.descriptionFile | ||
else: | ||
filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", RUtils.RScriptsFolder(), "R-SEXTANTE scripts (*.rsx)") | ||
if self.filename is None: | ||
self.filename = QtGui.QFileDialog.getSaveFileName(self, "Save Script", RUtils.RScriptsFolder(), "SEXTANTE R script (*.rsx)") | ||
|
||
if filename: | ||
#self.alg.descriptionFile = filename | ||
text = self.text.toPlainText() | ||
fout = open(filename, "w") | ||
if self.filename: | ||
text = str(self.text.toPlainText()) | ||
if self.alg is not None: | ||
self.alg.script = text | ||
fout = open(self.filename, "w") | ||
fout.write(text) | ||
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(filename + ".help", "wb") | ||
f = open(self.filename + ".help", "wb") | ||
pickle.dump(self.help, f) | ||
f.close() | ||
self.help = None | ||
QtGui.QMessageBox.information(self, "Script saving", "Script was correctly saved.") | ||
self.close() | ||
else: | ||
self.filename = None | ||
|
||
def cancelPressed(self): | ||
self.update = False | ||
#self.update = False | ||
self.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
##layer = raster | ||
##[Example scripts]=group | ||
##layer = raster | ||
##showplots | ||
hist(as.matrix(layer)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters