Script to manage lots of handlers and delete/re-order them.

Hi guys

I am working on an addon that makes use of handlers with there execution order being important, it was becoming a nightmare to visualize and debug all the handlers so I created this script to visualize them:

I am still learning Python so if you have any advice it would be welcomed, anyway hope this helps someone.

import bpy

class MoveH(bpy.types.Operator):
    """Move this handler"""
    bl_idname = "scene.move_handler"
    bl_label = "Move this Handler"
    
    handle = bpy.props.IntProperty(default=0)
    target = bpy.props.IntProperty(default=0)
    move = bpy.props.IntProperty(default=0)

    def execute(self, context):
        t = bpy.app.handlers[self.handle].pop(self.target)
        if self.move <= 0:
            self.move = 0
        bpy.app.handlers[self.handle].insert(self.move,t)        
        return {'FINISHED'}

class RemH(bpy.types.Operator):
    """Remove this handler"""
    bl_idname = "scene.remove_handler"
    bl_label = "Remove this Handler"
    
    handle = bpy.props.IntProperty(default=0)
    target = bpy.props.IntProperty(default=0)

    def execute(self, context):
        bpy.app.handlers[self.handle].pop(self.target)
        return {'FINISHED'}

class HandlerManager(bpy.types.Panel):
    """A Handler Manager"""
    bl_label = "Handler Manager"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"
    
    #16 lists all the handlers in order
    hl = ["frame_change_pre","frame_change_post","render_pre","render_post","render_stats","render_complete","render_cancel","load_pre","load_post","save_pre","save_post","scene_update_pre","scene_update_post","game_pre","game_post","persistent"]
    
    def draw(self, context):
        
        ih = 0
        layout = self.layout
        error = True
        for t in bpy.app.handlers:
            if t != [] and ih < 15:
                row = layout.row(align=True)
                row.label(text=self.hl[ih], icon="SCRIPTPLUGINS")
                error = False 
                l = bpy.app.handlers[ih]
                i = 0
                
                for h in l:
                    row = layout.row(align=True)
                    box = row.box()
                    row = box.row() 
                    h = str(h)
                    name = h[h.find(" ")+1:]
                    name = name[:name.find(" ")]
                    row.label(text=name, icon="SCRIPTWIN")
                    sub = row.row()
                    if i == 0:
                        sub.enabled = False
                    op = sub.operator("scene.move_handler", text="", icon="TRIA_UP")
                    op.target=i
                    op.handle=ih
                    op.move = -1
                    sub = row.row()
                    if i == len(l)-1:
                        sub.enabled = False
                    op = sub.operator("scene.move_handler", text="", icon="TRIA_DOWN")
                    op.target=i
                    op.handle=ih
                    op.move = 1
                    op = row.operator("scene.remove_handler", text="", icon="X")
                    op.target=i
                    op.handle=ih
                    i += 1
            ih += 1
        
        if error == True:
            row = layout.row(align=True)
            row.label(text="No Active Handlers", icon="ERROR")               
    
def register():
    bpy.utils.register_class(HandlerManager)
    bpy.utils.register_class(RemH)
    bpy.utils.register_class(MoveH)
    
def unregister():
    bpy.utils.unregister_class(HandlerManager) 
    bpy.utils.unregister_class(RemH)
    bpy.utils.unregister_class(MoveH) 
    
if __name__ == "__main__":
    register()

Just fixed an error that would only allow you to delete/reorder a handler if you had a bone selected in pose mode.

The arrows are now greyed out if its at the top or bottom of the list, I left them in because otherwise it confuses me when they move about.

Hey this is pretty cool!