Cleanup: remove redundant gpencil material checks
authorCampbell Barton <ideasman42@gmail.com>
Sun, 2 Dec 2018 02:09:15 +0000 (13:09 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 2 Dec 2018 02:12:06 +0000 (13:12 +1100)
Poll checks for an object, no need to check for non-object
materials in the draw function.

release/scripts/startup/bl_ui/properties_material_gpencil.py
release/scripts/startup/bl_ui/space_view3d.py

index 3aba3489a57138c99f037e61585e346946c37c50..fc25b70b36a12fb24650ec0372643e2f012883c8 100644 (file)
@@ -100,54 +100,47 @@ class MATERIAL_PT_gpencil_slots(Panel):
         layout = self.layout
         gpd = context.gpencil_data
 
-        mat = context.object.active_material
         ob = context.object
         slot = context.material_slot
-        space = context.space_data
 
-        if ob:
-            is_sortable = len(ob.material_slots) > 1
-            rows = 7
+        is_sortable = len(ob.material_slots) > 1
+        rows = 7
 
-            row = layout.row()
+        row = layout.row()
 
-            row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
+        row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
 
-            col = row.column(align=True)
-            col.operator("object.material_slot_add", icon='ADD', text="")
-            col.operator("object.material_slot_remove", icon='REMOVE', text="")
+        col = row.column(align=True)
+        col.operator("object.material_slot_add", icon='ADD', text="")
+        col.operator("object.material_slot_remove", icon='REMOVE', text="")
 
-            col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
+        col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
 
-            if is_sortable:
-                col.separator()
+        if is_sortable:
+            col.separator()
 
-                col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
-                col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
+            col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
+            col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 
-                col.separator()
+            col.separator()
 
-                sub = col.column(align=True)
-                sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
-                sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
+            sub = col.column(align=True)
+            sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
+            sub.operator("gpencil.color_isolate", icon='RESTRICT_VIEW_ON', text="").affect_visibility = True
 
         row = layout.row()
 
-        if ob:
-            row.template_ID(ob, "active_material", new="material.new", live_icon=True)
-
-            if slot:
-                icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
-                row.prop(slot, "link", icon=icon_link, icon_only=True)
+        row.template_ID(ob, "active_material", new="material.new", live_icon=True)
 
-            if gpd.use_stroke_edit_mode:
-                row = layout.row(align=True)
-                row.operator("gpencil.stroke_change_color", text="Assign")
-                row.operator("gpencil.color_select", text="Select").deselect = False
-                row.operator("gpencil.color_select", text="Deselect").deselect = True
+        if slot:
+            icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
+            row.prop(slot, "link", icon=icon_link, icon_only=True)
 
-        elif mat:
-            row.template_ID(space, "pin_id")
+        if gpd.use_stroke_edit_mode:
+            row = layout.row(align=True)
+            row.operator("gpencil.stroke_change_color", text="Assign")
+            row.operator("gpencil.color_select", text="Select").deselect = False
+            row.operator("gpencil.color_select", text="Deselect").deselect = True
 
 
 # Used as parent for "Stroke" and "Fill" panels
index 383f1938cd2fd0772347d299df654cf903515abc..affd6fedb0f8567fc1108ebb8de946fb5b607a84 100644 (file)
@@ -189,7 +189,7 @@ class VIEW3D_HT_header(Header):
                 sub = row.row(align=True)
                 sub.active = tool_settings.use_proportional_edit_objects
                 sub.prop(tool_settings, "proportional_edit_falloff", icon_only=True)
-                
+
             elif gpd is not None and obj.type == 'GPENCIL':
                 if gpd.use_stroke_edit_mode or gpd.is_stroke_sculpt_mode:
                     row = layout.row(align=True)
@@ -5397,30 +5397,29 @@ class TOPBAR_PT_gpencil_materials(Panel):
         layout = self.layout
         ob = context.object
 
-        if ob:
-            is_sortable = len(ob.material_slots) > 1
-            rows = 1
-            if (is_sortable):
-                rows = 10
+        is_sortable = len(ob.material_slots) > 1
+        rows = 1
+        if (is_sortable):
+            rows = 10
 
-            row = layout.row()
+        row = layout.row()
 
-            row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
+        row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
 
-            col = row.column(align=True)
-            col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
+        col = row.column(align=True)
+        col.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
 
-            if is_sortable:
-                col.separator()
+        if is_sortable:
+            col.separator()
 
-                col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
-                col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
+            col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
+            col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
 
-                col.separator()
+            col.separator()
 
-                sub = col.column(align=True)
-                sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
-                sub.operator("gpencil.color_isolate", icon='HIDE_OFF', text="").affect_visibility = True
+            sub = col.column(align=True)
+            sub.operator("gpencil.color_isolate", icon='LOCKED', text="").affect_visibility = False
+            sub.operator("gpencil.color_isolate", icon='HIDE_OFF', text="").affect_visibility = True
 
 
 classes = (