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.
This commit is contained in:
Lipu Fei 2018-04-06 11:52:58 +02:00
parent 19937d1be0
commit cadb2c62b7
2 changed files with 32 additions and 6 deletions

View File

@ -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)

View File

@ -855,6 +855,16 @@ UM.MainWindow
id: askOpenAsProjectOrModelsDialog
}
Connections
{
target: CuraApplication
onOpenProjectFile:
{
askOpenAsProjectOrModelsDialog.fileUrl = project_file;
askOpenAsProjectOrModelsDialog.show();
}
}
EngineLog
{
id: engineLog;