From a47dfa8f322e669f9ddfa4d7e5900fd4efc1e056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 22 Jul 2016 18:23:34 +0200 Subject: [PATCH] Texture browser: UI polish for HDRi variation selector --- blender_cloud/texture_browser.py | 39 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/blender_cloud/texture_browser.py b/blender_cloud/texture_browser.py index 31fc6ec..838ddc6 100644 --- a/blender_cloud/texture_browser.py +++ b/blender_cloud/texture_browser.py @@ -847,8 +847,8 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin, bpy.types.Operator): bl_idname = 'pillar.switch_hdri' bl_label = 'Switch with another variation' - bl_description = 'Downloads another variation of an HDRi, ' \ - 'and switches the current image with it' + bl_description = 'Downloads the selected variation of an HDRi, ' \ + 'replacing the current image' log = logging.getLogger('bpy.ops.%s' % bl_idname) @@ -942,18 +942,6 @@ class PILLAR_OT_switch_hdri(pillar.PillarOperatorMixin, addon_keymaps = [] -def image_by_file_uuid(file_uuid): - """Finds the image datablock by its file UUID. - - Returns None if the image cannot be found. - """ - - image = next((img for img in bpy.data.images - if img.get('bcloud_file_uuid') == file_uuid), - None) - return image - - def image_editor_menu(self, context): self.layout.operator(BlenderCloudBrowser.bl_idname, text='Get image from Blender Cloud', @@ -978,15 +966,23 @@ def _hdri_download_panel(self, current_image): return if current_image['bcloud_node_type'] != 'hdri': return + try: + current_variation = current_image['bcloud_file_uuid'] + except KeyError: + log.warning('Image %r has a bcloud_node_type but no bcloud_file_uuid property.', + current_image.name) + return - row = self.layout.row(align=True) + row = self.layout.row(align=True).split(0.3) row.label('HDRi', icon_value=blender.icon('CLOUD')) row.prop(current_image, 'hdri_variation', text='') - props = row.operator(PILLAR_OT_switch_hdri.bl_idname, - text='Replace', - icon='FILE_REFRESH') - props.image_name = current_image.name - props.file_uuid = current_image.hdri_variation + + if current_image.hdri_variation != current_variation: + props = row.operator(PILLAR_OT_switch_hdri.bl_idname, + text='Replace', + icon='FILE_REFRESH') + props.image_name = current_image.name + props.file_uuid = current_image.hdri_variation def hdri_variation_choices(self, context): @@ -1017,7 +1013,8 @@ def register(): # TODO: when an image is selected, switch this property to its current resolution. bpy.types.Image.hdri_variation = bpy.props.EnumProperty( name='HDRi variations', - items=hdri_variation_choices + items=hdri_variation_choices, + description='Select a variation with which to replace this image' ) # handle the keymap