Skip to content

Commit

Permalink
fixed #5693
Browse files Browse the repository at this point in the history
git-svn-id: http://sextante.googlecode.com/svn/trunk/soft/bindings/qgis-plugin@204 881b9c09-3ef8-f3c2-ec3d-21d735c97f4d
  • Loading branch information
volayaf committed Jun 1, 2012
1 parent caf1f36 commit 24fec70
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 37 deletions.
6 changes: 4 additions & 2 deletions src/sextante/grass/GrassAlgorithm.py
Expand Up @@ -41,7 +41,6 @@ def getIcon(self):

def helpFile(self):
folder = GrassUtils.grassHelpPath()
#if str(folder).strip() != "":
helpfile = str(folder) + os.sep + self.grassName + ".html"
if os.path.exists(helpfile):
return helpfile
Expand All @@ -51,7 +50,10 @@ def helpFile(self):

def getParameterDescriptions(self):
descs = {}
helpfile = self.helpFile()
try:
helpfile = self.helpFile()
except WrongHelpFileException:
return descs
if helpfile:
try:
infile = open(helpfile)
Expand Down
36 changes: 36 additions & 0 deletions src/sextante/gui/Help2Html.py
@@ -0,0 +1,36 @@
import pickle
from sextante.core.SextanteUtils import SextanteUtils
import os
class Help2Html():

ALG_DESC = "ALG_DESC"
ALG_CREATOR = "ALG_CREATOR"
ALG_HELP_CREATOR = "ALG_HELP_CREATOR"

def getHtmlFile(self, alg, helpFile):
if not os.path.exists(helpFile):
return None
self.alg = alg
f = open(helpFile, "rb")
self.descriptions = pickle.load(f)
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"
filename = SextanteUtils.tempFolder() + os.sep + "temphelp.html"
tempHtml = open(filename, "w")
tempHtml.write(s)

return filename

def getDescription(self, name):
if name in self.descriptions :
return self.descriptions[name]
else:
return ""
40 changes: 24 additions & 16 deletions src/sextante/gui/ParametersDialog.py
@@ -1,6 +1,6 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from PyQt4 import QtCore, QtGui, QtWebKit
from sextante.core.QGisLayers import QGisLayers
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
Expand Down Expand Up @@ -53,10 +53,6 @@ def setupUi(self, dialog, alg):
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.showHelpButton = QtGui.QPushButton()
self.showHelpButton.setText("Show help")
self.buttonBox.addButton(self.showHelpButton, QtGui.QDialogButtonBox.ActionRole)
QtCore.QObject.connect(self.showHelpButton, QtCore.SIGNAL("clicked()"), self.showHelp)
self.paramTable = ParametersPanel(self.alg, self.dialog)
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setWidget(self.paramTable)
Expand All @@ -70,7 +66,29 @@ def setupUi(self, dialog, alg):
self.verticalLayout = QtGui.QVBoxLayout(dialog)
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.scrollArea)
self.tabWidget = QtGui.QTabWidget()
self.tabWidget.setMinimumWidth(300)
self.tabWidget.addTab(self.scrollArea, "Parameters")
self.verticalLayout.addWidget(self.tabWidget)
self.webView = QtWebKit.QWebView()
html = None
try:
if self.alg.helpFile():
helpFile = self.alg.helpFile()
else:
html = "<h2>Sorry, no help is available for this algorithm.</h2>"
except WrongHelpFileException, e:
html = e.msg
self.webView.setHtml("<h2>Could not open help file :-( </h2>")
try:
if html:
self.webView.setHtml(html)
else:
url = QtCore.QUrl(helpFile)
self.webView.load(url)
except:
self.webView.setHtml("<h2>Could not open help file :-( </h2>")
self.tabWidget.addTab(self.webView, "Help")
self.verticalLayout.addWidget(self.progressLabel)
self.verticalLayout.addWidget(self.progress)
self.verticalLayout.addWidget(self.buttonBox)
Expand All @@ -79,16 +97,6 @@ def setupUi(self, dialog, alg):
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), self.reject)
QtCore.QMetaObject.connectSlotsByName(dialog)

def showHelp(self):
try:
if self.alg.helpFile():
dlg = HTMLViewerDialog(self.alg.helpFile())
dlg.exec_()
else:
QMessageBox.warning(self.dialog, "No help available", "No help is available for the current algorithm.")
except WrongHelpFileException, e:
QMessageBox.warning(self.dialog, "Help", e.msg)


def setParamValues(self):
params = self.alg.parameters
Expand Down
7 changes: 4 additions & 3 deletions src/sextante/modeler/ModelerAlgorithm.py
Expand Up @@ -15,6 +15,7 @@
from sextante.parameters.Parameter import Parameter
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterTableField import ParameterTableField
from sextante.gui.Help2Html import Help2Html

