Skip to content


enable custom help in python expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored and m-kuhn committed Aug 25, 2017
1 parent 74306c7 commit fea9e92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/core/
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def func(self, values, feature, parent):

helptemplate = string.Template("""<h3>$name function</h3><br>$doc""")
name = kwargs.get('name', function.__name__)
helptext = function.__doc__ or ''
helptext = kwargs.get('help_text') or function.__doc__ or ''
helptext = helptext.strip()
expandargs = False

Expand Down
23 changes: 23 additions & 0 deletions tests/src/python/
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ def special(values, feature, parent):
def sqrt(values, feature, parent):

@qgsfunction(1, 'testing', register=False)
def help_with_docstring(values, feature, parent):
"""The help comes from the python docstring."""

help_text = 'The help comes from a variable.'

@qgsfunction(1, 'testing', register=False, help_text=help_text)
def help_with_variable(values, feature, parent):
"""This docstring is not used for the help."""

@qgsfunction(1, 'testing', register=False, usesgeometry=True)
def geomtest(values, feature, parent):
Expand All @@ -67,6 +79,17 @@ def testAutoCountsCorrectArgs(self):
args = function.params()
self.assertEqual(args, 3)

def testHelp(self):
html = ('<h3>help_with_variable function</h3><br>'
'The help comes from a variable.')
self.assertEqual(self.help_with_variable.helptext(), html)

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()
Expand Down

0 comments on commit fea9e92

Please sign in to comment.