Browse Source

Merge pull request #4028 from Ultimaker/fix_style

Fix code style
Mark 6 years ago
parent
commit
183cd0182d

+ 3 - 0
plugins/GCodeReader/FlavorParser.py

@@ -286,6 +286,9 @@ class FlavorParser:
         self._cancelled = False
         # We obtain the filament diameter from the selected extruder to calculate line widths
         global_stack = CuraApplication.getInstance().getGlobalContainerStack()
+        if not global_stack:
+            return None
+
         self._filament_diameter = global_stack.extruders[str(self._extruder_number)].getProperty("material_diameter", "value")
 
         scene_node = CuraSceneNode()

+ 9 - 1
plugins/Toolbox/src/Toolbox.py

@@ -224,6 +224,11 @@ class Toolbox(QObject, Extension):
 
         if not self._dialog:
             self._dialog = self._createDialog("Toolbox.qml")
+
+        if not self._dialog:
+            Logger.log("e", "Unexpected error trying to create the 'Toolbox' dialog.")
+            return
+
         self._dialog.show()
 
         # Apply enabled/disabled state to installed plugins
@@ -231,7 +236,10 @@ class Toolbox(QObject, Extension):
 
     def _createDialog(self, qml_name: str) -> Optional[QObject]:
         Logger.log("d", "Toolbox: Creating dialog [%s].", qml_name)
-        path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "resources", "qml", qml_name)
+        plugin_path = PluginRegistry.getInstance().getPluginPath(self.getPluginId())
+        if not plugin_path:
+            return None
+        path = os.path.join(plugin_path, "resources", "qml", qml_name)
         dialog = self._application.createQmlComponent(path, {"toolbox": self})
         return dialog
 

+ 13 - 2
plugins/UM3NetworkPrinting/ClusterUM3OutputDevice.py

@@ -103,8 +103,12 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
         else:
             file_formats = CuraApplication.getInstance().getMeshFileHandler().getSupportedFileTypesWrite()
 
+        global_stack = CuraApplication.getInstance().getGlobalContainerStack()
+        if not global_stack:
+            return
+
         #Create a list from the supported file formats string.
-        machine_file_formats = CuraApplication.getInstance().getGlobalContainerStack().getMetaDataEntry("file_formats").split(";")
+        machine_file_formats = global_stack.getMetaDataEntry("file_formats").split(";")
         machine_file_formats = [file_type.strip() for file_type in machine_file_formats]
         #Exception for UM3 firmware version >=4.4: UFP is now supported and should be the preferred file format.
         if "application/x-ufp" not in machine_file_formats and self.printerType == "ultimaker3" and Version(self.firmwareVersion) >= Version("4.4"):
@@ -125,6 +129,10 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
         else:
             writer = CuraApplication.getInstance().getMeshFileHandler().getWriterByMimeType(cast(str, preferred_format["mime_type"]))
 
+        if not writer:
+            Logger.log("e", "Unexpected error when trying to get the FileWriter")
+            return
+
         #This function pauses with the yield, waiting on instructions on which printer it needs to print with.
         self._sending_job = self._sendPrintJob(writer, preferred_format, nodes)
         self._sending_job.send(None) #Start the generator.
@@ -205,6 +213,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
         yield #To prevent having to catch the StopIteration exception.
 
     def _sendPrintJobWaitOnWriteJobFinished(self, job: WriteFileJob) -> None:
+        # This is the callback when the job finishes, where the message is created
+        assert(self._write_job_progress_message is not None)
         self._write_job_progress_message.hide()
 
         self._progress_message = Message(i18n_catalog.i18nc("@info:status", "Sending data to printer"), lifetime = 0, dismissable = False, progress = -1,
@@ -249,7 +259,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
             self.activePrinterChanged.emit()
 
     def _onPostPrintJobFinished(self, reply: QNetworkReply) -> None:
-        self._progress_message.hide()
+        if self._progress_message is not None:
+            self._progress_message.hide()
         self._compressing_gcode = False
         self._sending_gcode = False
 

+ 4 - 1
plugins/UM3NetworkPrinting/DiscoverUM3Action.py

@@ -170,7 +170,10 @@ class DiscoverUM3Action(MachineAction):
         Logger.log("d", "Creating additional ui components for UM3.")
 
         # Create networking dialog
-        path = os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.qml")
+        plugin_path = PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting")
+        if not plugin_path:
+            return
+        path = os.path.join(plugin_path, "UM3InfoComponents.qml")
         self.__additional_components_view = CuraApplication.getInstance().createQmlComponent(path, {"manager": self})
         if not self.__additional_components_view:
             Logger.log("w", "Could not create ui components for UM3.")

+ 1 - 1
plugins/UM3NetworkPrinting/SendMaterialJob.py

@@ -23,7 +23,7 @@ if TYPE_CHECKING:
 #
 #   This way it won't freeze up the interface while sending those materials.
 class SendMaterialJob(Job):
-    def __init__(self, device: "ClusterUM3OutputDevice"):
+    def __init__(self, device: "ClusterUM3OutputDevice") -> None:
         super().__init__()
         self.device = device #type: ClusterUM3OutputDevice
 

+ 2 - 1
plugins/X3DReader/X3DReader.py

@@ -2,6 +2,7 @@
 # Cura is released under the terms of the LGPLv3 or higher.
 
 from math import pi, sin, cos, sqrt
+from typing import Dict
 
 import numpy
 
@@ -42,7 +43,7 @@ class X3DReader(MeshReader):
     def __init__(self) -> None:
         super().__init__()
         self._supported_extensions = [".x3d"]
-        self._namespaces = {}
+        self._namespaces = {}   # type: Dict[str, str]
 
     # Main entry point
     # Reads the file, returns a SceneNode (possibly with nested ones), or None