blender/release/scripts/templates_py/operator_modal_timer.py

46 lines
1.1 KiB
Python
Raw Normal View History

2011-03-28 13:53:53 +00:00
import bpy
class ModalTimerOperator(bpy.types.Operator):
"""Operator which runs its self from a timer"""
2011-03-28 13:53:53 +00:00
bl_idname = "wm.modal_timer_operator"
bl_label = "Modal Timer Operator"
_timer = None
def modal(self, context, event):
if event.type == 'ESC':
2011-08-10 09:30:45 +00:00
return self.cancel(context)
2011-03-28 13:53:53 +00:00
if event.type == 'TIMER':
# change theme color, silly!
color = context.user_preferences.themes[0].view_3d.space.back
2011-03-28 13:53:53 +00:00
color.s = 1.0
color.h += 0.01
return {'PASS_THROUGH'}
def execute(self, context):
self._timer = context.window_manager.event_timer_add(0.1, context.window)
context.window_manager.modal_handler_add(self)
2011-03-28 13:53:53 +00:00
return {'RUNNING_MODAL'}
def cancel(self, context):
context.window_manager.event_timer_remove(self._timer)
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalTimerOperator)
def unregister():
bpy.utils.unregister_class(ModalTimerOperator)
if __name__ == "__main__":
register()
# test call
bpy.ops.wm.modal_timer_operator()