I've taken the "Operator Modal Draw" template example and edited it. I wanted to see if I could pass the modal "event" through "args" in the draw_handler_add function. It works and the draw_callback_px function updates and draws the event type every time I press a key or do something with the mouse except for when I move the mouse (never prints "MOUSEMOVE" like it would if I were printing "event.type" directly within the modal function).
Anyone know why this is? Would be great If I could pass "event" entirely through to the draw_callback_px (not that I would want to run it every time the mouse moved, I'd control it with a conditional, but would like to have full power of the modal event within my bgl,blf drawing). My knowledge is pretty limited about the draw_handler and callbacks.
import bpy
import bgl
import blf
def draw_callback_px(self, contex, event):
font_id = 0
blf.position(font_id, 15, 30, 0)
blf.size(font_id, 20, 72)
blf.draw(font_id, event.type)
class ModalDrawOperator(bpy.types.Operator):
"""Draw a line with the mouse"""
bl_idname = "view3d.modal_operator"
bl_label = "Simple Modal View3D Operator"
def modal(self, context, event):
context.area.tag_redraw()
if event.type in {'ESC'}:
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
# the arguments we pass the the callback
args = (self, context, event)
# Add the region OpenGL drawing callback
# draw in view space with 'POST_VIEW' and 'PRE_VIEW'
self._handle = bpy.types.SpaceView3D.draw_handler_add(
draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
def register():
bpy.utils.register_class(ModalDrawOperator)
def unregister():
bpy.utils.unregister_class(ModalDrawOperator)
if __name__ == "__main__":
register()