-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path__init__.py
73 lines (60 loc) · 2.41 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
bl_info = {
"name": "Blender G'MIC Add-on",
"author": "Jonathan-David Schröder",
"blender": (2, 80, 0),
"version": (0, 0, 2),
"category": "Object",
}
import os
import sys
import platform
# TODO ensure that globals are tolerated in Blender3d python scripting guidelines..
__GMIC_ADDON_ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
__GMIC_FILTERS_JSON_PATH = os.path.join(__GMIC_ADDON_ROOT_PATH, "assets", "gmic_filters.json")
__GMIC_LOADED__ = False
__GMIC_PY_RELATIVE_LIBS_DIR = "-".join([platform.system().lower(), platform.architecture()[0]])
def register():
print("Registering " + bl_info["name"])
if not load_gmic_binary_library():
print("Failed loading G'MIC binary library :-(")
else:
import gmic
print(dir(gmic))
generate_nodes_from_gmic_filters(load_gmic_filters())
def unregister():
print("Unregistring " + bl_info["name"])
def load_gmic_binary_library():
global __GMIC_LOADED__
if __GMIC_LOADED__:
return True
__GMIC_LOADED__ = False
import os
import sys
libdir = os.path.join(__GMIC_ADDON_ROOT_PATH, __GMIC_PY_RELATIVE_LIBS_DIR)
if libdir not in sys.path:
sys.path.insert(0, libdir)
print("Added libdir to sys.path:", libdir)
try:
print("trying gmic import")
import gmic
print("gmic import worked")
__GMIC_LOADED__ = True
except ImportError as err:
raise ImportError("Cannot load G'MIC binary python module at {}. Details: {}".format(libdir, sys.exc_info()[0]))
try:
type(gmic.Gmic) == type
except AttributeError as err:
raise ImportError("G'MIC binary Python module was loaded improperly from {} and is without symbols. Details: {}".format(libdir, sys.exc_info()[0]))
return __GMIC_LOADED__
def load_gmic_filters():
import json
# TODO add cache? // mtime check?
filters_json = None
# TODO catch exception and make a nice error pop-in if open this file fails
with open(__GMIC_FILTERS_JSON_PATH) as f:
filters_json = f.read()
return json.loads(filters_json)
def generate_nodes_from_gmic_filters(gmic_filters_dict):
print("Loaded gmic_filters JSON overview:", gmic_filters_dict["format_version"], gmic_filters_dict["gmic_version"], "categories:", len(gmic_filters_dict["categories"]))
print("<STUB nodes should be generated from filters here>")
# TODO foreach loop on dict, create 1 node by filter