Is there a reliable way to determine when my Edit mode WorkSpaceTool is activated or deactivated that allows you to run operators?
I’m developing an addon for Blender that has its own tool that you switch to in Edit mode. I’d like to do some setup and teardown when the tool is activated or deactivated. I haven’t found any documentation on any handlers or methods on the WorkSpaceTool that let you do this. There are two workarounds I’ve found, one being using a timer and the second one is using a GizmoGroup(which doesn’t allow you to use operators).
The problem with timers is that unless you run it very quickly, a user could make a choice that gets overridden by the tool activation getting detected by the timer shortly after that choice. The user could also run a modal operator and put things in a very strange state if the timer triggers during that. I don’t know what the ramifications of running a faster timer are but I imagine you want to keep what it does to as fast as possible which isn’t ideal here.
The issue with using a GizmoGroup’s setup() and del() is that it is turned on and off in a number of places including running operators, using Ctrl-Z to undo and moving windows. These would cause flickering from my addon as it tries to be polite and set and restore state when it’s activated/deactivated. Also, because this appears to run in a draw/rendering only state or thread, you can’t run operators which I need to do to change the Select mode and to change tools(want to abort my tool with an error if the user goes into multi-edit which can’t be supported properly).
I did find an archived differential D10635 that looks absolutely perfect for what I need. It’s only 16 lines of code, maybe it could be resurrected and merged? @mauge? I didn’t see it in the pull requests and I could probably do it if you didn’t want to.