-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Function editor for expression widget.
Allows for adding on the fly functions to the expression engine. Functions are saved in qgis2\python\expressions. New qgis.user module in Python. The qgis.user.expressions package points to the qgis2\python\expressions package in the users home
- Loading branch information
Showing
8 changed files
with
866 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import sys | ||
import glob | ||
|
||
from qgis.core import QgsApplication | ||
|
||
def load_user_expressions(path): | ||
""" | ||
Load all user expressions from the given paths | ||
""" | ||
#Loop all py files and import them | ||
modules = glob.glob(path + "/*.py") | ||
names = [os.path.basename(f)[:-3] for f in modules] | ||
for name in names: | ||
if name == "__init__": | ||
continue | ||
# As user expression functions should be registed with qgsfunction | ||
# just importing the file is enough to get it to load the functions into QGIS | ||
__import__("expressions.{0}".format(name), locals(), globals()) | ||
|
||
|
||
userpythonhome = os.path.join(QgsApplication.qgisSettingsDirPath(), "python") | ||
expressionspath = os.path.join(userpythonhome, "expressions") | ||
startuppy = os.path.join(userpythonhome, "startup.py") | ||
|
||
# exec startup script | ||
if os.path.exists(startuppy): | ||
execfile(startuppy, locals(), globals()) | ||
|
||
if not os.path.exists(expressionspath): | ||
os.makedirs(expressionspath) | ||
|
||
initfile = os.path.join(expressionspath, "__init__.py") | ||
if not os.path.exists(initfile): | ||
open(initfile, "w").close() | ||
|
||
import expressions | ||
|
||
expressions.load = load_user_expressions | ||
expressions.load(expressionspath) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.