-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtextify_icons.py
More file actions
42 lines (28 loc) · 908 Bytes
/
textify_icons.py
File metadata and controls
42 lines (28 loc) · 908 Bytes
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
import atexit
from pathlib import Path
from bpy.utils import previews
_custom_icons = None
def load_icons():
global _custom_icons
if _custom_icons is None:
_custom_icons = previews.new()
icons_dir = Path(__file__).resolve().parent / "icons"
for icon_file in icons_dir.glob("*.png"):
icon_name = icon_file.stem
if icon_name not in _custom_icons:
_custom_icons.load(icon_name, str(icon_file), 'IMAGE')
def unload_icons():
global _custom_icons
if _custom_icons:
previews.remove(_custom_icons)
_custom_icons = None
def get_icon(name):
if _custom_icons is None:
return None
icon = _custom_icons.get(name)
return icon.icon_id if icon else None
atexit.register(unload_icons)
def register():
load_icons()
def unregister():
load_icons()