mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 07:33:57 -06:00
Apply a flood control on messages about materials/hotends changed on the printer
CURA-1850
This commit is contained in:
parent
c129b4b8b5
commit
bf529c6425
1 changed files with 25 additions and 6 deletions
|
@ -17,6 +17,8 @@ from . import ExtruderManager
|
||||||
from UM.i18n import i18nCatalog
|
from UM.i18n import i18nCatalog
|
||||||
catalog = i18nCatalog("cura")
|
catalog = i18nCatalog("cura")
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
class MachineManager(QObject):
|
class MachineManager(QObject):
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
@ -60,6 +62,10 @@ class MachineManager(QObject):
|
||||||
self.setActiveMachine(active_machine_id)
|
self.setActiveMachine(active_machine_id)
|
||||||
pass
|
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()
|
globalContainerChanged = pyqtSignal()
|
||||||
activeMaterialChanged = pyqtSignal()
|
activeMaterialChanged = pyqtSignal()
|
||||||
activeVariantChanged = 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)
|
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = self._global_container_stack.getBottom().getId(), name = hotend_id)
|
||||||
if containers:
|
if containers:
|
||||||
|
extruder_manager = ExtruderManager.ExtruderManager.getInstance()
|
||||||
old_index = extruder_manager.activeExtruderIndex
|
old_index = extruder_manager.activeExtruderIndex
|
||||||
if old_index != index:
|
if old_index != index:
|
||||||
extruder_manager.setActiveExtruderIndex(index)
|
extruder_manager.setActiveExtruderIndex(index)
|
||||||
|
@ -105,9 +112,12 @@ class MachineManager(QObject):
|
||||||
old_index = None
|
old_index = None
|
||||||
|
|
||||||
if self.activeVariantId != containers[0].getId():
|
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?"),
|
if time.time() - self._auto_change_material_hotend_flood_time > self._auto_change_material_hotend_flood_window:
|
||||||
catalog.i18nc("@label", "The hotend on your printer was changed. For best results always slice for the hotend that is inserted in your printer."),
|
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?"),
|
||||||
buttons = QMessageBox.Yes + QMessageBox.No, icon = QMessageBox.Question, callback = self._hotendChangedDialogCallback, callback_arguments = [index, containers[0].getId()])
|
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:
|
if old_index is not None:
|
||||||
extruder_manager.setActiveExtruderIndex(old_index)
|
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))
|
Logger.log("w", "No variant found for printer definition %s with id %s" % (definition_id, variant_id))
|
||||||
|
|
||||||
def _hotendChangedDialogCallback(self, button, index, hotend_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()))
|
Logger.log("d", "Setting hotend variant of hotend %d to %s" % (index, containers[0].getId()))
|
||||||
|
|
||||||
extruder_manager = ExtruderManager.ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.ExtruderManager.getInstance()
|
||||||
|
@ -147,9 +160,12 @@ class MachineManager(QObject):
|
||||||
old_index = None
|
old_index = None
|
||||||
|
|
||||||
if self.activeMaterialId != containers[0].getId():
|
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?"),
|
if time.time() - self._auto_change_material_hotend_flood_time > self._auto_change_material_hotend_flood_window:
|
||||||
catalog.i18nc("@label", "The material on your printer was changed. For best results always slice for the material that is inserted in your printer."),
|
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?"),
|
||||||
buttons = QMessageBox.Yes + QMessageBox.No, icon = QMessageBox.Question, callback = self._materialIdChangedDialogCallback, callback_arguments = [index, containers[0].getId()])
|
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:
|
if old_index is not None:
|
||||||
extruder_manager.setActiveExtruderIndex(old_index)
|
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))
|
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):
|
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))
|
Logger.log("d", "Setting material of hotend %d to %s" % (index, material_id))
|
||||||
|
|
||||||
extruder_manager = ExtruderManager.ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.ExtruderManager.getInstance()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue