Skip to content

Commit 7b15f7a

Browse files
committed
Fix #13059 - Fix expression template load error
- Backported to 2.10.1 - Cherry-picked from fbad680
1 parent ce2f87a commit 7b15f7a

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

python/user.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,26 @@ def load_user_expressions(path):
4444
if not os.path.exists(initfile):
4545
open(initfile, "w").close()
4646

47+
template = """\"\"\"
48+
Define new functions using @qgsfunction. feature and parent must always be the
49+
last args. Use args=-1 to pass a list of values as arguments
50+
\"\"\"
51+
52+
from qgis.core import *
53+
from qgis.gui import *
54+
55+
@qgsfunction(args='auto', group='Custom')
56+
def func(value1, feature, parent):
57+
return value1
58+
"""
59+
60+
4761
try:
4862
import expressions
4963

5064
expressions.load = load_user_expressions
5165
expressions.load(expressionspath)
52-
expressions.template = """\"\"\"
53-
Define new functions using @qgsfunction. feature and parent must always be the
54-
last args. Use args=-1 to pass a list of values as arguments
55-
\"\"\"
56-
57-
from qgis.core import *
58-
from qgis.gui import *
59-
60-
@qgsfunction(args='auto', group='Custom')
61-
def func(value1, feature, parent):
62-
return value1
63-
"""
66+
expressions.template = template
6467
except ImportError:
6568
# We get a import error and crash for some reason even if we make the expressions package
6669
# TODO Fix the crash on first load with no expressions folder

0 commit comments

Comments
 (0)