Browse Source

Always update root material even if not in QML

Previously the _current_root_material_id and _current_root_material_name dictionaries were only updated if they are used anywhere in QML. This is unreliable. We're now directly connecting to the signal so that they are always updated, even when not in use by the GUI. This way we can rely on it in other places than the GUI.

Contributes to issue CURA-4606.
Ghostkeeper 7 years ago
parent
commit
a87db2d721
1 changed files with 11 additions and 7 deletions
  1. 11 7
      cura/Settings/MachineManager.py

+ 11 - 7
cura/Settings/MachineManager.py

@@ -125,6 +125,7 @@ class MachineManager(QObject):
         # When the materials lookup table gets updated, it can mean that a material has its name changed, which should
         # be reflected on the GUI. This signal emission makes sure that it happens.
         self._material_manager.materialsUpdated.connect(self.rootMaterialChanged)
+        self.rootMaterialChanged.connect(self._onRootMaterialChanged)
 
     activeQualityGroupChanged = pyqtSignal()
     activeQualityChangesGroupChanged = pyqtSignal()
@@ -876,23 +877,26 @@ class MachineManager(QObject):
     def currentExtruderPositions(self):
         return sorted(list(self._global_container_stack.extruders.keys()))
 
-    @pyqtProperty("QVariant", notify = rootMaterialChanged)
-    def currentRootMaterialId(self):
-        # initial filling the current_root_material_id
+    ##  Update _current_root_material_id and _current_root_material_name when
+    #   the current root material was changed.
+    def _onRootMaterialChanged(self):
         self._current_root_material_id = {}
         for position in self._global_container_stack.extruders:
             self._current_root_material_id[position] = self._global_container_stack.extruders[position].material.getMetaDataEntry("base_file")
-        return self._current_root_material_id
 
-    @pyqtProperty("QVariant", notify = rootMaterialChanged)
-    def currentRootMaterialName(self):
-        # initial filling the current_root_material_name
         if self._global_container_stack:
             self._current_root_material_name = {}
             for position in self._global_container_stack.extruders:
                 if position not in self._current_root_material_name:
                     material = self._global_container_stack.extruders[position].material
                     self._current_root_material_name[position] = material.getName()
+
+    @pyqtProperty("QVariant", notify = rootMaterialChanged)
+    def currentRootMaterialId(self):
+        return self._current_root_material_id
+
+    @pyqtProperty("QVariant", notify = rootMaterialChanged)
+    def currentRootMaterialName(self):
         return self._current_root_material_name
 
     ##  Return the variant names in the extruder stack(s).