mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
enable custom help in python expressions
This commit is contained in:
parent
8a2cf3f709
commit
c606abc702
@ -112,7 +112,7 @@ def register_function(function, arg_count, group, usesgeometry=False,
|
||||
|
||||
helptemplate = string.Template("""<h3>$name function</h3><br>$doc""")
|
||||
name = kwargs.get('name', function.__name__)
|
||||
helptext = function.__doc__ or ''
|
||||
helptext = kwargs.get('helpText') or function.__doc__ or ''
|
||||
helptext = helptext.strip()
|
||||
expandargs = False
|
||||
|
||||
|
@ -43,6 +43,18 @@ class TestQgsExpressionCustomFunctions(unittest.TestCase):
|
||||
def sqrt(values, feature, parent):
|
||||
pass
|
||||
|
||||
@qgsfunction(1, 'testing', register=False)
|
||||
def help_with_docstring(values, feature, parent):
|
||||
"""The help comes from the python docstring."""
|
||||
pass
|
||||
|
||||
help_text = 'The help comes from a variable.'
|
||||
|
||||
@qgsfunction(1, 'testing', register=False, helpText=help_text)
|
||||
def help_with_variable(values, feature, parent):
|
||||
"""This docstring is not used for the help."""
|
||||
pass
|
||||
|
||||
@qgsfunction(1, 'testing', register=False, usesgeometry=True)
|
||||
def geomtest(values, feature, parent):
|
||||
pass
|
||||
@ -68,6 +80,17 @@ class TestQgsExpressionCustomFunctions(unittest.TestCase):
|
||||
args = function.params()
|
||||
self.assertEqual(args, 3)
|
||||
|
||||
def testHelp(self):
|
||||
QgsExpression.registerFunction(self.help_with_variable)
|
||||
html = ('<h3>help_with_variable function</h3><br>'
|
||||
'The help comes from a variable.')
|
||||
self.assertEqual(self.help_with_variable.helpText(), html)
|
||||
|
||||
QgsExpression.registerFunction(self.help_with_docstring)
|
||||
html = ('<h3>help_with_docstring function</h3><br>'
|
||||
'The help comes from the python docstring.')
|
||||
self.assertEqual(self.help_with_docstring.helpText(), html)
|
||||
|
||||
def testAutoArgsAreExpanded(self):
|
||||
function = self.expandargs
|
||||
args = function.params()
|
||||
|
Loading…
x
Reference in New Issue
Block a user