diff --git a/cura/Machines/Models/ExtrudersModel.py b/cura/Machines/Models/ExtrudersModel.py index f31f7c8717..872596dfab 100644 --- a/cura/Machines/Models/ExtrudersModel.py +++ b/cura/Machines/Models/ExtrudersModel.py @@ -2,7 +2,7 @@ # Cura is released under the terms of the LGPLv3 or higher. from PyQt6.QtCore import Qt, pyqtSignal, pyqtProperty, QTimer -from typing import Iterable, TYPE_CHECKING +from typing import Iterable, TYPE_CHECKING, Optional, Dict, Any from UM.i18n import i18nCatalog from UM.Qt.ListModel import ListModel @@ -104,6 +104,9 @@ class ExtrudersModel(ListModel): self.addOptionalExtruderChanged.emit() self._updateExtruders() + def getExtruderItem(self, extruder_index: int) -> Optional[Dict[str, Any]]: + return next((item for item in self.items if item["index"] == extruder_index), None) + @pyqtProperty(bool, fset = setAddOptionalExtruder, notify = addOptionalExtruderChanged) def addOptionalExtruder(self): return self._add_optional_extruder diff --git a/plugins/PaintTool/PaintView.py b/plugins/PaintTool/PaintView.py index 4a98fe8217..26dd19a25b 100644 --- a/plugins/PaintTool/PaintView.py +++ b/plugins/PaintTool/PaintView.py @@ -31,6 +31,8 @@ catalog = i18nCatalog("cura") class PaintView(CuraView): """View for model-painting.""" + MAX_EXTRUDER_COUNT = 16 + class PaintType: def __init__(self, display_color: Color, value: int): self.display_color: Color = display_color @@ -114,14 +116,17 @@ class PaintView(CuraView): def _makeExtrudersColors(self) -> Dict[str, "PaintView.PaintType"]: extruders_colors: Dict[str, "PaintView.PaintType"] = {} - for extruder_item in self._extruders_model.items: - if "color" in extruder_item: + for extruder_index in range(PaintView.MAX_EXTRUDER_COUNT): + extruder_item = self._extruders_model.getExtruderItem(extruder_index) + if extruder_item is None: + extruder_item = self._extruders_model.getExtruderItem(0) + + if extruder_item is not None and "color" in extruder_item: material_color = extruder_item["color"] else: material_color = self._extruders_model.defaultColors[0] - index = extruder_item["index"] - extruders_colors[str(index)] = self.PaintType(Color(*QColor(material_color).getRgb()), index) + extruders_colors[str(extruder_index)] = self.PaintType(Color(*QColor(material_color).getRgb()), extruder_index) return extruders_colors