Revert "Revert "Use optional last output (file) name from output-dev to set project name.""

This reverts commit 24ff3692bd.
This commit is contained in:
Konstantinos Karmas 2021-09-15 12:26:18 +02:00
parent 98eba28885
commit 87add2c8de
2 changed files with 13 additions and 5 deletions

View file

@ -13,6 +13,7 @@ from UM.Qt.Duration import Duration
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError from UM.MimeTypeDatabase import MimeTypeDatabase, MimeTypeNotFoundError
from UM.OutputDevice import OutputDevice
if TYPE_CHECKING: if TYPE_CHECKING:
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
@ -67,7 +68,8 @@ class PrintInformation(QObject):
self._application.globalContainerStackChanged.connect(self._updateJobName) self._application.globalContainerStackChanged.connect(self._updateJobName)
self._application.globalContainerStackChanged.connect(self.setToZeroPrintInformation) self._application.globalContainerStackChanged.connect(self.setToZeroPrintInformation)
self._application.fileLoaded.connect(self.setBaseName) 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.getMachineManager().rootMaterialChanged.connect(self._onActiveMaterialsChanged)
self._application.getInstance().getPreferences().preferenceChanged.connect(self._onPreferencesChanged) self._application.getInstance().getPreferences().preferenceChanged.connect(self._onPreferencesChanged)
@ -440,6 +442,12 @@ class PrintInformation(QObject):
self.setToZeroPrintInformation(self._active_build_plate) self.setToZeroPrintInformation(self._active_build_plate)
def _onWorkspaceLoaded(self, new_name: str) -> None: def _onOutputStart(self, output_device: OutputDevice) -> None:
"""Update the job name whenever a new workspace is loaded.""" """If this is the sort of output 'device' (like local or online file storage, rather than a printer),
self.setJobName(os.path.splitext(os.path.basename(new_name))[0]) 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)

View file

@ -111,7 +111,7 @@ class DigitalFactoryOutputDevice(ProjectOutputDevice):
self._writing = True self._writing = True
if new_name and Version(ApplicationMetadata.CuraSDKVersion) >= Version("7.8.0"): if new_name and Version(ApplicationMetadata.CuraSDKVersion) >= Version("7.8.0"):
# setLastOutputName is only supported in sdk version 7.8.0 and up # setLastOutputName is only supported in sdk version 7.8.0 and up
self.setLastOutputName(new_name) self.setLastOutputName(new_name) # On saving, the user can change the name, this should propagate.
self.writeStarted.emit(self) self.writeStarted.emit(self)
def _onWriteFinished(self) -> None: def _onWriteFinished(self) -> None: