Add-On Dev: Operator Window - Open/Close events?

by Robert   Last Updated October 13, 2019 05:15 AM

I've read in several places that its not safe to rely on constructors for types derived from Blender objects, such as property groups. But now I am creating a pop-up window with an operator class (using context.window_manager.invoke_props_dialog()), and I need to execute code when the window is opened and closed.

Previously, I was using invoke() as my open event, and execute() as my closing event. But I just found out that execute() is only called when the "OK" button is pressed. If the user clicks outside of the window to unfocus the window, it closes without executing. I'm assuming this is basically "cancel", which is cool. But I still want to execute certain code when it happens, if possible.

I've tried implementing _init__(self) and __del__(self) for the operator window, and they both appear to be called when the window opens and closes. But its difficult to know how reliable the behavior will be. Can anyone confirm that it is safe to use these as open/close events for an operator window? Or is there a better way to handle it?

Related Questions

Updated March 26, 2015 07:27 AM

Updated April 04, 2015 21:06 PM

Updated April 17, 2015 20:06 PM

Updated March 28, 2015 11:05 AM

Updated March 29, 2015 06:05 AM