From cadb2c62b7e1c4396f72562a16604afd68361d33 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Fri, 6 Apr 2018 11:52:58 +0200 Subject: [PATCH] Fix open file with Cura CURA-5203 When open a file that's associated with Cura, dialogs that need to pop up may not work because QML is still in the middle of initialization, so we need to wait for QML to finish before doing anything else such as opening files. --- cura/CuraApplication.py | 28 ++++++++++++++++++++++------ resources/qml/Cura.qml | 10 ++++++++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 296c9b75dd..205f918ec4 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -689,16 +689,26 @@ class CuraApplication(QtApplication): else: self.runWithGUI() - # Pre-load files if requested - for file_name in self.getCommandLineOption("file", []): - self._openFile(file_name) - for file_name in self._open_file_queue: # Open all the files that were queued up while plug-ins were loading. - self._openFile(file_name) - self.started = True self.initializationFinished.emit() + + # For now use a timer to postpone some things that need to be done after the application and GUI are + # initialized, for example opening files because they may show dialogs which can be closed due to incomplete + # GUI initialization. + self._post_start_timer = QTimer(self) + self._post_start_timer.setInterval(700) + self._post_start_timer.setSingleShot(True) + self._post_start_timer.timeout.connect(self._onPostStart) + self._post_start_timer.start() + self.exec_() + def _onPostStart(self): + for file_name in self.getCommandLineOption("file", []): + self.callLater(self._openFile, file_name) + for file_name in self._open_file_queue: # Open all the files that were queued up while plug-ins were loading. + self.callLater(self._openFile, file_name) + initializationFinished = pyqtSignal() ## Run Cura without GUI elements and interaction (server mode). @@ -1545,6 +1555,8 @@ class CuraApplication(QtApplication): def log(self, msg): Logger.log("d", msg) + openProjectFile = pyqtSignal(QUrl, arguments = ["project_file"]) # Emitted when a project file is about to open. + @pyqtSlot(QUrl) def readLocalFile(self, file): if not file.isValid(): @@ -1557,6 +1569,10 @@ class CuraApplication(QtApplication): self.deleteAll() break + if self.checkIsValidProjectFile(file): + self.callLater(self.openProjectFile.emit, file) + return + f = file.toLocalFile() extension = os.path.splitext(f)[1] filename = os.path.basename(f) diff --git a/resources/qml/Cura.qml b/resources/qml/Cura.qml index c4ebb790e8..005cb17220 100644 --- a/resources/qml/Cura.qml +++ b/resources/qml/Cura.qml @@ -855,6 +855,16 @@ UM.MainWindow id: askOpenAsProjectOrModelsDialog } + Connections + { + target: CuraApplication + onOpenProjectFile: + { + askOpenAsProjectOrModelsDialog.fileUrl = project_file; + askOpenAsProjectOrModelsDialog.show(); + } + } + EngineLog { id: engineLog;