From fc150a773972d561a4c5148acfafeeaf37acf58f Mon Sep 17 00:00:00 2001 From: tdierks Date: Wed, 11 Feb 2015 00:41:51 -0500 Subject: [PATCH] Explain importing for filter functions This code is correct, but doesn't work correctly with signs since they got JSON text formats in 14w25a. I will try to create another PR with an improved sign function tomorrow, but it's turning out to be complex, so for the moment, I'll stick with this tip on making imports work. --- docs/signs.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/signs.rst b/docs/signs.rst index 6490230..36d651e 100644 --- a/docs/signs.rst +++ b/docs/signs.rst @@ -55,6 +55,15 @@ be used as the hover text, the second will be used as the info window content:: if poi['id'] == "Chest": return ("Chest", "Chest with %d items" % len(poi['Items'])) +Because of the way the config file is loaded, if you need to import a function or module +for use in your filter function, you need to explicitly load it into the global namespace: + + global escape + from cgi import escape + def signFilter(poi): + if poi['id'] == 'Sign': + return "\n".join(map(escape, [poi['Text1'], poi['Text2'], poi['Text3'], poi['Text4']])) + Since writing these filters can be a little tedious, a set of predefined filters functions are provided. See the :ref:`predefined_filter_functions` section for details.