From c2aa5fc2a2756404f8ded96218aeeea566d8cdfb Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 1 Feb 2018 13:12:23 +0100 Subject: [PATCH] Only initialise AutoSave after Application finishes its start up CURA-4895 --- cura/CuraApplication.py | 8 ++++++++ plugins/AutoSave/AutoSave.py | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index c39ce1d079..e2efaeb517 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -106,6 +106,14 @@ if not MYPY: CuraDebugMode = False +# +# A global signal which is triggered when CuraApplication has finished its start up. +# This is used to initialise some plugins such as AutoSave which should only be started after the application passed +# the start up successfully. +# +applicationStarted = pyqtSignal() + + class CuraApplication(QtApplication): # SettingVersion represents the set of settings available in the machine/extruder definitions. # You need to make sure that this version number needs to be increased if there is any non-backwards-compatible diff --git a/plugins/AutoSave/AutoSave.py b/plugins/AutoSave/AutoSave.py index 331f328f2d..30c12b5424 100644 --- a/plugins/AutoSave/AutoSave.py +++ b/plugins/AutoSave/AutoSave.py @@ -9,6 +9,7 @@ from UM.Application import Application from UM.Resources import Resources from UM.Logger import Logger + class AutoSave(Extension): def __init__(self): super().__init__() @@ -16,8 +17,6 @@ class AutoSave(Extension): Preferences.getInstance().preferenceChanged.connect(self._triggerTimer) self._global_stack = None - Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) - self._onGlobalStackChanged() Preferences.getInstance().addPreference("cura/autosave_delay", 1000 * 10) @@ -28,6 +27,21 @@ class AutoSave(Extension): self._saving = False + # At this point, the Application instance has not finished its constructor call yet, so directly using something + # like Application.getInstance() is not correct. The initialisation now will only gets triggered after the + # application finishes its start up successfully. + from cura.CuraApplication import applicationStarted + applicationStarted.connect(self.initialize) + + def initialize(self): + from cura.CuraApplication import applicationStarted + applicationStarted.disconnect(self.initialize) + + Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) + self._onGlobalStackChanged() + + self._triggerTimer() + def _triggerTimer(self, *args): if not self._saving: self._change_timer.start()