diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 4d8fc42d57..462f411037 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -691,17 +691,29 @@ 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() Logger.log("d", "Booting Cura took %s seconds", time.time() - self._boot_loading_time) + + + # 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). @@ -1548,6 +1560,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(): @@ -1560,6 +1574,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;