From c2c53d51c1954315324982bd916b8aad5c19946d Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Wed, 1 Sep 2021 16:04:05 +0200 Subject: [PATCH] Use optional last output (file) name from output-dev to set project name. Instead of relying on the filename emitted when the workspace is changed. This is done so the user can also change the project name when saving to an output device, such as a local file, or the digital library, that supports changeing the (file)name. CURA-8358 --- cura/UI/PrintInformation.py | 16 ++++++++++++---- .../src/DigitalFactoryController.py | 4 ++-- .../src/DigitalFactoryOutputDevice.py | 4 +++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/cura/UI/PrintInformation.py b/cura/UI/PrintInformation.py index 852763cbfd..9640326c91 100644 --- a/cura/UI/PrintInformation.py +++ b/cura/UI/PrintInformation.py @@ -13,6 +13,7 @@ from UM.Qt.Duration import Duration from UM.Scene.SceneNode import SceneNode from UM.i18n import i18nCatalog from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError +from UM.OutputDevice import OutputDevice if TYPE_CHECKING: from cura.CuraApplication import CuraApplication @@ -67,7 +68,8 @@ class PrintInformation(QObject): self._application.globalContainerStackChanged.connect(self._updateJobName) self._application.globalContainerStackChanged.connect(self.setToZeroPrintInformation) self._application.fileLoaded.connect(self.setBaseName) - self._application.workspaceLoaded.connect(self._onWorkspaceLoaded) + self._application.workspaceLoaded.connect(self.setProjectName) + self._application.getOutputDeviceManager().writeStarted.connect(self._onOutputStart) self._application.getMachineManager().rootMaterialChanged.connect(self._onActiveMaterialsChanged) self._application.getInstance().getPreferences().preferenceChanged.connect(self._onPreferencesChanged) @@ -440,6 +442,12 @@ class PrintInformation(QObject): self.setToZeroPrintInformation(self._active_build_plate) - def _onWorkspaceLoaded(self, new_name: str) -> None: - """Update the job name whenever a new workspace is loaded.""" - self.setJobName(os.path.splitext(os.path.basename(new_name))[0]) + def _onOutputStart(self, output_device: OutputDevice) -> None: + """If this is the sort of output 'device' (like local or online file storage, rather than a printer), + the user could have altered the file-name, and thus the project name should be altered as well.""" + new_name = output_device.getLastOutputName() + if new_name is not None: + if len(os.path.dirname(new_name)) > 0: + self.setProjectName(new_name) + else: + self.setJobName(new_name) diff --git a/plugins/DigitalLibrary/src/DigitalFactoryController.py b/plugins/DigitalLibrary/src/DigitalFactoryController.py index b94f0e69c8..8a91992c0a 100644 --- a/plugins/DigitalLibrary/src/DigitalFactoryController.py +++ b/plugins/DigitalLibrary/src/DigitalFactoryController.py @@ -603,8 +603,8 @@ class DigitalFactoryController(QObject): self._saveFileToSelectedProjectHelper(filename, formats) def _saveFileToSelectedProjectHelper(self, filename: str, formats: List[str]) -> None: - # Indicate we have started sending a job. - self.uploadStarted.emit() + # Indicate we have started sending a job (and propagate any user file name changes back to the open project) + self.uploadStarted.emit(filename) library_project_id = self._project_model.items[self._selected_project_idx]["libraryProjectId"] library_project_name = self._project_model.items[self._selected_project_idx]["displayName"] diff --git a/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py b/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py index 70e3ac34f2..3f52be6284 100644 --- a/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py +++ b/plugins/DigitalLibrary/src/DigitalFactoryOutputDevice.py @@ -105,8 +105,10 @@ class DigitalFactoryOutputDevice(ProjectOutputDevice): self.enabled = logged_in and self._controller.userAccountHasLibraryAccess() self.enabledChanged.emit() - def _onWriteStarted(self) -> None: + def _onWriteStarted(self, new_name: Optional[str] = None) -> None: self._writing = True + if new_name: + self.setLastOutputName(new_name) # On saving, the user can change the name, this should propagate. self.writeStarted.emit(self) def _onWriteFinished(self) -> None: