* Fix small bug in Python operator example; improved example of modal operator
This commit is contained in:
@@ -26,8 +26,8 @@ class CustomDrawOperator(bpy.types.Operator):
|
|||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
context.window_manager.fileselect_add(self)
|
wm = context.window_manager
|
||||||
return {'RUNNING_MODAL'}
|
return wm.invoke_props_dialog(self)
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
|
@@ -40,15 +40,17 @@ class ModalOperator(bpy.types.Operator):
|
|||||||
elif event.type == 'LEFTMOUSE': # Confirm
|
elif event.type == 'LEFTMOUSE': # Confirm
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
elif event.type in ('RIGHTMOUSE', 'ESC'): # Cancel
|
elif event.type in ('RIGHTMOUSE', 'ESC'): # Cancel
|
||||||
|
context.object.location.x = self.init_loc_x
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
|
self.init_loc_x = context.object.location.x
|
||||||
self.value = event.mouse_x
|
self.value = event.mouse_x
|
||||||
self.execute(context)
|
self.execute(context)
|
||||||
|
|
||||||
print(context.window_manager.modal_handler_add(self))
|
context.window_manager.modal_handler_add(self)
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user