123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import bpy
- class ModalTimerOperator(bpy.types.Operator):
- """Operator which runs its self from a timer"""
- bl_idname = "wm.modal_timer_operator"
- bl_label = "Modal Timer Operator"
- _timer = None
- def modal(self, context, event):
- if event.type in {'RIGHTMOUSE', 'ESC'}:
- self.cancel(context)
- return {'CANCELLED'}
- if event.type == 'TIMER':
- # change theme color, silly!
- color = context.preferences.themes[0].view_3d.space.gradients.high_gradient
- color.s = 1.0
- color.h += 0.01
- return {'PASS_THROUGH'}
- def execute(self, context):
- wm = context.window_manager
- self._timer = wm.event_timer_add(0.1, window=context.window)
- wm.modal_handler_add(self)
- return {'RUNNING_MODAL'}
- def cancel(self, context):
- wm = context.window_manager
- wm.event_timer_remove(self._timer)
- 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()
|