mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 02:08:08 +02:00
[core] Propagate the onAttributeChanged notification to connected attributes
This commit is contained in:
parent
a82fe3927b
commit
3cc67fddfb
2 changed files with 23 additions and 2 deletions
|
@ -76,6 +76,8 @@ class Attribute(BaseObject):
|
|||
self._value = None
|
||||
self.initValue()
|
||||
|
||||
self.valueChanged.connect(self.onChanged)
|
||||
|
||||
@property
|
||||
def node(self):
|
||||
return self._node()
|
||||
|
@ -187,6 +189,21 @@ class Attribute(BaseObject):
|
|||
return self.getLinkParam().value
|
||||
return self._value
|
||||
|
||||
def onChanged(self):
|
||||
""" Called when the attribute value has changed """
|
||||
if self.node.isCompatibilityNode:
|
||||
# We have no access to the node's implementation,
|
||||
# so we cannot call the custom method.
|
||||
return
|
||||
if self.isOutput and not self.node.isInputNode:
|
||||
# Ignore changes on output attributes for non-input nodes
|
||||
# as they are updated during the node's computation.
|
||||
# And we do not want notifications during the graph processing.
|
||||
return
|
||||
# notify the node that the attribute has changed
|
||||
# this will call the node descriptor "onAttrNameChanged" method
|
||||
self.node.onAttributeChanged(self)
|
||||
|
||||
def _set_value(self, value, emitSignals=True):
|
||||
if self._value == value:
|
||||
return
|
||||
|
@ -206,8 +223,6 @@ class Attribute(BaseObject):
|
|||
if not emitSignals:
|
||||
return
|
||||
|
||||
if not self.node.isCompatibilityNode:
|
||||
self.node.onAttributeChanged(self)
|
||||
# Request graph update when input parameter value is set
|
||||
# and parent node belongs to a graph
|
||||
# Output attributes value are set internally during the update process,
|
||||
|
|
|
@ -920,6 +920,7 @@ class BaseNode(BaseObject):
|
|||
Args:
|
||||
attr (Attribute): attribute that has changed
|
||||
"""
|
||||
# Call the specific function if it exists in the node implementation
|
||||
paramName = attr.name[:1].upper() + attr.name[1:]
|
||||
methodName = f'on{paramName}Changed'
|
||||
if hasattr(self.nodeDesc, methodName):
|
||||
|
@ -927,6 +928,11 @@ class BaseNode(BaseObject):
|
|||
if callable(m):
|
||||
m(self)
|
||||
|
||||
# Propage the notification to connected output attributes
|
||||
outEdges = self.graph.outEdges(attr)
|
||||
for edge in outEdges:
|
||||
edge.dst.onChanged()
|
||||
|
||||
def onAttributeClicked(self, attr):
|
||||
""" When an attribute is clicked, a specific function can be defined in the descriptor and be called.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue