Browse Source

Move getDefaultFirmwareName() into GlobalStack

fieldOfView 6 years ago
parent
commit
bc52830c89

+ 28 - 1
cura/Settings/GlobalStack.py

@@ -4,7 +4,7 @@
 from collections import defaultdict
 import threading
 from typing import Any, Dict, Optional, Set, TYPE_CHECKING
-from PyQt5.QtCore import pyqtProperty
+from PyQt5.QtCore import pyqtProperty, pyqtSlot
 
 from UM.Decorators import override
 from UM.MimeTypeDatabase import MimeType, MimeTypeDatabase
@@ -13,6 +13,8 @@ from UM.Settings.SettingInstance import InstanceState
 from UM.Settings.ContainerRegistry import ContainerRegistry
 from UM.Settings.Interfaces import PropertyEvaluationContext
 from UM.Logger import Logger
+from UM.Resources import Resources
+from UM.Platform import Platform
 from UM.Util import parseBool
 
 import cura.CuraApplication
@@ -200,6 +202,31 @@ class GlobalStack(CuraContainerStack):
     def getHasMachineQuality(self) -> bool:
         return parseBool(self.getMetaDataEntry("has_machine_quality", False))
 
+    ##  Get default firmware file name if one is specified in the firmware
+    @pyqtSlot(result = str)
+    def getDefaultFirmwareName(self) -> str:
+        machine_has_heated_bed = self.getProperty("machine_heated_bed", "value")
+
+        baudrate = 250000
+        if Platform.isLinux():
+            # Linux prefers a baudrate of 115200 here because older versions of
+            # pySerial did not support a baudrate of 250000
+            baudrate = 115200
+
+        # If a firmware file is available, it should be specified in the definition for the printer
+        hex_file = self.getMetaDataEntry("firmware_file", None)
+        if machine_has_heated_bed:
+            hex_file = self.getMetaDataEntry("firmware_hbk_file", hex_file)
+
+        if hex_file:
+            try:
+                return Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.Firmware, hex_file.format(baudrate=baudrate))
+            except FileNotFoundError:
+                Logger.log("w", "Firmware file %s not found.", hex_file)
+                return ""
+        else:
+            Logger.log("w", "There is no firmware for machine %s.", self.getBottom().id)
+            return ""
 
 ## private:
 global_stack_mime = MimeType(

+ 0 - 32
cura/Settings/MachineManager.py

@@ -10,7 +10,6 @@ from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
 from UM.Settings.InstanceContainer import InstanceContainer
 from UM.Settings.Interfaces import ContainerInterface
 from UM.Signal import Signal
-from UM.Platform import Platform
 
 from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QTimer
 from UM.FlameProfiler import pyqtSlot
@@ -1540,34 +1539,3 @@ class MachineManager(QObject):
         with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
             self.updateMaterialWithVariant(None)
             self._updateQualityWithMaterial()
-
-    ##  Get default firmware file name if one is specified in the firmware
-    @pyqtSlot(result = str)
-    def getDefaultFirmwareName(self) -> str:
-        # Check if there is a valid global container stack
-        if not self._global_container_stack:
-            return ""
-
-        # The bottom of the containerstack is the machine definition
-        machine_has_heated_bed = self._global_container_stack.getProperty("machine_heated_bed", "value")
-
-        baudrate = 250000
-        if Platform.isLinux():
-            # Linux prefers a baudrate of 115200 here because older versions of
-            # pySerial did not support a baudrate of 250000
-            baudrate = 115200
-
-        # If a firmware file is available, it should be specified in the definition for the printer
-        hex_file = self._global_container_stack.getMetaDataEntry("firmware_file", None)
-        if machine_has_heated_bed:
-            hex_file = self._global_container_stack.getMetaDataEntry("firmware_hbk_file", hex_file)
-
-        if hex_file:
-            try:
-                return Resources.getPath(cura.CuraApplication.CuraApplication.ResourceTypes.Firmware, hex_file.format(baudrate=baudrate))
-            except FileNotFoundError:
-                Logger.log("w", "Firmware file %s not found.", hex_file)
-                return ""
-        else:
-            Logger.log("w", "There is no firmware for machine %s.", self._global_container_stack.getBottom().id)
-            return ""

+ 1 - 1
plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml

@@ -51,7 +51,7 @@ Cura.MachineAction
             anchors.horizontalCenter: parent.horizontalCenter
             width: childrenRect.width
             spacing: UM.Theme.getSize("default_margin").width
-            property var firmwareName: Cura.MachineManager.getDefaultFirmwareName()
+            property var firmwareName: Cura.MachineManager.activeMachine.getDefaultFirmwareName()
             Button
             {
                 id: autoUpgradeButton