Simple popup windows, the usual “Cancel/OK” stuff.
import bpy
class FOO_Panel(bpy.types.Panel):
bl_label = "FOO"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS'
def draw(self, context):
layout = self.layout
column = layout.column(align=True)
column.operator("popup.message")
class PopupOP(bpy.types.Operator):
bl_idname = "popup.message"
bl_label = "Simple Popup"
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_popup(self,width=200, height=100)
def draw(self,contest):
self.layout.label("Popup Message")
row = self.layout.split(0.5)
row.operator("render.ok")
row.operator("render.cancel")
class OkOP(bpy.types.Operator):
bl_idname = "render.ok"
bl_label = "OK"
def execute(self, contest):
return {'FINISHED'}
class CancelOP(bpy.types.Operator):
bl_idname = "render.cancel"
bl_label = "Cancel"
def execute(self, contest):
return {'FINISHED'}
classes = [
FOO_Panel,
PopupOP,
OkOP,
CancelOP
]
def register():
for c in classes:
bpy.utils.register_class(c)
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'TOOLS':
region.tag_redraw()
def unregister():
for c in classes:
bpy.utils.unregister_class(c)
if __name__ == "__main__":
register()
The problem is, I’d like the popup to close if you either click “cancel” or “ok”.
Can this even be done? The API docu hasn’t made me any smarter - unfortunately.