Bug in addon to change header color dynamically
I made an add-on that changes the theme color of the header if the automatic keyframe feature is enabled.
The color change function works fine.
However, the following bug occurs in the object gizmo transform gizmo.
- Mouse hovers no longer highlight
- Drag operation is delayed a little
Why do bugs occur in Gizmo by changing the theme color? I have no idea.
python
import bpy
bl_info = {
"name" : "header_color_change",
"author" : "Bookyakuno",
"version" : (1, 0, 0),
"blender" : (2, 80, 0),
"location" : "hoge",
"description" : "hoge",
"category" : "UI"
}
def TEST_HT_header_color_change(self, context):
layout = self.layout
layout.label(text="")
if bpy.context.scene.tool_settings.use_keyframe_insert_auto == True:
bpy.context.preferences.themes[0].topbar.space.header = (0.4, 0.000000, 0.000000, 1.000000)
else:
bpy.context.preferences.themes[0].topbar.space.header = (0.137255, 0.137255, 0.137255, 1.000000)
return {'FINISHED'}
def register():
bpy.types.TOPBAR_HT_upper_bar.append(TEST_HT_header_color_change)
def unregister():
bpy.types.TOPBAR_HT_upper_bar.remove(TEST_HT_header_color_change)
if __name__ == "__main__":
register()
'''

The code attached to the reference fixed the Gizmo bug, but it didn't load at Blender startup and it didn't work (it will work if you reload the add-on itself every time). Therefore, I improved it to read by "load_post" using "persistent", This method is loaded at boot time.
Thank you for teaching me the handler. header_color_change.py - github
– Bookyakuno Jun 07 '19 at 14:26