-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistrator.py
44 lines (37 loc) · 1.4 KB
/
registrator.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
#Util imports
from importlib import import_module
from pkgutil import iter_modules
from pathlib import Path
from inspect import isclass
#Blender imports
import bpy
#Project imports
from em.utils.deps_graph import DepsGraph
from em.base_classes.registrable import Registrable
from em import root_module_name
def register_all_classes():
classes = gather_all_registrable_classes()
for c in classes:
bpy.utils.register_class(c)
def unregister_all_classes():
classes = gather_all_registrable_classes()
for c in reversed(classes):
bpy.utils.unregister_class(c)
def gather_all_registrable_classes():
root_dir = Path(__file__).parent
class_set = set()
_gather_all_registrable_classes(root_dir, class_set, root_module_name)
return DepsGraph.Sorted(class_set)
def _gather_all_registrable_classes(path, class_set, module_path):
if module_path:
module_path += '.'
for (_, modulename, ispkg) in iter_modules([path]):
module = import_module(module_path + modulename)
if ispkg:
_gather_all_registrable_classes(path.joinpath(modulename), class_set, module_path + modulename)
else:
for att_name in dir(module):
att = getattr(module, att_name)
if isclass(att):
if (Registrable in att.__bases__):
class_set.add(att)