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:
|
if self._backend:
|
||||||
self._backend.printDurationMessage.connect(self._onPrintDurationMessage)
|
self._backend.printDurationMessage.connect(self._onPrintDurationMessage)
|
||||||
|
|
||||||
self._job_name = ""
|
self._base_name = ""
|
||||||
self._abbr_machine = ""
|
self._abbr_machine = ""
|
||||||
|
self._job_name = ""
|
||||||
|
|
||||||
Application.getInstance().globalContainerStackChanged.connect(self._setAbbreviatedMachineName)
|
Application.getInstance().globalContainerStackChanged.connect(self._setAbbreviatedMachineName)
|
||||||
Application.getInstance().fileLoaded.connect(self.setJobName)
|
Application.getInstance().fileLoaded.connect(self.setBaseName)
|
||||||
|
|
||||||
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
|
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
|
||||||
|
|
||||||
|
@ -221,16 +222,8 @@ class PrintInformation(QObject):
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def setJobName(self, name):
|
def setJobName(self, name):
|
||||||
# Ensure that we don't use entire path but only filename
|
self._job_name = name
|
||||||
name = os.path.basename(name)
|
self.jobNameChanged.emit()
|
||||||
|
|
||||||
# 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()
|
|
||||||
|
|
||||||
jobNameChanged = pyqtSignal()
|
jobNameChanged = pyqtSignal()
|
||||||
|
|
||||||
|
@ -238,21 +231,43 @@ class PrintInformation(QObject):
|
||||||
def jobName(self):
|
def jobName(self):
|
||||||
return self._job_name
|
return self._job_name
|
||||||
|
|
||||||
@pyqtSlot(str, result = str)
|
def _updateJobName(self):
|
||||||
def createJobName(self, base_name):
|
if self._base_name == "":
|
||||||
if base_name == "":
|
self._job_name = ""
|
||||||
return ""
|
self.jobNameChanged.emit()
|
||||||
base_name = self._stripAccents(base_name)
|
return
|
||||||
|
|
||||||
|
base_name = self._stripAccents(self._base_name)
|
||||||
self._setAbbreviatedMachineName()
|
self._setAbbreviatedMachineName()
|
||||||
if self._pre_sliced:
|
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"):
|
elif Preferences.getInstance().getValue("cura/jobname_prefix"):
|
||||||
# Don't add abbreviation if it already has the exact same abbreviation.
|
# Don't add abbreviation if it already has the exact same abbreviation.
|
||||||
if base_name.startswith(self._abbr_machine + "_"):
|
if base_name.startswith(self._abbr_machine + "_"):
|
||||||
return base_name
|
self._job_name = base_name
|
||||||
return self._abbr_machine + "_" + base_name
|
else:
|
||||||
|
self._job_name = self._abbr_machine + "_" + base_name
|
||||||
else:
|
else:
|
||||||
return base_name
|
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
|
## Created an acronymn-like abbreviated machine name from the currently active machine name
|
||||||
# Called each time the global stack is switched
|
# Called each time the global stack is switched
|
||||||
|
@ -277,4 +292,4 @@ class PrintInformation(QObject):
|
||||||
|
|
||||||
## Utility method that strips accents from characters (eg: â -> a)
|
## Utility method that strips accents from characters (eg: â -> a)
|
||||||
def _stripAccents(self, str):
|
def _stripAccents(self, str):
|
||||||
return ''.join(char for char in unicodedata.normalize('NFD', str) if unicodedata.category(char) != 'Mn')
|
return ''.join(char for char in unicodedata.normalize('NFD', str) if unicodedata.category(char) != 'Mn')
|
||||||
|
|
|
@ -13,13 +13,7 @@ Item {
|
||||||
id: base
|
id: base
|
||||||
|
|
||||||
property bool activity: CuraApplication.platformActivity
|
property bool activity: CuraApplication.platformActivity
|
||||||
property string fileBaseName
|
property string fileBaseName: ""
|
||||||
property variant activeMachineName: Cura.MachineManager.activeMachineName
|
|
||||||
|
|
||||||
onActiveMachineNameChanged:
|
|
||||||
{
|
|
||||||
printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
|
|
||||||
}
|
|
||||||
|
|
||||||
UM.I18nCatalog { id: catalog; name:"cura"}
|
UM.I18nCatalog { id: catalog; name:"cura"}
|
||||||
|
|
||||||
|
@ -30,23 +24,26 @@ Item {
|
||||||
target: backgroundItem
|
target: backgroundItem
|
||||||
onHasMesh:
|
onHasMesh:
|
||||||
{
|
{
|
||||||
base.fileBaseName = name
|
if (base.fileBaseName == "")
|
||||||
|
{
|
||||||
|
base.fileBaseName = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onActivityChanged: {
|
onActivityChanged: {
|
||||||
if (activity == true && base.fileBaseName == ''){
|
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)
|
//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)
|
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)
|
||||||
printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
|
PrintInformation.setBaseName(base.fileBaseName);
|
||||||
}
|
}
|
||||||
if (activity == true && 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
|
//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){
|
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)
|
//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)
|
width: Math.max(__contentWidth + UM.Theme.getSize("default_margin").width, 50)
|
||||||
maximumLength: 120
|
maximumLength: 120
|
||||||
property int unremovableSpacing: 5
|
property int unremovableSpacing: 5
|
||||||
text: ''
|
text: PrintInformation.jobName
|
||||||
horizontalAlignment: TextInput.AlignRight
|
horizontalAlignment: TextInput.AlignRight
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
PrintInformation.setJobName(text);
|
PrintInformation.setJobName(text);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue