Load current machine's extruders upon creation, start and switch of machines

This requires some trickery of initialising the extruder manager before the machine manager is initialised, so that it properly listens to global container stack changes.

Contributes to issues CURA-340 and CURA-1278.
This commit is contained in:
Ghostkeeper 2016-06-07 17:37:25 +02:00
parent 98a0f90dae
commit 8b1c363932
No known key found for this signature in database
GPG key ID: 701948C5954A7385
3 changed files with 33 additions and 8 deletions

View file

@ -9,7 +9,8 @@ import UM.Qt.ListModel
## Model that holds extruders.
#
# This model is designed for use by any list of extruders, but specifically
# intended for drop-down lists of extruders in place of settings.
# intended for drop-down lists of the current machine's extruders in place of
# settings.
class ExtrudersModel(UM.Qt.ListModel.ListModel):
## Human-readable name of the extruder.
NameRole = Qt.UserRole + 1
@ -37,7 +38,8 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
#Listen to changes.
manager = cura.ExtruderManager.ExtruderManager.getInstance()
manager.extrudersChanged.connect(self._updateExtruders)
manager.extrudersChanged.connect(self._updateExtruders) #When the list of extruders changes in general.
UM.Application.globalContainerStackChanged.connect(self._updateExtruders) #When the current machine changes.
self._updateExtruders()
## Update the list of extruders.
@ -46,7 +48,10 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
def _updateExtruders(self):
self.clear()
manager = cura.ExtruderManager.ExtruderManager.getInstance()
for index, extruder in enumerate(manager._extruder_trains):
global_container_stack = UM.Application.getInstance().getGlobalContainerStack()
if not global_container_stack:
return #There is no machine to get the extruders of.
for index, extruder in manager.getMachineExtruders(global_container_stack.getBottom()):
item = { #Construct an item with only the relevant information.
"name": extruder.name,
"colour": extruder.material.getMetaDataEntry("color_code", default = "#FFFF00"),