diff options
author | Nino van Hooff <ninovanhooff@gmail.com> | 2020-06-30 18:04:03 +0300 |
---|---|---|
committer | Nino van Hooff <ninovanhooff@gmail.com> | 2020-06-30 18:04:03 +0300 |
commit | c50f7aa4558576612c71daa4612f217ac2afa9eb (patch) | |
tree | 41ecd126b792d3d7eab2166187089938bfbce61c /cura/UI | |
parent | 99f4c1a2d36f4dc31b5c0ca0867f7ac70be830a3 (diff) |
Add a print job name setting to general preferences
CURA-5479
Diffstat (limited to 'cura/UI')
-rw-r--r-- | cura/UI/PrintInformation.py | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/cura/UI/PrintInformation.py b/cura/UI/PrintInformation.py index ae4aab0407..1a5c096c8c 100644 --- a/cura/UI/PrintInformation.py +++ b/cura/UI/PrintInformation.py @@ -252,11 +252,12 @@ class PrintInformation(QObject): self.materialNamesChanged.emit() def _onPreferencesChanged(self, preference: str) -> None: - if preference != "cura/material_settings": - return + if preference == "cura/job_name_template": + self._updateJobName() - for build_plate_number in range(self._multi_build_plate_model.maxBuildPlate + 1): - self._calculateInformation(build_plate_number) + if preference == "cura/material_settings": + for build_plate_number in range(self._multi_build_plate_model.maxBuildPlate + 1): + self._calculateInformation(build_plate_number) def _onActiveBuildPlateChanged(self) -> None: new_active_build_plate = self._multi_build_plate_model.activeBuildPlate @@ -305,12 +306,8 @@ class PrintInformation(QObject): # Only update the job name when it's not user-specified. if not self._is_user_specified_job_name: - if self._application.getInstance().getPreferences().getValue("cura/jobname_prefix") and not self._pre_sliced: - # Don't add abbreviation if it already has the exact same abbreviation. - if base_name.startswith(self._abbr_machine + "_"): - self._job_name = base_name - else: - self._job_name = self._abbr_machine + "_" + base_name + if not self._pre_sliced: + self._job_name = self.parseTemplate() else: self._job_name = base_name @@ -440,3 +437,28 @@ class PrintInformation(QObject): """Listen to scene changes to check if we need to reset the print information""" self.setToZeroPrintInformation(self._active_build_plate) + + def parseTemplate(self) -> str: + """Generate a print job name from the job name template + + The template is a user preference: "cura/job_name_template" + """ + template = self._application.getInstance().getPreferences().getValue("cura/job_name_template") + output = template + + output = output.replace("{machine_name_short}", self._abbr_machine) + + if "{machine_name}" in template: + global_container_stack = self._application.getGlobalContainerStack() + if not global_container_stack: + self._abbr_machine = "" + return + active_machine_type_name = global_container_stack.definition.getName() + active_machine_type_name = active_machine_type_name.replace(" ", "_") + output = output.replace("{machine_name}", active_machine_type_name) + + if "{project_name}" in template: + base_name = self._stripAccents(self._base_name) + output = output.replace("{project_name}", base_name) + + return output |