mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 04:45:52 +08:00
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:
parent
19937d1be0
commit
cadb2c62b7
@ -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)
|
||||
|
@ -855,6 +855,16 @@ UM.MainWindow
|
||||
id: askOpenAsProjectOrModelsDialog
|
||||
}
|
||||
|
||||
Connections
|
||||
{
|
||||
target: CuraApplication
|
||||
onOpenProjectFile:
|
||||
{
|
||||
askOpenAsProjectOrModelsDialog.fileUrl = project_file;
|
||||
askOpenAsProjectOrModelsDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
EngineLog
|
||||
{
|
||||
id: engineLog;
|
||||
|
Loading…
x
Reference in New Issue
Block a user