Postpone signals in project loading to avoid incomplete data update

CURA-5056
This commit is contained in:
Lipu Fei 2018-03-07 11:15:26 +01:00
parent 23653d7357
commit c0d55ac2a8

View file

@ -6,6 +6,7 @@ from UM.Application import Application
from UM.Logger import Logger from UM.Logger import Logger
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from UM.Signal import postponeSignals, CompressTechnique
from UM.Settings.ContainerStack import ContainerStack from UM.Settings.ContainerStack import ContainerStack
from UM.Settings.DefinitionContainer import DefinitionContainer from UM.Settings.DefinitionContainer import DefinitionContainer
from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.InstanceContainer import InstanceContainer
@ -434,6 +435,24 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
# \param file_name # \param file_name
@call_on_qt_thread @call_on_qt_thread
def read(self, file_name): def read(self, file_name):
container_registry = ContainerRegistry.getInstance()
signals = [container_registry.containerAdded,
container_registry.containerRemoved,
container_registry.containerMetaDataChanged]
#
# We now have different managers updating their lookup tables upon container changes. It is critical to make
# sure that the managers have a complete set of data when they update.
#
# In project loading, lots of the container-related signals are loosely emitted, which can create timing gaps
# for incomplete data update or other kinds of issues to happen.
#
# To avoid this, we postpone all signals so they don't get emitted immediately. But, please also be aware that,
# because of this, do not expect to have the latest data in the lookup tables in project loading.
#
with postponeSignals(*signals, compress = CompressTechnique.CompressSingle):
return self._read(file_name)
def _read(self, file_name):
archive = zipfile.ZipFile(file_name, "r") archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")] cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]