Created by: zeffii
new decorator for updateNode wrappers..
implementation details
this is only a preliminary implementation, because it might be useful to include a way to end the update function early, and not ultimately process_node
.
# use as a decorator
def throttled(func):
"""
When a node has changed, like a mode-change leading to a socket change (remove, new)
Blender will trigger nodetree.update. We want to ignore this trigger-event, and we do so by
- first throttling the update system.
- then We execute the code that makes changes to the node/nodetree
- then we end the throttle-state
- we are then ready to process
"""
def wrapper_update(self, context):
with self.sv_throttle_tree_update():
func(self, context)
self.process_node(context)
return wrapper_update
usage
from sverchok.node_tree import SverchCustomTreeNode, throttled
class SvYourNode(...):
...
@throttled
def mode_update_wrapper(self, context):
# your nodetree update triggering stuff here
# 1) changes to sockets
# 2) changes to links
# the decorator calls self.process_node(context) for you
mode_direction: bpy.props.EnumProperty(......update=mode_update_wrapper)
Why ?
this means that we can abstract away the task of throttleing, and also assume that the node tree will be udpated at the end.
issues..
i'm not sure on the name, but the implementation seems sound.- maybe later after testing the implementation and encountering special cases, we might consider adding the ability to pass an 'exit_function`..