|
| 1 | +# Copyright 2016 Maxime Herpin, Jake Dube |
| 2 | +# |
| 3 | +# ##### BEGIN GPL LICENSE BLOCK ###### |
| 4 | +# This file is part of Modular Tree. |
| 5 | +# |
| 6 | +# Modular Tree is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU General Public License as published by |
| 8 | +# the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Modular Tree is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with Modular Tree. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +# ##### END GPL LICENSE BLOCK ##### |
| 19 | + |
| 20 | +from os.path import join, dirname |
| 21 | +from bpy.utils import previews |
| 22 | + |
| 23 | +# global variables |
| 24 | +ICONS = {'TREE', 'TREE_UPDATE', 'BATCH_TREE', 'TWIG'} |
| 25 | +ICON_COLLECTION = {} |
| 26 | + |
| 27 | + |
| 28 | +def register_icons(): |
| 29 | + preview_coll = previews.new() |
| 30 | + icons_folder = join(dirname(__file__), "custom_icons") |
| 31 | + |
| 32 | + for icon in ICONS: |
| 33 | + preview_coll.load(icon, join(icons_folder, icon + ".png"), 'IMAGE') |
| 34 | + |
| 35 | + ICON_COLLECTION["main"] = preview_coll |
| 36 | + |
| 37 | + |
| 38 | +def unregister_icons(): |
| 39 | + for collection in ICON_COLLECTION.values(): |
| 40 | + previews.remove(collection) |
| 41 | + ICON_COLLECTION.clear() |
| 42 | + |
| 43 | + |
| 44 | +def get_icon(icon): |
| 45 | + preview_coll = ICON_COLLECTION["main"] |
| 46 | + return preview_coll[icon].icon_id |
0 commit comments