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>2010-02-21 19:20:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-02-21 19:20:32 +0300
commitd85191bd2d8c8c87379b897c269b6a597545d90e (patch)
treecb2c12bdc17b297caab1da088bcd69477595012b /release/scripts/templates/operator_modal.py
parenteb0bf10c9ccdf4088d624a141c762ab2c4b8c03f (diff)
modal operator python template
Diffstat (limited to 'release/scripts/templates/operator_modal.py')
-rw-r--r--release/scripts/templates/operator_modal.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/release/scripts/templates/operator_modal.py b/release/scripts/templates/operator_modal.py
new file mode 100644
index 00000000000..ff3863ff59a
--- /dev/null
+++ b/release/scripts/templates/operator_modal.py
@@ -0,0 +1,39 @@
+from bpy.props import *
+
+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.properties.first_mouse_x - event.mouse_x
+ context.object.location.x = self.properties.first_value + delta * 0.01
+
+ elif event.type == 'LEFTMOUSE':
+ return {'FINISHED'}
+
+ elif event.type in ('RIGHTMOUSE', 'ESCAPE'):
+ context.object.location.x = self.properties.first_value
+ return {'CANCELLED'}
+
+ return {'RUNNING_MODAL'}
+
+ def invoke(self, context, event):
+ if context.object:
+ context.manager.add_modal_handler(self)
+ self.properties.first_mouse_x = event.mouse_x
+ self.properties.first_value = context.object.location.x
+ return {'RUNNING_MODAL'}
+ else:
+ self.report({'WARNING'}, "No active object, could not finish")
+ return {'CANCELLED'}
+
+
+bpy.types.register(ModalOperator)
+
+if __name__ == "__main__":
+ bpy.ops.object.modal_operator() \ No newline at end of file