diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 15b5265850..1c8734c80d 100644 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -17,6 +17,8 @@ from . import ExtruderManager from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") +import time + class MachineManager(QObject): def __init__(self, parent = None): super().__init__(parent) @@ -60,6 +62,10 @@ class MachineManager(QObject): self.setActiveMachine(active_machine_id) pass + self._auto_change_material_hotend_flood_window = 10 + self._auto_change_material_hotend_flood_time = 0 + self._auto_change_material_hotend_flood_last_choice = None + globalContainerChanged = pyqtSignal() activeMaterialChanged = pyqtSignal() activeVariantChanged = pyqtSignal() @@ -98,6 +104,7 @@ class MachineManager(QObject): containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = self._global_container_stack.getBottom().getId(), name = hotend_id) if containers: + extruder_manager = ExtruderManager.ExtruderManager.getInstance() old_index = extruder_manager.activeExtruderIndex if old_index != index: extruder_manager.setActiveExtruderIndex(index) @@ -105,9 +112,12 @@ class MachineManager(QObject): old_index = None if self.activeVariantId != containers[0].getId(): - Application.getInstance().messageBox(catalog.i18nc("@window:title", "Changes on the Printer"), catalog.i18nc("@label", "Do you want to change the hotend to match the hotend in your printer?"), - catalog.i18nc("@label", "The hotend on your printer was changed. For best results always slice for the hotend that is inserted in your printer."), - buttons = QMessageBox.Yes + QMessageBox.No, icon = QMessageBox.Question, callback = self._hotendChangedDialogCallback, callback_arguments = [index, containers[0].getId()]) + if time.time() - self._auto_change_material_hotend_flood_time > self._auto_change_material_hotend_flood_window: + Application.getInstance().messageBox(catalog.i18nc("@window:title", "Changes on the Printer"), catalog.i18nc("@label", "Do you want to change the hotend to match the hotend in your printer?"), + catalog.i18nc("@label", "The hotend on your printer was changed. For best results always slice for the hotend that is inserted in your printer."), + buttons = QMessageBox.Yes + QMessageBox.No, icon = QMessageBox.Question, callback = self._hotendChangedDialogCallback, callback_arguments = [index, containers[0].getId()]) + else: + self._hotendChangedDialogCallback(self._auto_change_material_hotend_flood_last_choice, index, containers[0].getId()) if old_index is not None: extruder_manager.setActiveExtruderIndex(old_index) @@ -115,6 +125,9 @@ class MachineManager(QObject): Logger.log("w", "No variant found for printer definition %s with id %s" % (definition_id, variant_id)) def _hotendChangedDialogCallback(self, button, index, hotend_id): + self._auto_change_material_hotend_flood_time = time.time() + self._auto_change_material_hotend_flood_last_choice = button + Logger.log("d", "Setting hotend variant of hotend %d to %s" % (index, containers[0].getId())) extruder_manager = ExtruderManager.ExtruderManager.getInstance() @@ -147,9 +160,12 @@ class MachineManager(QObject): old_index = None if self.activeMaterialId != containers[0].getId(): - Application.getInstance().messageBox(catalog.i18nc("@window:title", "Changes on the Printer"), catalog.i18nc("@label", "Do you want to change the material to match the material in your printer?"), - catalog.i18nc("@label", "The material on your printer was changed. For best results always slice for the material that is inserted in your printer."), - buttons = QMessageBox.Yes + QMessageBox.No, icon = QMessageBox.Question, callback = self._materialIdChangedDialogCallback, callback_arguments = [index, containers[0].getId()]) + if time.time() - self._auto_change_material_hotend_flood_time > self._auto_change_material_hotend_flood_window: + Application.getInstance().messageBox(catalog.i18nc("@window:title", "Changes on the Printer"), catalog.i18nc("@label", "Do you want to change the material to match the material in your printer?"), + catalog.i18nc("@label", "The material on your printer was changed. For best results always slice for the material that is inserted in your printer."), + buttons = QMessageBox.Yes + QMessageBox.No, icon = QMessageBox.Question, callback = self._materialIdChangedDialogCallback, callback_arguments = [index, containers[0].getId()]) + else: + self._materialIdChangedDialogCallback(self._auto_change_material_hotend_flood_last_choice, index, containers[0].getId()) if old_index is not None: extruder_manager.setActiveExtruderIndex(old_index) @@ -157,6 +173,9 @@ class MachineManager(QObject): Logger.log("w", "No material definition found for printer definition %s and GUID %s" % (definition_id, material_id)) def _materialIdChangedDialogCallback(self, button, index, material_id): + self._auto_change_material_hotend_flood_time = time.time() + self._auto_change_material_hotend_flood_last_choice = button + Logger.log("d", "Setting material of hotend %d to %s" % (index, material_id)) extruder_manager = ExtruderManager.ExtruderManager.getInstance()