Add deprecated marker on extruders: Use extruderList

Extruders is dangerous because it's a dict of which the values are randomly ordered. The keys are often cast to int so you can't use anything else than integer numbers. And then they are often cast back so if you're not properly counting from 0 you're also in trouble. So please, only use the list. Eventually we can switch the data structure around.
This commit is contained in:
Ghostkeeper 2019-09-09 14:21:28 +02:00
parent 8c893caf9f
commit eb401defdf
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276

View file

@ -1,4 +1,4 @@
# Copyright (c) 2018 Ultimaker B.V.
# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from collections import defaultdict
@ -8,7 +8,7 @@ import uuid
from PyQt5.QtCore import pyqtProperty, pyqtSlot, pyqtSignal
from UM.Decorators import override
from UM.Decorators import deprecated, override
from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
from UM.Settings.ContainerStack import ContainerStack
from UM.Settings.SettingInstance import InstanceState
@ -61,12 +61,13 @@ class GlobalStack(CuraContainerStack):
#
# \return The extruders registered with this stack.
@pyqtProperty("QVariantMap", notify = extrudersChanged)
@deprecated("Please use extruderList instead.", "4.4")
def extruders(self) -> Dict[str, "ExtruderStack"]:
return self._extruders
@pyqtProperty("QVariantList", notify = extrudersChanged)
def extruderList(self) -> List["ExtruderStack"]:
result_tuple_list = sorted(list(self.extruders.items()), key=lambda x: int(x[0]))
result_tuple_list = sorted(list(self._extruders.items()), key=lambda x: int(x[0]))
result_list = [item[1] for item in result_tuple_list]
machine_extruder_count = self.getProperty("machine_extruder_count", "value")