-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistry.py
More file actions
64 lines (46 loc) · 1.6 KB
/
Copy pathregistry.py
File metadata and controls
64 lines (46 loc) · 1.6 KB
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
import bpy
from typing import Any, Callable
_bpy_class_registry: list[type] = []
_timer_registry: list[Callable[Any, int | None]] = []
# BPY CLASSES
def register_class(cls: type) -> type:
_bpy_class_registry.append(cls)
return cls
def get() -> list[type]:
return list(_bpy_class_registry)
def blender_register_classes():
for module in get():
bpy.utils.register_class(module)
def blender_unregister_classes():
for module in get():
bpy.utils.unregister_class(module)
# TIMERS
def register_timer(clb: Callable[Any, Any]):
_timer_registry.append(clb)
return clb
def get_timers() -> list[Callable[Any, int | None]]:
return list(_timer_registry)
def blender_register_timers():
for timer in _timer_registry:
bpy.app.timers.register(timer, persistent=True)
def blender_unregister_timers():
for timer in _timer_registry:
bpy.app.timers.unregister(timer)
import os
from bpy.utils.previews import ImagePreviewCollection
_icons_pcoll: ImagePreviewCollection | None = None
def blender_register_icons():
global _icons_pcoll
_icons_pcoll = bpy.utils.previews.new()
my_icons_dir = os.path.join(os.path.dirname(__file__), "icons")
for filename in os.listdir(my_icons_dir):
_icons_pcoll.load(filename, os.path.join(my_icons_dir, filename), 'IMAGE')
def blender_unregister_icons():
global _icons_pcoll
if not _icons_pcoll: return
bpy.utils.previews.remove(_icons_pcoll)
del _icons_pcoll
def get_icon(icon_id: str) -> int:
global _icons_pcoll
if not _icons_pcoll: return -1
return _icons_pcoll[icon_id].icon_id