Skip to content

Commit

Permalink
[core] Attribute: remove emitSignals logic on value setting
Browse files Browse the repository at this point in the history
With valueChanged signal being connected outside of the
Attribute's constructor, the emitSignals logic is not required to prevent
early valueChanged propagation.
  • Loading branch information
yann-lty committed Oct 28, 2024
1 parent 8e3b987 commit 4686b0d
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def attributeFactory(description, value, isOutput, node, root=None, parent=None)
"""
attr: Attribute = description.instanceType(node, description, isOutput, root, parent)
if value is not None:
attr._set_value(value, emitSignals=False)
attr._set_value(value)
else:
attr.resetToDefaultValue(emitSignals=False)
attr.resetToDefaultValue()

attr.valueChanged.connect(lambda attr=attr: node._onAttributeChanged(attr))

Expand Down Expand Up @@ -182,7 +182,7 @@ def _get_value(self):
return self.getLinkParam().value
return self._value

def _set_value(self, value, emitSignals=True):
def _set_value(self, value):
if self._value == value:
return

Expand All @@ -198,9 +198,6 @@ def _set_value(self, value, emitSignals=True):
convertedValue = self.validateValue(value)
self._value = convertedValue

if not emitSignals:
return

# 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,
Expand Down Expand Up @@ -238,8 +235,8 @@ def initValue(self):
if self.desc._valueType is not None:
self._value = self.desc._valueType()

def resetToDefaultValue(self, emitSignals=True):
self._set_value(copy.copy(self.defaultValue()), emitSignals=emitSignals)
def resetToDefaultValue(self):
self._set_value(copy.copy(self.defaultValue()))

def requestGraphUpdate(self):
if self.node.graph:
Expand Down Expand Up @@ -525,14 +522,13 @@ def index(self, item):
return self._value.indexOf(item)

def initValue(self):
self.resetToDefaultValue(emitSignals=False)
self.resetToDefaultValue()

def resetToDefaultValue(self, emitSignals=True):
def resetToDefaultValue(self):
self._value = ListModel(parent=self)
if emitSignals:
self.valueChanged.emit()
self.valueChanged.emit()

def _set_value(self, value, emitSignals=True):
def _set_value(self, value):
if self.node.graph:
self.remove(0, len(self))
# Link to another attribute
Expand All @@ -545,8 +541,6 @@ def _set_value(self, value, emitSignals=True):
self._value = ListModel(parent=self)
newValue = self.desc.validateValue(value)
self.extend(newValue)
if not emitSignals:
return
self.requestGraphUpdate()

def upgradeValue(self, exportedValues):
Expand Down Expand Up @@ -683,7 +677,7 @@ def __getattr__(self, key):
except KeyError:
raise AttributeError(key)

def _set_value(self, exportedValue, emitSignals=True):
def _set_value(self, exportedValue):
value = self.validateValue(exportedValue)
if isinstance(value, dict):
# set individual child attribute values
Expand Down Expand Up @@ -721,7 +715,7 @@ def initValue(self):
childAttr.valueChanged.connect(self.valueChanged)
self._value.reset(subAttributes)

def resetToDefaultValue(self, emitSignals=True):
def resetToDefaultValue(self):
for attrDesc in self.desc._groupDesc:
self._value.get(attrDesc.name).resetToDefaultValue()

Expand Down

0 comments on commit 4686b0d

Please sign in to comment.