I have managed to use some code I found written for 2.5x that works somewhat to display a window with a message and an OK button, but it seems less than obvious how I might setup an event.
I've got an operator which I want to, before it begins it's real work, show a message warning the user that it may take the script several minutes to complete its' work, but to be patient even though the UI seems unresponsive. I want the user to be able to say "OK" or "Cancel".
OK->addon script continues to run and returns {'FINISHED'}
Cancel->addon script aborts and returns {'CANCELED'}
Code: Select all
class MessageOperator(bpy.types.Operator):
bl_idname = "dialog.message"
bl_label = "Message"
type = StringProperty()
message = StringProperty()
def execute(self, context):
self.report({'INFO'}, self.message)
print(self.message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_popup(self, width=800, height=300)
def draw(self, context):
self.layout.label("Preparing to export...")
row=self.layout.split(0.25)
row.prop(self, "message")
row = self.layout.split(0.80)
row.label("")
row.operator("dialog.ok")
class OkOperator(bpy.types.Operator):
bl_idname="dialog.ok"
bl_label="OK"
def execute(self, context):
return{'FINISHED'}
class CancelOperator(bpy.types.Operator):
bl_idname="dialog.cancel"
bl_label="Cancel"
def execute(self,context):
return{'CANCELED'}
bpy.utils.register_class(CancelOperator)
bpy.utils.register_class(OkOperator)
bpy.utils.register_class(MessageOperator)
How can I make the dialog block until a button is pressed?