-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic_path.py
56 lines (39 loc) · 1.55 KB
/
public_path.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
import bpy
from typing import Optional, Union, Any
from pathlib import Path
def get_pref(data_path: Optional[str] = None) -> bpy.types.AddonPreferences | Any:
pref = bpy.context.preferences.addons.get(__package__).preferences
if data_path is None:
return pref
# search attribute by path
def search_attr(obj, path: str):
if '.' in path:
path = path.split('.')
return search_attr(getattr(obj, path[0]), path[1])
else:
return getattr(obj, path)
return search_attr(pref, data_path)
def get_asset_directory() -> Path:
return Path(__file__).parent.joinpath('asset')
def get_tool_icon(icon_name: str) -> str:
return get_asset_directory().joinpath('bl_ui_icon', 'icons_tool', icon_name).as_posix()
def get_svg_icon(name: Optional[str] = None) -> str | None:
d = get_asset_directory().joinpath('bl_ui_icon', 'icons_svg')
if not name:
return d.as_posix()
if (p := d.joinpath(name + '.svg')).exists():
return p.as_posix()
return None
def get_color_palettes_directory() -> Path:
return get_asset_directory().joinpath('color_palette')
def get_color_palettes() -> dict[str, list[str]]:
"""Return the color palette directory and file names.
"""
d = get_color_palettes_directory()
res = {}
for p in d.iterdir():
if p.is_dir():
res[p.name] = [f.stem for f in p.iterdir() if f.name.endswith('.jpg')]
return res
def get_png_icons_directory() -> Path:
return get_asset_directory().joinpath('bl_ui_icon', 'icons_align')