Ways to avoid toggling edit mode from within an operator

So here’s the problem: I’ve been working on my Show Vertex Groups/Weights addon and it works pretty well. Unfortunately, there are two instances where the script toggles out of and back into Edit mode from within an operator. I wasn’t previously aware that this is discouraged and disallowed. To that end, I’d really like to find a solution where I don’t have to make that toggle.

The core of the issue is this: I’m using panels in the UI (3D View’s Properties region) to display vertex information. Unfortunately, due to the nature of the Mesh module, when you add or remove a vertex to/from a vertex group, these panels get out of sync with the actual state of the mesh. And the only way (that I’m aware of) to re-sync those UI values is to quickly pop out of edit mode and then back in.

So… what’s the solution here? Is there another way to force a refresh of the mesh data? Will I need to resort to using custom properties for the UI that basically act as a thin wrapper for the actual mesh data?

Ideas and suggestions welcome.

Have you tried mesh.update()?

I thought bMesh was supposed to solve this toggle edit state problem…

I just tried mesh.update(); doesn’t seem to help.

By and large, bmesh does solve a lot of the toggle problem. Unfortunately, bmesh properties aren’t exposed to be available to the UILayout module (that is, layout.prop(bmeshsomething, “something”) doesn’t work).