From d2e5ba50c7edee569dcda026c56574a8f5dd52b7 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Wed, 21 Nov 2018 17:09:02 +0100 Subject: [PATCH] Fix updating job prefix when changing variant/material Fixes #23 --- .../PrintInformationPatches.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/BlackBeltPlugin/PrintInformationPatches.py b/plugins/BlackBeltPlugin/PrintInformationPatches.py index c2f248308c..bc20eef26b 100644 --- a/plugins/BlackBeltPlugin/PrintInformationPatches.py +++ b/plugins/BlackBeltPlugin/PrintInformationPatches.py @@ -1,10 +1,37 @@ +from cura.CuraApplication import CuraApplication import re +from typing import Any, Optional, TYPE_CHECKING + +if TYPE_CHECKING: + from cura.Settings.GlobalStack import GlobalStack + class PrintInformationPatches(): - def __init__(self, print_information): + def __init__(self, print_information) -> None: self._print_information = print_information self._print_information._defineAbbreviatedMachineName = self._defineAbbreviatedMachineName + self._global_stack = None # type: Optional[GlobalStack] + CuraApplication.getInstance().getMachineManager().globalContainerChanged.connect(self._onMachineChanged) + self._onMachineChanged() + + def _onMachineChanged(self) -> None: + if self._global_stack: + definition_container = self._global_stack.getBottom() + if definition_container.getId() == "blackbelt": + self._global_stack.containersChanged.disconnect(self._onContainersChanged) + + self._global_stack = CuraApplication.getInstance().getGlobalContainerStack() + + if self._global_stack: + definition_container = self._global_stack.getBottom() + if definition_container.getId() == "blackbelt": + self._global_stack.containersChanged.connect(self._onContainersChanged) + + def _onContainersChanged(self, container: Any) -> None: + self._print_information._updateJobName() + + ## Created an acronymn-like abbreviated machine name from the currently active machine name # Called each time the global stack is switched # Copied verbatim from PrintInformation._defineAbbreviatedMachineName, with a minor patch to set the abbreviation from settings