Cleanup: de-duplicate gpencil material UI
authorCampbell Barton <ideasman42@gmail.com>
Sun, 2 Dec 2018 02:26:10 +0000 (13:26 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 2 Dec 2018 02:26:39 +0000 (13:26 +1100)
Top-bar and properties-editor were near duplicates.

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

index ff294e7d922c1423dd2c4902050bd7670a8a5c67..eed78ff26ad17feb4590e147f49bea2c9d494d22 100644 (file)
@@ -902,6 +902,66 @@ class GreasePencilToolsPanel:
         gpencil_stroke_placement_settings(context, layout)
 
 
+class GreasePencilMaterialsPanel:
+    # Mix-in, use for properties editor and top-bar.
+
+    @classmethod
+    def poll(cls, context):
+        ob = context.object
+        return ob and ob.type == 'GPENCIL'
+
+    @staticmethod
+    def draw(self, context):
+        layout = self.layout
+        show_full_ui = (self.bl_space_type == 'PROPERTIES')
+
+        gpd = context.gpencil_data
+
+        ob = context.object
+
+        is_sortable = len(ob.material_slots) > 1
+        rows = 7
+
+        row = layout.row()
+
+        row.template_list("GPENCIL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
+
+        col = row.column(align=True)
+        if show_full_ui:
+            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="")
+
+        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.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
+
+        if show_full_ui:
+            row = layout.row()
+
+            row.template_ID(ob, "active_material", new="material.new", live_icon=True)
+
+            slot = context.material_slot
+            if slot:
+                icon_link = 'MESH_DATA' if slot.link == 'DATA' else 'OBJECT_DATA'
+                row.prop(slot, "link", icon=icon_link, icon_only=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
+
+
 class GPENCIL_UL_layer(UIList):
     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
         # assert(isinstance(item, bpy.types.GPencilLayer)
index fc25b70b36a12fb24650ec0372643e2f012883c8..b62b251163e2463c071473f23a083ee0888f03ae 100644 (file)
@@ -22,6 +22,10 @@ from bpy.types import Menu, Panel, UIList
 from rna_prop_ui import PropertyPanel
 from bl_operators.presets import PresetMenu
 
+from .properties_grease_pencil_common import (
+    GreasePencilMaterialsPanel,
+)
+
 
 class GPENCIL_MT_color_specials(Menu):
     bl_label = "Layer"
@@ -83,65 +87,13 @@ class GPMaterialButtonsPanel:
                 ob.active_material.grease_pencil)
 
 
-class MATERIAL_PT_gpencil_slots(Panel):
+class MATERIAL_PT_gpencil_slots(GreasePencilMaterialsPanel, Panel):
     bl_label = "Grease Pencil Material Slots"
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
     bl_context = "material"
     bl_options = {'HIDE_HEADER'}
 
-    @classmethod
-    def poll(cls, context):
-        ob = context.object
-        return ob and ob.type == 'GPENCIL'
-
-    @staticmethod
-    def draw(self, context):
-        layout = self.layout
-        gpd = context.gpencil_data
-
-        ob = context.object
-        slot = context.material_slot
-
-        is_sortable = len(ob.material_slots) > 1
-        rows = 7
-
-        row = layout.row()
-
-        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.menu("GPENCIL_MT_color_specials", icon='DOWNARROW_HLT', text="")
-
-        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.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
-
-        row = layout.row()
-
-        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)
-
-        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
 class MATERIAL_PT_gpencil_surface(GPMaterialButtonsPanel, Panel):
index affd6fedb0f8567fc1108ebb8de946fb5b607a84..7f4c9f2028302d9948dd56cd8dbc7d5c87b0c512 100644 (file)
 
 # <pep8 compliant>
 import bpy
-from bpy.types import Header, Menu, Panel
-from .properties_paint_common import UnifiedPaintPanel
-from .properties_grease_pencil_common import AnnotationDataPanel, AnnotationOnionSkin
+from bpy.types import (
+    Header,
+    Menu,
+    Panel,
+)
+from .properties_paint_common import (
+    UnifiedPaintPanel,
+)
+from .properties_grease_pencil_common import (
+    AnnotationDataPanel,
+    AnnotationOnionSkin,
+    GreasePencilMaterialsPanel,
+)
 from bpy.app.translations import contexts as i18n_contexts
 
 
@@ -5381,46 +5391,12 @@ class VIEW3D_MT_gpencil_sculpt_specials(Menu):
             layout.menu("VIEW3D_MT_gpencil_autoweights")
 
 
-class TOPBAR_PT_gpencil_materials(Panel):
+class TOPBAR_PT_gpencil_materials(GreasePencilMaterialsPanel, Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'HEADER'
     bl_label = "Materials"
     bl_ui_units_x = 14
 
-    @classmethod
-    def poll(cls, context):
-        ob = context.object
-        return ob and ob.type == 'GPENCIL'
-
-    @staticmethod
-    def draw(self, context):
-        layout = self.layout
-        ob = context.object
-
-        is_sortable = len(ob.material_slots) > 1
-        rows = 1
-        if (is_sortable):
-            rows = 10
-
-        row = layout.row()
-
-        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="")
-
-        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.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
-
 
 classes = (
     VIEW3D_HT_header,