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 #####
23 # We can store multiple preview collections here,
24 # however in this example we only store "main"
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()