From 250939dc3241c34b176aa93c049740e9f8f1f1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 8 Jul 2016 17:00:44 +0200 Subject: [PATCH] Added custom cloud icon --- blender_cloud/blender.py | 66 +++++++++++++++++++++++------ blender_cloud/icons/icon-cloud.png | Bin 0 -> 1627 bytes blender_cloud/image_sharing.py | 3 +- 3 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 blender_cloud/icons/icon-cloud.png diff --git a/blender_cloud/blender.py b/blender_cloud/blender.py index 9210367..d21200f 100644 --- a/blender_cloud/blender.py +++ b/blender_cloud/blender.py @@ -4,6 +4,7 @@ Separated from __init__.py so that we can import & run from non-Blender environm """ import logging +import os.path import bpy from bpy.types import AddonPreferences, Operator, WindowManager, Scene, PropertyGroup @@ -17,6 +18,8 @@ PILLAR_SERVER_URL = 'https://cloudapi.blender.org/' ADDON_NAME = 'blender_cloud' log = logging.getLogger(__name__) +icons = None + def redraw(self, context): context.area.tag_redraw() @@ -120,28 +123,28 @@ class BlenderCloudPreferences(AddonPreferences): blender_id_profile = blender_id.get_active_profile() if blender_id is None: - icon = 'ERROR' + msg_icon = 'ERROR' text = 'This add-on requires Blender ID' help_text = 'Make sure that the Blender ID add-on is installed and activated' elif not blender_id_profile: - icon = 'ERROR' + msg_icon = 'ERROR' text = 'You are logged out.' help_text = 'To login, go to the Blender ID add-on preferences.' elif bpy.app.debug and pillar.SUBCLIENT_ID not in blender_id_profile.subclients: - icon = 'QUESTION' + msg_icon = 'QUESTION' text = 'No Blender Cloud credentials.' help_text = ('You are logged in on Blender ID, but your credentials have not ' 'been synchronized with Blender Cloud yet. Press the Update ' 'Credentials button.') else: - icon = 'WORLD_DATA' + msg_icon = 'WORLD_DATA' text = 'You are logged in as %s.' % blender_id_profile.username help_text = ('To logout or change profile, ' 'go to the Blender ID add-on preferences.') # Authentication stuff auth_box = layout.box() - auth_box.label(text=text, icon=icon) + auth_box.label(text=text, icon=msg_icon) help_lines = textwrap.wrap(help_text, 80) for line in help_lines: @@ -151,18 +154,18 @@ class BlenderCloudPreferences(AddonPreferences): # Texture browser stuff texture_box = layout.box() - texture_box.enabled = icon != 'ERROR' + texture_box.enabled = msg_icon != 'ERROR' sub = texture_box.column() - sub.label(text='Local directory for downloaded textures') + sub.label(text='Local directory for downloaded textures', icon_value=icon('CLOUD')) sub.prop(self, "local_texture_dir", text='Default') sub.prop(context.scene, "local_texture_dir", text='Current scene') # Blender Sync stuff bss = context.window_manager.blender_sync_status bsync_box = layout.box() - bsync_box.enabled = icon != 'ERROR' + bsync_box.enabled = msg_icon != 'ERROR' row = bsync_box.row().split(percentage=0.33) - row.label('Blender Sync with Blender Cloud') + row.label('Blender Sync with Blender Cloud', icon_value=icon('CLOUD')) icon_for_level = { 'INFO': 'NONE', @@ -170,9 +173,9 @@ class BlenderCloudPreferences(AddonPreferences): 'ERROR': 'ERROR', 'SUBSCRIBE': 'ERROR', } - icon = icon_for_level[bss.level] if bss.message else 'NONE' + msg_icon = icon_for_level[bss.level] if bss.message else 'NONE' message_container = row.row() - message_container.label(bss.message, icon=icon) + message_container.label(bss.message, icon=msg_icon) sub = bsync_box.column() @@ -182,8 +185,8 @@ class BlenderCloudPreferences(AddonPreferences): # Image Share stuff share_box = layout.box() - share_box.label('Image Sharing on Blender Cloud') - texture_box.enabled = icon != 'ERROR' + share_box.label('Image Sharing on Blender Cloud', icon_value=icon('CLOUD')) + texture_box.enabled = msg_icon != 'ERROR' share_box.prop(self, 'open_browser_after_share') def draw_subscribe_button(self, layout): @@ -284,6 +287,39 @@ def preferences() -> BlenderCloudPreferences: return bpy.context.user_preferences.addons[ADDON_NAME].preferences +def load_custom_icons(): + global icons + + if icons is not None: + # Already loaded + return + + import bpy.utils.previews + icons = bpy.utils.previews.new() + my_icons_dir = os.path.join(os.path.dirname(__file__), 'icons') + icons.load('CLOUD', os.path.join(my_icons_dir, 'icon-cloud.png'), 'IMAGE') + + +def unload_custom_icons(): + global icons + + if icons is None: + # Already unloaded + return + + bpy.utils.previews.remove(icons) + icons = None + + +def icon(icon_name: str) -> int: + """Returns the icon ID for the named icon. + + Use with layout.operator('pillar.image_share', icon_value=icon('CLOUD')) + """ + + return icons[icon_name].icon_id + + def register(): bpy.utils.register_class(BlenderCloudPreferences) bpy.utils.register_class(PillarCredentialsUpdate) @@ -310,8 +346,12 @@ def register(): WindowManager.blender_sync_status = PointerProperty(type=SyncStatusProperties) + load_custom_icons() + def unregister(): + unload_custom_icons() + gui.unregister() bpy.utils.unregister_class(PillarCredentialsUpdate) diff --git a/blender_cloud/icons/icon-cloud.png b/blender_cloud/icons/icon-cloud.png new file mode 100644 index 0000000000000000000000000000000000000000..a4d229ddb77d95d939c3dce0a6a9a656da184688 GIT binary patch literal 1627 zcmV-h2Bi6kP)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00qNIL_t(o!^M|hXjI!3#=m{$ zUovBoDM>CS9i!CN#*zmqLj!SAwe&(M7Lis#d*H`F0$2rv0qYA@z{|YE%d}R~*RNi^`eAEp z>yD>SpN12OM82u1$&N;&nwpwYGMNkx4-c2b9;c_5#Z#lga72y1Log+S>f&3Qo3j~)N z+y_K~^}u%E*XeZn`l?l{3W-F*o|%~`01j`$1)RHg@7gsrHBLMp&$+JqF>u^V;>$o_ zIl(J|IPg=T3m80c;>2`WSs4!=Ja}8+H;4=j3^$gZC)jOZ)>z5@FgGy zGy&~EFE9yYVzC%)ZEX~T=H_NLZrn&Jl`7=(`A5JXfsefA^erS10M-KgfL{W?1wH}p z1Gy(po;Z@|@9!^)KzDaHl8{6=9A@v{y@iR1i9xTjE9XxK5bo*eIndnP{9@(Gm5yau zq*AGWdrjsJ4h|xTTeogeES^1kMk;a;dcahll?%kuLq(q5CLgVA( zbFWy%VlkDLmg>fh8}IZ|3xz_uaN&ZsZr!Q_2M&Dg`Sa&Lk`xnA`}pzWpO=-DIj2sY znspq9v9Yn&*zerAlQnDBkjv$GS3G?9kW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