class ModelerAlgorithm(GeoAlgorithm):

Expand Down Expand Up @@ -457,11 +458,11 @@ def updateModelerView(self):
if self.modelerdialog:
self.modelerdialog.repaintModel()


def helpfile(self):
def helpFile(self):
helpfile = self.descriptionFile + ".help"
if os.path.exists(helpfile):
return helpfile
h2h = Help2Html()
return h2h.getHtmlFile(self, helpfile)
else:
return None

Expand Down
40 changes: 24 additions & 16 deletions src/sextante/modeler/ModelerParametersDialog.py
@@ -1,6 +1,6 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtCore, QtGui
from PyQt4 import QtCore, QtGui, QtWebKit
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
Expand Down Expand Up @@ -47,10 +47,6 @@ def setupUi(self):
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
self.showHelpButton = QtGui.QPushButton()
self.showHelpButton.setText("Show help")
self.buttonBox.addButton(self.showHelpButton, QtGui.QDialogButtonBox.ActionRole)
QtCore.QObject.connect(self.showHelpButton, QtCore.SIGNAL("clicked()"), self.showHelp)
self.tableWidget = QtGui.QTableWidget()
self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.tableWidget.setColumnCount(2)
Expand All @@ -66,23 +62,35 @@ def setupUi(self):
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setSpacing(2)
self.verticalLayout.setMargin(0)
self.verticalLayout.addWidget(self.tableWidget)
self.tabWidget = QtGui.QTabWidget()
self.tabWidget.setMinimumWidth(300)
self.tabWidget.addTab(self.tableWidget, "Parameters")
self.webView = QtWebKit.QWebView()
html = None
try:
if self.alg.helpFile():
helpFile = self.alg.helpFile()
else:
html = "<h2>Sorry, no help is available for this algorithm.</h2>"
except WrongHelpFileException, e:
html = e.msg
self.webView.setHtml("<h2>Could not open help file :-( </h2>")
try:
if html:
self.webView.setHtml(html)
else:
url = QtCore.QUrl(helpFile)
self.webView.load(url)
except:
self.webView.setHtml("<h2>Could not open help file :-( </h2>")
self.tabWidget.addTab(self.webView, "Help")
self.verticalLayout.addWidget(self.tabWidget)
self.verticalLayout.addWidget(self.buttonBox)
self.setLayout(self.verticalLayout)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), self.okPressed)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), self.cancelPressed)
QtCore.QMetaObject.connectSlotsByName(self)

def showHelp(self):
try:
if self.alg.helpFile():
dlg = HTMLViewerDialog(self.alg.helpFile())
dlg.exec_()
else:
QMessageBox.warning(self.dialog, "No help available", "No help is available for the current algorithm.")
except WrongHelpFileException, e:
QMessageBox.warning(self.dialog, "Help", e.msg)

def getRasterLayers(self):
layers = []
params = self.model.parameters
Expand Down
8 changes: 8 additions & 0 deletions src/sextante/r/RAlgorithm.py
Expand Up @@ -25,6 +25,7 @@
from sextante.parameters.ParameterExtent import ParameterExtent
from sextante.parameters.ParameterFile import ParameterFile
from sextante.outputs.OutputFile import OutputFile
from sextante.gui.Help2Html import Help2Html

class RAlgorithm(GeoAlgorithm):

Expand Down Expand Up @@ -279,6 +280,13 @@ def getImportCommands(self):
def getRCommands(self):
return self.commands

def helpFile(self):
helpfile = self.descriptionFile + ".help"
if os.path.exists(helpfile):
h2h = Help2Html()
return h2h.getHtmlFile(self, helpfile)
else:
return None

def checkBeforeOpeningParametersDialog(self):
if SextanteUtils.isWindows():
Expand Down
8 changes: 8 additions & 0 deletions src/sextante/script/ScriptAlgorithm.py
Expand Up @@ -19,6 +19,7 @@
from sextante.parameters.ParameterFile import ParameterFile
from sextante.outputs.OutputFile import OutputFile
import sys
from sextante.gui.Help2Html import Help2Html

class ScriptAlgorithm(GeoAlgorithm):

Expand Down Expand Up @@ -140,6 +141,13 @@ def processAlgorithm(self, progress):
exec(script)
sys.stdout = sys.__stdout__

def helpFile(self):
helpfile = self.descriptionFile + ".help"
if os.path.exists(helpfile):
h2h = Help2Html()
return h2h.getHtmlFile(self, helpfile)
else:
return None

class Redirection():
def __init__(self, progress):
Expand Down

0 comments on commit 24fec70

Please sign in to comment.