# Reset Active Operator

I want to write a Handler that runs code only when the user stops translating an object, using bpy.ops.transform.translate (the 'G' key). So while the user is sliding the mouse around, nothing should happen besides the object being translated. But when they exit the modal operator (by left-clicking or pressing 'enter'), my code should run.

My approach:

@bpy.app.handlers.persistent
def detect_change(scene):
op = bpy.context.active_operator
opname = op.bl_idname.replace("_OT_", ".").lower() if op else ''

# On entering translate mode, start checking for exit
if opname == "transform.translate":
waiting = True # This will be some sort of persistent variable.
return

# If not in translate mode, then run code
elif waiting:
my_function()
waiting = False


The only problem is that after exiting the translate modal operator, the active_operator remains at transform.translate. It doesn't switch until another operator is called.
Any way to either force the operator to update to None or to detect exiting the modal operator?
• So the idea would be to call the macro instead of directly invoking transform.translate? A bit inconvenient for the user to have to remember, but I see how that could work. – supergra Jul 17 '14 at 21:50
• Oh weird. In that case, I'll hold out. I wonder if there's room for post_operator and pre_operator Handlers? (I know they don't exist, just wondering if it would be useful addition). – supergra Jul 17 '14 at 22:02