Skip to content

Instantly share code, notes, and snippets.

@vfig
Last active September 18, 2022 14:08
Show Gist options
  • Save vfig/63f6c08c0a6398b0c41483eacc7e6123 to your computer and use it in GitHub Desktop.
Save vfig/63f6c08c0a6398b0c41483eacc7e6123 to your computer and use it in GitHub Desktop.
Blender: show current mode with status bar colors
bl_info = {
"name": "Status Bar Mode Color",
"author": "Dspazio / vfig",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "View3D",
"description": "Changes background gradient color for each mode.",
"warning": "",
"doc_url": "",
"category": "Themes",
}
import bpy
from bpy.app.handlers import persistent
# nice green: 33b061
COLORS_BY_MODE = {
# mode header text highlight
'default': ('000080', '00cccc', '00ffff'),
'OBJECT': ('303030', 'cccccc', 'ffffff'),
'EDIT': ('ff9e00', '101010', '000000'),
'POSE': ('ff0080', '101010', '000000'),
'SCULPT': ('59e5ff', '101010', '000000'),
'VERTEX_PAINT': ('9400d3', 'eeeeee', 'ffffff'),
'WEIGHT_PAINT': ('ffffff', '101010', '000000'),
'TEXTURE_PAINT': ('008080', 'eeeeee', 'ffffff'),
}
def srgb_to_linearrgb(c):
if c < 0: return 0
elif c < 0.04045: return c/12.92
else: return ((c+0.055)/1.055)**2.4
def hex_to_rgb(h):
if isinstance(h, str):
if h.startswith('#'):
h = h[1:]
h = int(h, 16)
r = (h & 0xff0000) >> 16
g = (h & 0x00ff00) >> 8
b = (h & 0x0000ff)
return tuple([srgb_to_linearrgb(c/0xff) for c in (r,g,b)])
def hex_to_rgba(h,alpha=1):
if isinstance(h, str):
if h.startswith('#'):
h = h[1:]
h = int(h, 16)
r = (h & 0xff0000) >> 16
g = (h & 0x00ff00) >> 8
b = (h & 0x0000ff)
return tuple([srgb_to_linearrgb(c/0xff) for c in (r,g,b)] + [alpha])
@persistent
def set_status_bar_color(scene):
obj = bpy.context.active_object
if obj:
color_hex = COLORS_BY_MODE.get(obj.mode, COLORS_BY_MODE['default'])
statusbar = bpy.context.preferences.themes[0].statusbar.space
statusbar.header = hex_to_rgba(color_hex[0])
statusbar.header_text = hex_to_rgb(color_hex[1])
statusbar.header_text_hi = hex_to_rgb(color_hex[2])
def register():
bpy.app.handlers.depsgraph_update_post.append(set_status_bar_color)
def unregister():
bpy.app.handlers.depsgraph_update_post.remove(set_status_bar_color)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment