diff --git a/cura/Arranging/Arrange.py b/cura/Arranging/Arrange.py
index c0aca9a893..a99e747c48 100644
--- a/cura/Arranging/Arrange.py
+++ b/cura/Arranging/Arrange.py
@@ -173,7 +173,10 @@ class Arrange:
def bestSpot(self, shape_arr, start_prio = 0, step = 1):
start_idx_list = numpy.where(self._priority_unique_values == start_prio)
if start_idx_list:
- start_idx = start_idx_list[0][0]
+ try:
+ start_idx = start_idx_list[0][0]
+ except IndexError:
+ start_idx = 0
else:
start_idx = 0
for priority in self._priority_unique_values[start_idx::step]:
diff --git a/cura/Machines/Models/QualitySettingsModel.py b/cura/Machines/Models/QualitySettingsModel.py
index 6835ffb68f..8a956263e7 100644
--- a/cura/Machines/Models/QualitySettingsModel.py
+++ b/cura/Machines/Models/QualitySettingsModel.py
@@ -2,6 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, pyqtSignal, Qt
+from typing import Set
import cura.CuraApplication
from UM.Logger import Logger
@@ -23,7 +24,7 @@ class QualitySettingsModel(ListModel):
GLOBAL_STACK_POSITION = -1
- def __init__(self, parent = None):
+ def __init__(self, parent = None) -> None:
super().__init__(parent = parent)
self.addRoleName(self.KeyRole, "key")
@@ -38,7 +39,9 @@ class QualitySettingsModel(ListModel):
self._application = cura.CuraApplication.CuraApplication.getInstance()
self._application.getMachineManager().activeStackChanged.connect(self._update)
- self._selected_position = self.GLOBAL_STACK_POSITION #Must be either GLOBAL_STACK_POSITION or an extruder position (0, 1, etc.)
+ # Must be either GLOBAL_STACK_POSITION or an extruder position (0, 1, etc.)
+ self._selected_position = self.GLOBAL_STACK_POSITION
+
self._selected_quality_item = None # The selected quality in the quality management page
self._i18n_catalog = None
@@ -47,14 +50,14 @@ class QualitySettingsModel(ListModel):
selectedPositionChanged = pyqtSignal()
selectedQualityItemChanged = pyqtSignal()
- def setSelectedPosition(self, selected_position):
+ def setSelectedPosition(self, selected_position: int) -> None:
if selected_position != self._selected_position:
self._selected_position = selected_position
self.selectedPositionChanged.emit()
self._update()
@pyqtProperty(int, fset = setSelectedPosition, notify = selectedPositionChanged)
- def selectedPosition(self):
+ def selectedPosition(self) -> int:
return self._selected_position
def setSelectedQualityItem(self, selected_quality_item):
@@ -67,7 +70,7 @@ class QualitySettingsModel(ListModel):
def selectedQualityItem(self):
return self._selected_quality_item
- def _update(self):
+ def _update(self) -> None:
Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
if not self._selected_quality_item:
@@ -83,7 +86,7 @@ class QualitySettingsModel(ListModel):
quality_changes_group = self._selected_quality_item["quality_changes_group"]
quality_node = None
- settings_keys = set()
+ settings_keys = set() # type: Set[str]
if quality_group:
if self._selected_position == self.GLOBAL_STACK_POSITION:
quality_node = quality_group.node_for_global
diff --git a/cura/Scene/ConvexHullDecorator.py b/cura/Scene/ConvexHullDecorator.py
index 2a160f6069..b5f5fb4540 100644
--- a/cura/Scene/ConvexHullDecorator.py
+++ b/cura/Scene/ConvexHullDecorator.py
@@ -36,8 +36,10 @@ class ConvexHullDecorator(SceneNodeDecorator):
# Make sure the timer is created on the main thread
self._recompute_convex_hull_timer = None # type: Optional[QTimer]
+ self._timer_scheduled_to_be_created = False
from cura.CuraApplication import CuraApplication
if CuraApplication.getInstance() is not None:
+ self._timer_scheduled_to_be_created = True
CuraApplication.getInstance().callLater(self.createRecomputeConvexHullTimer)
self._raft_thickness = 0.0
@@ -171,7 +173,12 @@ class ConvexHullDecorator(SceneNodeDecorator):
if self._recompute_convex_hull_timer is not None:
self._recompute_convex_hull_timer.start()
else:
- self.recomputeConvexHull()
+ from cura.CuraApplication import CuraApplication
+ if not self._timer_scheduled_to_be_created:
+ # The timer is not created and we never scheduled it. Time to create it now!
+ CuraApplication.getInstance().callLater(self.createRecomputeConvexHullTimer)
+ # Now we know for sure that the timer has been scheduled for creation, so we can try this again.
+ CuraApplication.getInstance().callLater(self.recomputeConvexHullDelayed)
def recomputeConvexHull(self) -> None:
controller = Application.getInstance().getController()
diff --git a/cura/Settings/CuraStackBuilder.py b/cura/Settings/CuraStackBuilder.py
index 61a04e1be6..c8287696ae 100644
--- a/cura/Settings/CuraStackBuilder.py
+++ b/cura/Settings/CuraStackBuilder.py
@@ -58,7 +58,10 @@ class CuraStackBuilder:
# Create ExtruderStacks
extruder_dict = machine_definition.getMetaDataEntry("machine_extruder_trains")
for position in extruder_dict:
- cls.createExtruderStackWithDefaultSetup(new_global_stack, position)
+ try:
+ cls.createExtruderStackWithDefaultSetup(new_global_stack, position)
+ except IndexError:
+ return None
for new_extruder in new_global_stack.extruders.values(): # Only register the extruders if we're sure that all of them are correct.
registry.addContainer(new_extruder)
diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py
index 25152b3d5b..6b1460b17b 100755
--- a/cura/Settings/MachineManager.py
+++ b/cura/Settings/MachineManager.py
@@ -320,8 +320,19 @@ class MachineManager(QObject):
# This signal might not have been emitted yet (if it didn't change) but we still want the models to update that depend on it because we changed the contents of the containers too.
extruder_manager.activeExtruderChanged.emit()
+ # Validate if the machine has the correct variants
+ # It can happen that a variant is empty, even though the machine has variants. This will ensure that that
+ # that situation will be fixed (and not occur again, since it switches it out to the preferred variant instead!)
+ machine_node = ContainerTree.getInstance().machines[global_stack.definition.getId()]
+ for extruder in self._global_container_stack.extruderList:
+ variant_name = self._global_container_stack.variant.getName()
+ variant_node = machine_node.variants.get(variant_name)
+ if variant_node is None:
+ Logger.log("w", "An extruder has an unknown variant, switching it to the preferred variant")
+ self.setVariantByName(extruder.getMetaDataEntry("position"), machine_node.preferred_variant_name)
self.__emitChangedSignals()
+
## Given a definition id, return the machine with this id.
# Optional: add a list of keys and values to filter the list of machines with the given definition id
# \param definition_id \type{str} definition id that needs to look for
@@ -336,9 +347,9 @@ class MachineManager(QObject):
return cast(GlobalStack, machine)
return None
- @pyqtSlot(str)
- @pyqtSlot(str, str)
- def addMachine(self, definition_id: str, name: Optional[str] = None) -> None:
+ @pyqtSlot(str, result=bool)
+ @pyqtSlot(str, str, result = bool)
+ def addMachine(self, definition_id: str, name: Optional[str] = None) -> bool:
Logger.log("i", "Trying to add a machine with the definition id [%s]", definition_id)
if name is None:
definitions = CuraContainerRegistry.getInstance().findDefinitionContainers(id = definition_id)
@@ -353,6 +364,8 @@ class MachineManager(QObject):
self.setActiveMachine(new_stack.getId())
else:
Logger.log("w", "Failed creating a new machine!")
+ return False
+ return True
def _checkStacksHaveErrors(self) -> bool:
time_start = time.time()
@@ -1507,7 +1520,13 @@ class MachineManager(QObject):
if quality_id == empty_quality_container.getId():
extruder.intent = empty_intent_container
continue
- quality_node = container_tree.machines[definition_id].variants[variant_name].materials[material_base_file].qualities[quality_id]
+
+ # Yes, we can find this in a single line of code. This makes it easier to read and it has the benefit
+ # that it doesn't lump key errors together for the crashlogs
+ machine_node = container_tree.machines[definition_id]
+ variant_node = machine_node.variants[variant_name]
+ material_node = variant_node.materials[material_base_file]
+ quality_node = material_node.qualities[quality_id]
for intent_node in quality_node.intents.values():
if intent_node.intent_category == intent_category: # Found an intent with the correct category.
diff --git a/plugins/ModelChecker/ModelChecker.py b/plugins/ModelChecker/ModelChecker.py
index 0afed28f19..00e87139d5 100644
--- a/plugins/ModelChecker/ModelChecker.py
+++ b/plugins/ModelChecker/ModelChecker.py
@@ -73,6 +73,8 @@ class ModelChecker(QObject, Extension):
# Check node material shrinkage and bounding box size
for node in self.sliceableNodes():
node_extruder_position = node.callDecoration("getActiveExtruderPosition")
+ if node_extruder_position is None:
+ continue
# This function can be triggered in the middle of a machine change, so do not proceed if the machine change
# has not done yet.
diff --git a/plugins/PostProcessingPlugin/PostProcessingPlugin.qml b/plugins/PostProcessingPlugin/PostProcessingPlugin.qml
index cd8303d1d3..f94c0a1cca 100644
--- a/plugins/PostProcessingPlugin/PostProcessingPlugin.qml
+++ b/plugins/PostProcessingPlugin/PostProcessingPlugin.qml
@@ -484,15 +484,53 @@ UM.Dialog
onClicked: dialog.accept()
}
- Cura.SecondaryButton
+ Item
{
objectName: "postProcessingSaveAreaButton"
visible: activeScriptsList.count > 0
height: UM.Theme.getSize("action_button").height
width: height
- tooltip: catalog.i18nc("@info:tooltip", "Change active post-processing scripts")
- onClicked: dialog.show()
- iconSource: "postprocessing.svg"
- fixedWidthMode: true
+
+ Cura.SecondaryButton
+ {
+ height: UM.Theme.getSize("action_button").height
+ tooltip:
+ {
+ var tipText = catalog.i18nc("@info:tooltip", "Change active post-processing scripts.");
+ if (activeScriptsList.count > 0)
+ {
+ tipText += "
" + catalog.i18ncp("@info:tooltip",
+ "The following script is active:",
+ "The following scripts are active:",
+ activeScriptsList.count
+ ) + "