* Fix small bug in Python operator example; improved example of modal operator

This commit is contained in:
Jiri Hnidek 2012-10-12 18:19:39 +00:00
parent 1958fda91f
commit 13d829e57d
2 changed files with 5 additions and 3 deletions

@ -26,8 +26,8 @@ class CustomDrawOperator(bpy.types.Operator):
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
wm = context.window_manager
return wm.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout

@ -40,15 +40,17 @@ class ModalOperator(bpy.types.Operator):
elif event.type == 'LEFTMOUSE': # Confirm
return {'FINISHED'}
elif event.type in ('RIGHTMOUSE', 'ESC'): # Cancel
context.object.location.x = self.init_loc_x
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
self.init_loc_x = context.object.location.x
self.value = event.mouse_x
self.execute(context)
print(context.window_manager.modal_handler_add(self))
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}