Reputation: 69
I'm new in blender addon development and trying to create a popup dialog box that doesn't close when I click outside the box, It should only close when I click on the close button.
please let me know I you know of any solution.
Here is the sample code of the dialog box
import bpy
class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Simple Dialog Operator"
my_float: bpy.props.FloatProperty(name="Some Floating Point")
my_bool: bpy.props.BoolProperty(name="Toggle Option")
my_string: bpy.props.StringProperty(name="String Value")
def execute(self, context):
message = (
"Popup Values: %f, %d, '%s'" %
(self.my_float, self.my_bool, self.my_string)
)
self.report({'INFO'}, message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
bpy.utils.register_class(DialogOperator)
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
Upvotes: 4
Views: 972
Reputation: 111
There is a workaround using the cancel function of the operator. It calls the operator again when the dialog is closed, and it looks like the dialog was never closed (except a movement in the dialog) https://docs.blender.org/api/3.3/bpy.types.Operator.html#bpy.types.Operator.cancel
import bpy
class DialogOperator(bpy.types.Operator):
bl_idname = "object.dialog_operator"
bl_label = "Simple Dialog Operator"
my_float: bpy.props.FloatProperty(name="Some Floating Point")
my_bool: bpy.props.BoolProperty(name="Toggle Option")
my_string: bpy.props.StringProperty(name="String Value")
def execute(self, context):
message = (
"Popup Values: %f, %d, '%s'" %
(self.my_float, self.my_bool, self.my_string)
)
self.report({'INFO'}, message)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)
def cancel(self, context):
bpy.ops.object.dialog_operator('INVOKE_DEFAULT', my_float=self.my_float, my_bool=self.my_bool, my_string=self.my_string)
bpy.utils.register_class(DialogOperator)
bpy.ops.object.dialog_operator('INVOKE_DEFAULT')
Upvotes: 1