Viewport Material colour Custom panel problem [GIF and script Included] I was trying to make a custom panel for the settings(which includes the viewport Material colour settings) in the materials tab in the properties windows and I faced this problem. The problem is that I am only able to use the panel for the specific material name that I define. For example in the code I added a specific name "MyMat", and it only work for that specific material. How do I make it work for the current material that is currently assigned to the object regardless of the name. Here's the code and the gif.

Import Bpy
Class MaterialPanel(bpy.types.Panel):
    bl_idname = "mat.p_operator"
    bl_label = "Material panel"
    bl_space_type = "VIEW_3D"
    bl_region_type = "TOOLS"
    bl_category = "Mats"

def draw(self, context):
    layout = self.layout
    row = layout.row()
    mat = bpy.data.materials["MyMat"]
    row.prop(mat, "diffuse_color", text="Diffuse")
    row = layout.row()
    row.prop(mat, "specular_color", text="Specular")

def register():
    bpy.utils.register_class(MaterialPanel)

def unregister():
    bpy.utils.unregister_class(MaterialPanel)

if__name__ == "__main__":
   register()


GIF here, somehow it's not appearing in the post
You can get the active material of the active object like this:

mat = bpy.context.active_object.active_material