Temporarily disable add-on UI property update callback I want to synchronize two properties (e.g. sizeX and SizeY) when a “lock size” property is enabled. I have the properties SizeX and SizeY update callbacks linked to separate methods: update_sizex and update_sizey. When the property “lock sizes” is enabled, I want my update_sizex callback function to update the value of the property sizey whenever the user changes property sizex and the update_sizey callback function update the value of sizex whenever the user changes property sizey. Obviously since both properties have update callbacks, changing the value of one property programmatically from within the callback of the other property will create a cascade of recursive callbacks. Is there a way to temporarily disable the callback of a property programmatically just so that its value can be synced with other property value? (think of this as the Photoshop resize width / height lock mechanism).

sizex = FloatProperty(name='Size X', description='Size of plane along X',
                      default=10.0, update=update_sizex)

sizey = FloatProperty(name='Size Y', description='Size of plane along Y',
                      default=10.0, update=update_sizey)

def update_sizex(self, context):
        if self.lockSize:
            # update self.sizey without triggering recursive update callback

def update_sizey(self, context):
        if self.lockSize:
            # update self.sizex without triggering recursive update callback
Only trigger the update when it makes sense, when the value will be changed. Otherwise then don't set the value to the counterpart.

sizex = FloatProperty(name='Size X', description='Size of plane along X',
                      default=10.0, update=update_sizex)

sizey = FloatProperty(name='Size Y', description='Size of plane along Y',
                      default=10.0, update=update_sizey)

def update_sizex(self, context):
    if self.lockSize and self.sizey != self.sizex:
        self.sizey = self.sizex

def update_sizey(self, context):
    if self.lockSize and self.sizex != self.sizey:
        self.sizex = self.sizey


You can also use a temporary property for this. But in my opinion that makes things too complex. Also be aware that the setting can be set incorrectly making the lockSize functionality not working.


from the outside the do_not_update setting can be altered making the whole lockSize button broken.
when an exception happens during updating.


This can be fixed by a using finaly

try:
    self.do_not_update=True
    self.sizex = self.sizey

finally:
    self.do_not_update=False