2011-03-28 13:53:53 +00:00
|
|
|
import bpy
|
|
|
|
|
|
|
|
|
|
|
|
class ModalTimerOperator(bpy.types.Operator):
|
2012-07-01 07:55:44 +00:00
|
|
|
"""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):
|
2013-10-22 00:25:15 +00:00
|
|
|
if event.type in {'RIGHTMOUSE', '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!
|
2013-02-23 12:55:19 +00:00
|
|
|
color = context.user_preferences.themes[0].view_3d.space.gradients.high_gradient
|
2011-03-28 13:53:53 +00:00
|
|
|
color.s = 1.0
|
|
|
|
color.h += 0.01
|
|
|
|
|
|
|
|
return {'PASS_THROUGH'}
|
|
|
|
|
|
|
|
def execute(self, context):
|
2013-10-22 00:25:15 +00:00
|
|
|
wm = context.window_manager
|
|
|
|
self._timer = wm.event_timer_add(0.1, context.window)
|
|
|
|
wm.modal_handler_add(self)
|
2011-03-28 13:53:53 +00:00
|
|
|
return {'RUNNING_MODAL'}
|
|
|
|
|
|
|
|
def cancel(self, context):
|
2013-10-22 00:25:15 +00:00
|
|
|
wm = context.window_manager
|
|
|
|
wm.event_timer_remove(self._timer)
|
2011-03-28 13:53:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|