Cleanup: trailing space
[blender-addons.git] / blenderkit / icons.py
blob5d877b253b7cb1e8d13bfa8d1c76d0f7ce168247
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
20 import os
21 import bpy
23 # We can store multiple preview collections here,
24 # however in this example we only store "main"
25 icon_collections = {}
27 icons_read = {
28 'fp.png': 'free',
29 'flp.png': 'full',
30 'test.jpg': 'test',
34 def register_icons():
35 # Note that preview collections returned by bpy.utils.previews
36 # are regular py objects - you can use them to store custom data.
37 import bpy.utils.previews
38 pcoll = bpy.utils.previews.new()
40 # path to the folder where the icon is
41 # the path is calculated relative to this py file inside the addon folder
42 icons_dir = os.path.join(os.path.dirname(__file__), "thumbnails")
44 # load a preview thumbnail of a file and store in the previews collection
45 for ir in icons_read.keys():
46 pcoll.load(icons_read[ir], os.path.join(icons_dir, ir), 'IMAGE')
48 # iprev = pcoll.new(icons_read[ir])
49 # img = bpy.data.images.load(os.path.join(icons_dir, ir))
50 # iprev.image_size = (img.size[0], img.size[1])
51 # iprev.image_pixels_float = img.pixels[:]
53 icon_collections["main"] = pcoll
56 def unregister_icons():
57 for pcoll in icon_collections.values():
58 bpy.utils.previews.remove(pcoll)
59 icon_collections.clear()