When you are texture painting in Blender, if you want to change the layer order you have to change the order of the texture slots, and if you want to select which layer to draw on you have to change the active paint slot, in a completely different place. I find this leads to accidental mistakes, for me at least, like selecting a specific texture slot and thinking you are drawing on that layer.
I'm thinking of writing an addon to sync the two. Such that if you select a specific texture slot, the active paint slot will update to the same index. To do this I can just write:
bpy.context.object.active_material.paint_active_slot = bpy.context.object.active_material.active_texture_index
However I don't know if to run this at a specific interval? Or if Blender allows to run a code on each OpenGL render update? Or if I can get this code triggered in some way? I appreciate any suggestions.