I want to make sure that the user acknowledges the selection of a checkbox. What am I missing?
import bpy
from bpy.types import PropertyGroup
def my_boolean_handler(self, context):
#context.window_manager.invoke_popup(self) # error self should be an operator
bpy.ops.my_category.custom_confirm_dialog() # prints Info: YES! because executed not invoked
class MySettings(PropertyGroup):
my_boolean : bpy.props.BoolProperty(
name = "My Boolean",
description = "This checkbox triggers a Dialog Box",
default = False,
update = my_boolean_handler
)
class SimpleConfirmOperator(bpy.types.Operator):
"""Really?"""
bl_idname = "my_category.custom_confirm_dialog"
bl_label = "Do you really want to do that?"
bl_options = {'REGISTER', 'INTERNAL'}
@classmethod
def poll(cls, context):
return True
def execute(self, context):
self.report({'INFO'}, "YES!")
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_confirm(self, event)
class OBJECT_PT_CustomPanel(bpy.types.Panel):
bl_label = "My Panel"
bl_idname = "OBJECT_PT_custom_panel"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "Tools"
bl_context = "objectmode"
def draw(self, context):
settings = context.scene.world.my_settings
layout = self.layout
layout.prop(settings, 'my_boolean')
def register():
bpy.utils.register_class(OBJECT_PT_CustomPanel)
bpy.utils.register_class(SimpleConfirmOperator)
bpy.utils.register_class(MySettings)
bpy.types.World.my_settings = bpy.props.PointerProperty(type=MySettings)
def unregister():
del bpy.types.World.my_settings
bpy.utils.unregister_class(SimpleConfirmOperator)
bpy.utils.unregister_class(OBJECT_PT_CustomPanel)
if __name__ == "__main__":
register()
I saw 2 StackExchange questions pointing in the right direction, but couldn't get it working with the checkbox.