2023-03-21 20:39:30 +00:00
|
|
|
import bpy
|
|
|
|
import os
|
|
|
|
|
|
|
|
icons_collection = None
|
|
|
|
icons_directory = os.path.dirname(__file__)
|
|
|
|
|
|
|
|
def initialize_icons_collection():
|
2023-03-21 20:54:53 +00:00
|
|
|
import bpy.utils.previews
|
|
|
|
global icons_collection
|
|
|
|
print("icons_collection : {}".format(icons_collection))
|
|
|
|
icons_collection = bpy.utils.previews.new()
|
2023-03-21 20:39:30 +00:00
|
|
|
|
|
|
|
def unload_icons():
|
2023-03-21 20:54:53 +00:00
|
|
|
bpy.utils.previews.remove(icons_collection)
|
2023-03-21 20:39:30 +00:00
|
|
|
|
|
|
|
def get_icon_id(identifier):
|
2023-03-21 20:54:53 +00:00
|
|
|
# The initialize_icons_collection function needs to be called first.
|
|
|
|
return get_icon(identifier).icon_id
|
2023-03-21 20:39:30 +00:00
|
|
|
|
|
|
|
def get_icon(identifier):
|
2023-03-21 20:54:53 +00:00
|
|
|
if identifier in icons_collection:
|
|
|
|
return icons_collection[identifier]
|
|
|
|
return icons_collection.load(identifier, os.path.join(icons_directory, identifier + ".png"), "IMAGE")
|
2023-03-21 20:39:30 +00:00
|
|
|
|
|
|
|
def register_icons():
|
2023-03-21 20:54:53 +00:00
|
|
|
initialize_icons_collection()
|
2023-03-21 20:39:30 +00:00
|
|
|
|
|
|
|
def unregister_icons():
|
2023-03-21 20:54:53 +00:00
|
|
|
unload_icons()
|