mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 15:44:04 -06:00
Fix job name mismatching
CURA-4276
This commit is contained in:
parent
c614f02d0f
commit
b0916e4b67
2 changed files with 47 additions and 35 deletions
|
@ -76,11 +76,12 @@ class PrintInformation(QObject):
|
|||
if self._backend:
|
||||
self._backend.printDurationMessage.connect(self._onPrintDurationMessage)
|
||||
|
||||
self._job_name = ""
|
||||
self._base_name = ""
|
||||
self._abbr_machine = ""
|
||||
self._job_name = ""
|
||||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._setAbbreviatedMachineName)
|
||||
Application.getInstance().fileLoaded.connect(self.setJobName)
|
||||
Application.getInstance().fileLoaded.connect(self.setBaseName)
|
||||
|
||||
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
|
||||
|
||||
|
@ -221,14 +222,6 @@ class PrintInformation(QObject):
|
|||
|
||||
@pyqtSlot(str)
|
||||
def setJobName(self, name):
|
||||
# Ensure that we don't use entire path but only filename
|
||||
name = os.path.basename(name)
|
||||
|
||||
# when a file is opened using the terminal; the filename comes from _onFileLoaded and still contains its
|
||||
# extension. This cuts the extension off if necessary.
|
||||
name = os.path.splitext(name)[0]
|
||||
name = self.createJobName(name)
|
||||
if self._job_name != name and (self._job_name == "" or name == ""):
|
||||
self._job_name = name
|
||||
self.jobNameChanged.emit()
|
||||
|
||||
|
@ -238,21 +231,43 @@ class PrintInformation(QObject):
|
|||
def jobName(self):
|
||||
return self._job_name
|
||||
|
||||
@pyqtSlot(str, result = str)
|
||||
def createJobName(self, base_name):
|
||||
if base_name == "":
|
||||
return ""
|
||||
base_name = self._stripAccents(base_name)
|
||||
def _updateJobName(self):
|
||||
if self._base_name == "":
|
||||
self._job_name = ""
|
||||
self.jobNameChanged.emit()
|
||||
return
|
||||
|
||||
base_name = self._stripAccents(self._base_name)
|
||||
self._setAbbreviatedMachineName()
|
||||
if self._pre_sliced:
|
||||
return catalog.i18nc("@label", "Pre-sliced file {0}", base_name)
|
||||
self._job_name = catalog.i18nc("@label", "Pre-sliced file {0}", base_name)
|
||||
elif Preferences.getInstance().getValue("cura/jobname_prefix"):
|
||||
# Don't add abbreviation if it already has the exact same abbreviation.
|
||||
if base_name.startswith(self._abbr_machine + "_"):
|
||||
return base_name
|
||||
return self._abbr_machine + "_" + base_name
|
||||
self._job_name = base_name
|
||||
else:
|
||||
return base_name
|
||||
self._job_name = self._abbr_machine + "_" + base_name
|
||||
else:
|
||||
self._job_name = base_name
|
||||
|
||||
self.jobNameChanged.emit()
|
||||
|
||||
@pyqtProperty(str)
|
||||
def baseName(self):
|
||||
return self._base_name
|
||||
|
||||
@pyqtSlot(str)
|
||||
def setBaseName(self, base_name):
|
||||
# Ensure that we don't use entire path but only filename
|
||||
name = os.path.basename(base_name)
|
||||
|
||||
# when a file is opened using the terminal; the filename comes from _onFileLoaded and still contains its
|
||||
# extension. This cuts the extension off if necessary.
|
||||
name = os.path.splitext(name)[0]
|
||||
|
||||
if self._base_name == "" and self._base_name != name:
|
||||
self._base_name = name
|
||||
self._updateJobName()
|
||||
|
||||
## Created an acronymn-like abbreviated machine name from the currently active machine name
|
||||
# Called each time the global stack is switched
|
||||
|
|
|
@ -13,13 +13,7 @@ Item {
|
|||
id: base
|
||||
|
||||
property bool activity: CuraApplication.platformActivity
|
||||
property string fileBaseName
|
||||
property variant activeMachineName: Cura.MachineManager.activeMachineName
|
||||
|
||||
onActiveMachineNameChanged:
|
||||
{
|
||||
printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
|
||||
}
|
||||
property string fileBaseName: ""
|
||||
|
||||
UM.I18nCatalog { id: catalog; name:"cura"}
|
||||
|
||||
|
@ -30,23 +24,26 @@ Item {
|
|||
target: backgroundItem
|
||||
onHasMesh:
|
||||
{
|
||||
base.fileBaseName = name
|
||||
if (base.fileBaseName == "")
|
||||
{
|
||||
base.fileBaseName = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onActivityChanged: {
|
||||
if (activity == true && base.fileBaseName == ''){
|
||||
//this only runs when you open a file from the terminal (or something that works the same way; for example when you drag a file on the icon in MacOS or use 'open with' on Windows)
|
||||
base.fileBaseName = PrintInformation.jobName; //get the fileBaseName from PrintInformation.py because this saves the filebase when the file is opened using the terminal (or something alike)
|
||||
printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
|
||||
base.fileBaseName = PrintInformation.baseName; //get the fileBaseName from PrintInformation.py because this saves the filebase when the file is opened using the terminal (or something alike)
|
||||
PrintInformation.setBaseName(base.fileBaseName);
|
||||
}
|
||||
if (activity == true && base.fileBaseName != ''){
|
||||
//this runs in all other cases where there is a mesh on the buildplate (activity == true). It uses the fileBaseName from the hasMesh signal
|
||||
printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
|
||||
PrintInformation.setBaseName(base.fileBaseName);
|
||||
}
|
||||
if (activity == false){
|
||||
//When there is no mesh in the buildplate; the printJobTextField is set to an empty string so it doesn't set an empty string as a jobName (which is later used for saving the file)
|
||||
printJobTextfield.text = '';
|
||||
PrintInformation.setJobName('')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +99,7 @@ Item {
|
|||
width: Math.max(__contentWidth + UM.Theme.getSize("default_margin").width, 50)
|
||||
maximumLength: 120
|
||||
property int unremovableSpacing: 5
|
||||
text: ''
|
||||
text: PrintInformation.jobName
|
||||
horizontalAlignment: TextInput.AlignRight
|
||||
onTextChanged: {
|
||||
PrintInformation.setJobName(text);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue