blob: ec47390da81f079dde40b9589ae183606c03242e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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 == 'ESC':
return self.cancel(context)
if event.type == 'TIMER':
# change theme color, silly!
color = context.user_preferences.themes[0].view_3d.back
color.s = 1.0
color.h += 0.01
return {'PASS_THROUGH'}
def execute(self, context):
context.window_manager.modal_handler_add(self)
self._timer = context.window_manager.event_timer_add(0.1, context.window)
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()
|