[processing] Fixes #11363 - help file is created but not shown in the Help tab

This commit is contained in:
Salvatore Larosa 2014-10-08 18:57:25 +02:00
parent c768f13f14
commit bb723027f4

View File

@ -26,6 +26,7 @@ __copyright__ = '(C) 2012, Victor Olaya'
__revision__ = '$Format:%H$'
from PyQt4.QtCore import QCoreApplication
import os
import re
import json
@ -42,7 +43,6 @@ exps = [(r"\*(.*?)\*", r"<i>\1</i>"),
(r"::(\s*\n(\s*\n)*((\s+).*?\n)(((\4).*?\n)|(\s*\n))*)",r"<pre>\1</pre>"),
("\n+", "</p><p>")]
def getHtmlFromRstFile(rst):
if not os.path.exists(rst):
return None
@ -54,20 +54,17 @@ def getHtmlFromRstFile(rst):
s = p.sub(replace, s)
return s
def getHtmlFromHelpFile(alg, helpFile):
if not os.path.exists(helpFile):
return None
try:
with open(helpFile) as f:
descriptions = json.load(f)
return getHtmlFromDescriptionsDict(descriptions)
return getHtmlFromDescriptionsDict(alg, descriptions)
except:
return None
def getHtmlFromDescriptionsDict(alg, descriptions):
s = tr('<html><body><h2>Algorithm description</h2>\n')
s += '<p>' + getDescription(ALG_DESC, descriptions) + '</p>\n'
s += tr('<h2>Input parameters</h2>\n')
@ -80,12 +77,11 @@ def getHtmlFromDescriptionsDict(alg, descriptions):
s += '<p>' + getDescription(out.name, descriptions) + '</p>\n'
s += '<br>'
s += tr('<p align="right">Algorithm author: %s</p>') % getDescription(ALG_CREATOR, descriptions)
s += tr('<p align="right">Help author: %s</p>') + getDescription(ALG_HELP_CREATOR, descriptions)
s += tr('<p align="right">Algorithm version: %s</p>') + getDescription(ALG_VERSION, descriptions)
s += tr('<p align="right">Help author: %s</p>') % getDescription(ALG_HELP_CREATOR, descriptions)
s += tr('<p align="right">Algorithm version: %s</p>') % getDescription(ALG_VERSION, descriptions)
s += '</body></html>'
return s
def getDescription(name, descriptions):
if name in descriptions:
return unicode(descriptions[name]).replace("\n", "<br>")
@ -93,4 +89,4 @@ def getDescription(name, descriptions):
return ''
def tr(string):
return QtCore.QCoreApplication.translate('Help2Html', string)
return QCoreApplication.translate('Help2Html', string)