Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-03-28 17:53:53 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-03-28 17:53:53 +0400
commitd766111632014f346827ccd15a6741b3e898842e (patch)
tree5d509917f04804690d2aa66270cbfc2659f56929 /release/scripts/templates
parentbf1e2ce41ebf3dab1647d28588f951b5e587aa3e (diff)
example operator that uses a timer.
Diffstat (limited to 'release/scripts/templates')
-rw-r--r--release/scripts/templates/operator_modal_timer.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/release/scripts/templates/operator_modal_timer.py b/release/scripts/templates/operator_modal_timer.py
new file mode 100644
index 00000000000..d8c218f67ea
--- /dev/null
+++ b/release/scripts/templates/operator_modal_timer.py
@@ -0,0 +1,46 @@
+import bpy
+from bpy.props import IntProperty, FloatProperty
+
+
+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()
+
+ 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()