-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcatalogue.py
executable file
·67 lines (50 loc) · 1.75 KB
/
catalogue.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
import bpy
from typing import List, Union, TypeVar
T = TypeVar("T")
BPY_REGISTER_TYPE = Union[
bpy.types.Header,
bpy.types.KeyingSetInfo,
bpy.types.Menu,
bpy.types.Operator,
bpy.types.Panel,
bpy.types.PropertyGroup,
bpy.types.RenderEngine,
bpy.types.UIList,
]
########################################################################################
# Decorators for add-on initialization
########################################################################################
def bpy_register(cls: T) -> T:
"""
Add an object to the global catalogue to mark for registration with bpy.
### Use as decorator.
Parameters:
- cls (anything): bpy object class
Returns:
- anything: Unchanged object
"""
if cls not in Catalogue.bpy_register_classes:
Catalogue.bpy_register_classes.append(cls)
return cls
########################################################################################
# Catalogue class
########################################################################################
class Catalogue:
"""Stores all catalogued classes & provides methods to (de)register them"""
# Initialization lists
bpy_register_classes: List[BPY_REGISTER_TYPE] = []
# Initialization methods
@classmethod
def bpy_register(cls):
"""
Loop through all collected classes and register them with bpy.
"""
for bpy_cls in cls.bpy_register_classes:
bpy.utils.register_class(bpy_cls)
@classmethod
def bpy_deregister(cls):
"""
Loop through all collected classes and deregister them with bpy.
"""
for bpy_cls in reversed(cls.bpy_register_classes):
bpy.utils.unregister_class(bpy_cls)