[core] Add new type of ChoiceParam that changes dynamically according to other values

Add new type of ChoiceParam that changes dynamically according to other
values.

When value of an attribute is changed onAttributeChanged is called,
allowing to have unique reaction within node files.

Also add of callDesc function to be able to have other functions such as
onNodeCreated at creation of node.
This commit is contained in:
Aurore LAFAURIE 2024-03-27 16:51:24 +01:00
parent bb9661a141
commit 498fd6cbd2
4 changed files with 68 additions and 11 deletions

View file

@ -879,6 +879,14 @@ class BaseNode(BaseObject):
def _updateChunks(self):
pass
def onAttributeChanged(self, attr):
paramName = attr.name[:1].upper() + attr.name[1:]
methodName = f'on{paramName}Changed'
if hasattr(self.nodeDesc, methodName):
m = getattr(self.nodeDesc, methodName)
if callable(m):
m(self)
def updateInternals(self, cacheDir=None):
""" Update Node's internal parameters and output attributes.
@ -1245,6 +1253,13 @@ class Node(BaseNode):
self.attributesPerUid[uidIndex].add(attr)
self.setAttributeValues(kwargs)
self.callDesc("onNodeCreated")
def callDesc(self, methodName, *args, **kwargs):
if hasattr(self.nodeDesc, methodName):
m = getattr(self.nodeDesc, methodName)
if callable(m):
m(self, *args, **kwargs)
def setAttributeValues(self, values):
# initialize attribute values