13

I want to be able to change the background color of a property ui.

At the moment it does:

  • Green = has an Fcurve
  • Yellow = has a keyframe
  • Purple = has a Driver

I want to to be able to change the color of the background depending my own conditions. IE I don't want to change the color theme, I want to add a new color and define its condition.

For Example: If a property is above 500 it changes to red!

Is this possible?

MCHammond
  • 451
  • 5
  • 16

1 Answers1

19

The colors are controlled by C code, you can't set it to arbitrary colors with python.

However, you can change the background to alert color (=red) by setting the alert property on the layout block:

Panel - layout alert state

Blender 2.8+

import bpy

class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object"

def draw(self, context):
    layout = self.layout

    obj = context.object
    if obj is None: return

    col = layout.column()
    col.alert = True
    col.label(text="Alert state NOT supported:")

    box = col.box()
    box.label(text="Labels", icon="X")
    box.menu("VIEW3D_MT_object", text="Menus")

    col.separator()
    col.label(text="Supported:")
    box = col.box()
    box.operator("mesh.primitive_cube_add", text="Operators (Buttons)")
    box.prop(obj, "name", text="Many properties")
    box.prop(obj, "location", index=1, text="Vector props: only single")
    box.label(text="also with emboss=False, but...")
    box.prop(obj, "name", text="read-only?!", emboss=False)
    box.label(text="template_list() sort of (needs materials):")
    box.template_list("UI_UL_list", "foobar", obj.data, "materials", obj, "active_material_index")

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

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

if name == "main": register()

Blender 2.7x

import bpy

class HelloWorldPanel(bpy.types.Panel): """Creates a Panel in the Object properties window""" bl_label = "Hello World Panel" bl_idname = "OBJECT_PT_hello" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "object"

def draw(self, context):
    layout = self.layout

    obj = context.object
    if obj is None: return

    col = layout.column()
    col.alert = True
    col.label("Alert state NOT supported:")

    box = col.box()
    box.label("Labels", icon="X")
    box.menu("VIEW3D_MT_object", text="Menus")
    box.prop(obj, "layers", text="Not all properties")

    col.separator()
    col.label("Supported:")
    box = col.box()
    box.operator("mesh.primitive_cube_add", text="Operators (Buttons)")
    box.prop(obj, "name", text="Many properties")
    box.prop(obj, "location", index=1, text="Vector props: only single")
    box.label("also with emboss=False, but...")
    box.prop(obj, "name", text="read-only?!", emboss=False)
    box.label("template_list() sort of (needs materials):")
    box.template_list("UI_UL_list", "foobar", obj.data, "materials", obj, "active_material_index")

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

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

if name == "main": register()

Run the above code in Text Editor and check out the Object tab.

brockmann
  • 12,613
  • 4
  • 50
  • 93
CodeManX
  • 29,298
  • 3
  • 89
  • 128