[Bf-blender-cvs] [de02dac] ui-preview-buttons: improving path handling in py samples for ui-previews
Ines Almeida
noreply at git.blender.org
Sun May 10 13:00:50 CEST 2015
Commit: de02dac321817288d62674754239e3fe2183c0ba
Author: Ines Almeida
Date: Sun May 10 11:57:21 2015 +0100
Branches: ui-preview-buttons
https://developer.blender.org/rBde02dac321817288d62674754239e3fe2183c0ba
improving path handling in py samples for ui-previews
===================================================================
M release/scripts/templates_py/ui_previews_custom_icon.py
M release/scripts/templates_py/ui_previews_dynamic_enum.py
===================================================================
diff --git a/release/scripts/templates_py/ui_previews_custom_icon.py b/release/scripts/templates_py/ui_previews_custom_icon.py
index 0f66c8c..236e90c 100644
--- a/release/scripts/templates_py/ui_previews_custom_icon.py
+++ b/release/scripts/templates_py/ui_previews_custom_icon.py
@@ -4,7 +4,7 @@
# IMPORTANT NOTE: if you run this sample, there will be no icon in the button
# You need to replace the image path with a real existing one.
# For distributable addons, it is recommended to place the icons inside the
-# addon folder and access it with bpy.utils.user_resource for portability
+# addon folder and access it relative to the py script file for portability
#
#
# Other use cases for UI-previews:
@@ -46,18 +46,21 @@ preview_collections = {}
def register():
+ # path to the folder where the icon is
+ # the path is calculated relative to this py file inside the addon folder
+ my_icons_dir = os.path.join(os.path.dirname(__file__), "icons")
+
# Note that preview collections returned by bpy.utils.previews
# are regular py objects - you can use them to store custom data.
import bpy.utils.previews
pcoll = bpy.utils.previews.new()
- pcoll.my_icons_dir = bpy.utils.user_resource('SCRIPTS', "addons") \
- + "/my_addon_folder/icons/"
+
# load a preview thumbnail of a file and store in the previews collection
pcoll.load(
# identifier
"my_icon",
# path to image
- pcoll.my_icons_dir + "icon-image.png",
+ os.path.join( my_icons_dir, "icon-image.png"),
# file type to generate preview from. others are: MOVIE, FONT, BLEND
'IMAGE')
diff --git a/release/scripts/templates_py/ui_previews_dynamic_enum.py b/release/scripts/templates_py/ui_previews_dynamic_enum.py
index 0bf1a5f..2e45e4b 100644
--- a/release/scripts/templates_py/ui_previews_dynamic_enum.py
+++ b/release/scripts/templates_py/ui_previews_dynamic_enum.py
@@ -12,8 +12,8 @@
# For custom icons, see the template 'ui_previews_custom_icon"
#
# For distributable addons, it is recommended to place the icons inside the
-# addon folder and access it with bpy.utils.user_resource for portability:
-# bpy.utils.user_resource('SCRIPTS', "addons") + "/my_addon/imgs/"
+# addon folder and access it relative to the py script file for portability:
+# os.path.join(os.path.dirname(__file__), "imgs")
import os
More information about the Bf-blender-cvs
mailing list