From 641b51496abee64a1f413aa41262421b788cece8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Tue, 30 Oct 2018 11:29:32 +0100 Subject: [PATCH] Some drawing code simplification --- blender_cloud/attract/__init__.py | 101 +++++++++++++++--------------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/blender_cloud/attract/__init__.py b/blender_cloud/attract/__init__.py index 68ed2ce..efe1304 100644 --- a/blender_cloud/attract/__init__.py +++ b/blender_cloud/attract/__init__.py @@ -189,56 +189,8 @@ class ATTRACT_PT_tools(AttractPollMixin, Panel): layout = self.layout strip_types = {'MOVIE', 'IMAGE', 'META', 'COLOR'} - selshots = list(selected_shots(context)) if strip and strip.type in strip_types and strip.atc_object_id: - if len(selshots) > 1: - noun = '%i Shots' % len(selshots) - else: - noun = 'This Shot' - - if strip.atc_object_id_conflict: - warnbox = layout.box() - warnbox.alert = True - warnbox.label(text='Warning: This shot is linked to multiple sequencer strips.', - icon='ERROR') - - layout.prop(strip, 'atc_name', text='Name') - layout.prop(strip, 'atc_status', text='Status') - - # Create a special sub-layout for read-only properties. - ro_sub = layout.column(align=True) - ro_sub.enabled = False - ro_sub.prop(strip, 'atc_description', text='Description') - ro_sub.prop(strip, 'atc_notes', text='Notes') - - if strip.atc_is_synced: - sub = layout.column(align=True) - row = sub.row(align=True) - if bpy.ops.attract.submit_selected.poll(): - row.operator('attract.submit_selected', - text='Submit %s' % noun, - icon='TRIA_UP') - else: - row.operator(ATTRACT_OT_submit_all.bl_idname) - row.operator(ATTRACT_OT_shot_fetch_update.bl_idname, - text='', icon='FILE_REFRESH') - row.operator(ATTRACT_OT_shot_open_in_browser.bl_idname, - text='', icon='WORLD') - row.operator(ATTRACT_OT_copy_id_to_clipboard.bl_idname, - text='', icon='COPYDOWN') - sub.operator(ATTRACT_OT_make_shot_thumbnail.bl_idname, - text='Render Thumbnail for %s' % noun, - icon='RENDER_STILL') - - # Group more dangerous operations. - dangerous_sub = layout.split(**blender.factor(0.6), align=True) - dangerous_sub.operator('attract.strip_unlink', - text='Unlink %s' % noun, - icon='PANEL_CLOSE') - dangerous_sub.operator(ATTRACT_OT_shot_delete.bl_idname, - text='Delete %s' % noun, - icon='CANCEL') - + self._draw_attractstrip_buttons(context, strip) elif context.selected_sequences: if len(context.selected_sequences) > 1: noun = 'Selected Strips' @@ -250,6 +202,56 @@ class ATTRACT_PT_tools(AttractPollMixin, Panel): else: layout.operator(ATTRACT_OT_submit_all.bl_idname) + def _draw_attractstrip_buttons(self, context, strip): + """Draw buttons when selected strips are Attract shots.""" + + layout = self.layout + selshots = list(selected_shots(context)) + + if len(selshots) > 1: + noun = '%i Shots' % len(selshots) + else: + noun = 'This Shot' + if strip.atc_object_id_conflict: + warnbox = layout.box() + warnbox.alert = True + warnbox.label(text='Warning: This shot is linked to multiple sequencer strips.', + icon='ERROR') + layout.prop(strip, 'atc_name', text='Name') + layout.prop(strip, 'atc_status', text='Status') + # Create a special sub-layout for read-only properties. + ro_sub = layout.column(align=True) + ro_sub.enabled = False + ro_sub.prop(strip, 'atc_description', text='Description') + ro_sub.prop(strip, 'atc_notes', text='Notes') + if strip.atc_is_synced: + sub = layout.column(align=True) + row = sub.row(align=True) + if bpy.ops.attract.submit_selected.poll(): + row.operator('attract.submit_selected', + text='Submit %s' % noun, + icon='TRIA_UP') + else: + row.operator(ATTRACT_OT_submit_all.bl_idname) + row.operator(ATTRACT_OT_shot_fetch_update.bl_idname, + text='', icon='FILE_REFRESH') + row.operator(ATTRACT_OT_shot_open_in_browser.bl_idname, + text='', icon='WORLD') + row.operator(ATTRACT_OT_copy_id_to_clipboard.bl_idname, + text='', icon='COPYDOWN') + sub.operator(ATTRACT_OT_make_shot_thumbnail.bl_idname, + text='Render Thumbnail for %s' % noun, + icon='RENDER_STILL') + + # Group more dangerous operations. + dangerous_sub = layout.split(**blender.factor(0.6), align=True) + dangerous_sub.operator('attract.strip_unlink', + text='Unlink %s' % noun, + icon='PANEL_CLOSE') + dangerous_sub.operator(ATTRACT_OT_shot_delete.bl_idname, + text='Delete %s' % noun, + icon='CANCEL') + class AttractOperatorMixin(AttractPollMixin): """Mix-in class for all Attract operators.""" @@ -957,6 +959,7 @@ def deactivate(): _rna_classes = [cls for cls in locals().values() if isinstance(cls, type) and cls.__name__.startswith('ATTRACT')] +log.info('RNA classes:\n%s', '\n'.join([repr(cls) for cls in _rna_classes])) def register():