update @classmethod outside area

I have a class with an @classmethod. It polls for a variable to be set.
If the variable is not set the button is grayed out, if the variable has a value, the button is not grayed out and usable.

it works, but only updates when the mouse is in the area (window) where the button is.

When i have my mouse in, for example, the 3d view when the variable gets a value, the button does not become active. when i move my mouse then into the properties window, the button becomes active.

I want it to get working regardless where my mouse is. so, as soon as the variable gets a value, the button becomes active immediately.

Does someone know how to fix this problem?

Thanks in advance.


This is a limitation by design, not every area is updated when some property changes. Usually it’s the desired behavior, because otherwise there would be a lot more updates and redraws.

The only way to workaround it is to constantly tag the target area to redraw - Area.tag_redraw(), which adds some overhead. You can do that in a scene update handler, or maybe with a modal timer operator.


This brings me a little further. Thanks.
I actually know when the variable is set. So constantly redrawing is not needed.
As I understand i have to redraw the panel in the properties at some point after the variable is set.
Going to find out how this area.tag_redraw() works.



EDIT: found it!

for area in bpy.context.screen.areas:
    if area.type == 'PROPERTIES':