remove return argument from wmOperatorType->cancel, was only ever returning OPERATOR_...
[blender.git] / release / scripts / templates_py / operator_modal_timer.py
1 import bpy
2
3
4 class ModalTimerOperator(bpy.types.Operator):
5     """Operator which runs its self from a timer"""
6     bl_idname = "wm.modal_timer_operator"
7     bl_label = "Modal Timer Operator"
8
9     _timer = None
10
11     def modal(self, context, event):
12         if event.type in {'RIGHTMOUSE', 'ESC'}:
13             return self.cancel(context)
14
15         if event.type == 'TIMER':
16             # change theme color, silly!
17             color = context.user_preferences.themes[0].view_3d.space.gradients.high_gradient
18             color.s = 1.0
19             color.h += 0.01
20
21         return {'PASS_THROUGH'}
22
23     def execute(self, context):
24         wm = context.window_manager
25         self._timer = wm.event_timer_add(0.1, context.window)
26         wm.modal_handler_add(self)
27         return {'RUNNING_MODAL'}
28
29     def cancel(self, context):
30         wm = context.window_manager
31         wm.event_timer_remove(self._timer)
32
33
34 def register():
35     bpy.utils.register_class(ModalTimerOperator)
36
37
38 def unregister():
39     bpy.utils.unregister_class(ModalTimerOperator)
40
41
42 if __name__ == "__main__":
43     register()
44
45     # test call
46     bpy.ops.wm.modal_timer_operator()