\"\"\" from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def my_sum(value1, value2, feature, parent): \"\"\" Calculates the sum of the two parameters value1 and value2. <h2>Example usage:</h2> <ul> <li>my_sum(5, 8) -> 13</li> <li>my_sum(\"fiel1\", \"field2\") -> 42</li> </ul> \"\"\" return value1 + value2 """ try: import expressions expressions.load = load_user_expressions expressions.load(expressionspath) expressions.template = template except ImportError: # We get a import error and crash for some reason even if we make the expressions package # TODO Fix the crash on first load with no expressions folder # But for now it's not the end of the world if it doesn't load the first time pass
template = """from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def my_sum(value1, value2, feature, parent): \"\"\" Calculates the sum of the two parameters value1 and value2. <h2>Example usage:</h2> <ul> <li>my_sum(5, 8) -> 13</li> <li>my_sum(\"field1\", \"field2\") -> 42</li> </ul> \"\"\" return value1 + value2 """ default_expression_template = template try: import expressions expressions.load = load_user_expressions expressions.load(expressionspath) expressions.template = template except ImportError: # We get a import error and crash for some reason even if we make the expressions package # TODO Fix the crash on first load with no expressions folder # But for now it's not the end of the world if it doesn't load the first time pass