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>2012-12-30 05:39:55 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-12-30 05:39:55 +0400
commit33955940e4931e2184434393e0f8c15c36a5c3c6 (patch)
tree7b3c10343162a256e85ff4346f57122032715e82 /release/scripts/templates_py/operator_modal.py
parente12354c4c5850864f925d22f53ec31578384bc63 (diff)
add templates menu for OSL, use preprocessor directive color for decorators in python.
Diffstat (limited to 'release/scripts/templates_py/operator_modal.py')
-rw-r--r--release/scripts/templates_py/operator_modal.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/release/scripts/templates_py/operator_modal.py b/release/scripts/templates_py/operator_modal.py
new file mode 100644
index 00000000000..88e5ee80590
--- /dev/null
+++ b/release/scripts/templates_py/operator_modal.py
@@ -0,0 +1,51 @@
+import bpy
+from bpy.props import IntProperty, FloatProperty
+
+
+class ModalOperator(bpy.types.Operator):
+ """Move an object with the mouse, example"""
+ bl_idname = "object.modal_operator"
+ bl_label = "Simple Modal Operator"
+
+ first_mouse_x = IntProperty()
+ first_value = FloatProperty()
+
+ def modal(self, context, event):
+ if event.type == 'MOUSEMOVE':
+ delta = self.first_mouse_x - event.mouse_x
+ context.object.location.x = self.first_value + delta * 0.01
+
+ elif event.type == 'LEFTMOUSE':
+ return {'FINISHED'}
+
+ elif event.type in {'RIGHTMOUSE', 'ESC'}:
+ context.object.location.x = self.first_value
+ return {'CANCELLED'}
+
+ return {'RUNNING_MODAL'}
+
+ def invoke(self, context, event):
+ if context.object:
+ self.first_mouse_x = event.mouse_x
+ self.first_value = context.object.location.x
+
+ context.window_manager.modal_handler_add(self)
+ return {'RUNNING_MODAL'}
+ else:
+ self.report({'WARNING'}, "No active object, could not finish")
+ return {'CANCELLED'}
+
+
+def register():
+ bpy.utils.register_class(ModalOperator)
+
+
+def unregister():
+ bpy.utils.unregister_class(ModalOperator)
+
+
+if __name__ == "__main__":
+ register()
+
+ # test call
+ bpy.ops.object.modal_operator('INVOKE_DEFAULT')