Skip to content

Commit

Permalink
[core] Discard attribute callbacks during graph loading
Browse files Browse the repository at this point in the history
  • Loading branch information
yann-lty committed Nov 14, 2024
1 parent 87e538c commit 1134b33
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion meshroom/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def getFeaturesForVersion(fileVersion):
def __init__(self, name, parent=None):
super(Graph, self).__init__(parent)
self.name = name
self._loading = False
self._updateEnabled = True
self._updateRequested = False
self.dirtyTopology = False
Expand Down Expand Up @@ -247,19 +248,31 @@ def fileFeatures(self):
""" Get loaded file supported features based on its version. """
return Graph.IO.getFeaturesForVersion(self.header.get(Graph.IO.Keys.FileVersion, "0.0"))

@property
def isLoading(self):
""" Return True if the graph is currently being loaded. """
return self._loading

@Slot(str)
def load(self, filepath, setupProjectFile=True, importProject=False, publishOutputs=False):
"""
Load a Meshroom graph ".mg" file.
Args:
filepath: project filepath to load
setupProjectFile: Store the reference to the project file and setup the cache directory.
setupProjectFile: Storeu the reference to the project file and setup the cache directory.
If false, it only loads the graph of the project file as a template.
importProject: True if the project that is loaded will be imported in the current graph, instead
of opened.
publishOutputs: True if "Publish" nodes from templates should not be ignored.
"""
self._loading = True
try:
self._load(filepath, setupProjectFile, importProject, publishOutputs)
finally:
self._loading = False

def _load(self, filepath: PathLike, setupProjectFile: bool, importProject: bool, publishOutputs: bool):
if not importProject:
self.clear()
with open(filepath) as jsonFile:
Expand Down
4 changes: 4 additions & 0 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ def _onAttributeChanged(self, attr: Attribute):
if attr.value is None:
# Discard dynamic values depending on the graph processing.
return

if self.graph and self.graph.isLoading:
# Do not trigger attribute callbacks during the graph loading.
return

callback = self._getAttributeChangedCallback(attr)

Expand Down

0 comments on commit 1134b33

Please sign in to comment.