[Bf-blender-cvs] [7be9bf43a48] blender2.8: Cleanup: de-duplicate gpencil material UI

Campbell Barton noreply at git.blender.org
Sun Dec 2 03:27:21 CET 2018


Commit: 7be9bf43a4854e085ba828cc5682a739a52163a6
Author: Campbell Barton
Date:   Sun Dec 2 13:26:10 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB7be9bf43a4854e085ba828cc5682a739a52163a6

Cleanup: de-duplicate gpencil material UI

Top-bar and properties-editor were near duplicates.

===================================================================

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

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
index ff294e7d922..eed78ff26ad 100644
--- a/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
+++ b/release/scripts/startup/bl_ui/properties_grease_pencil_common.py
@@ -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)
diff --git a/release/scripts/startup/bl_ui/properties_material_gpencil.py b/release/scripts/startup/bl_ui/properties_material_gpencil.py
index fc25b70b36a..b62b251163e 100644
--- a/release/scripts/startup/bl_ui/properties_material_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_material_gpencil.py
@@ -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):
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index affd6fedb0f..7f4c9f20283 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -18,9 +18,19 @@
 
 # <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,



More information about the Bf-blender-cvs mailing list