Fix typing

This commit is contained in:
Lipu Fei 2019-04-02 07:43:41 +00:00
parent 31e20e78b6
commit dd19d7d1a9
4 changed files with 25 additions and 20 deletions

View File

@ -1,31 +1,33 @@
# Copyright (c) 2018 Ultimaker B.V. # Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
import math
import re
from typing import Dict, List, NamedTuple, Optional, Union
import numpy
from UM.Backend import Backend from UM.Backend import Backend
from UM.Job import Job from UM.Job import Job
from UM.Logger import Logger from UM.Logger import Logger
from UM.Math.Vector import Vector from UM.Math.Vector import Vector
from UM.Message import Message from UM.Message import Message
from cura.Scene.CuraSceneNode import CuraSceneNode
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
from cura.LayerDataBuilder import LayerDataBuilder from cura.LayerDataBuilder import LayerDataBuilder
from cura.LayerDataDecorator import LayerDataDecorator from cura.LayerDataDecorator import LayerDataDecorator
from cura.LayerPolygon import LayerPolygon from cura.LayerPolygon import LayerPolygon
from cura.Scene.CuraSceneNode import CuraSceneNode
from cura.Scene.GCodeListDecorator import GCodeListDecorator from cura.Scene.GCodeListDecorator import GCodeListDecorator
from cura.Settings.ExtruderManager import ExtruderManager from cura.Settings.ExtruderManager import ExtruderManager
import numpy catalog = i18nCatalog("cura")
import math
import re
from typing import Dict, List, NamedTuple, Optional, Union
PositionOptional = NamedTuple("Position", [("x", Optional[float]), ("y", Optional[float]), ("z", Optional[float]), ("f", Optional[float]), ("e", Optional[float])]) PositionOptional = NamedTuple("Position", [("x", Optional[float]), ("y", Optional[float]), ("z", Optional[float]), ("f", Optional[float]), ("e", Optional[float])])
Position = NamedTuple("Position", [("x", float), ("y", float), ("z", float), ("f", float), ("e", List[float])]) Position = NamedTuple("Position", [("x", float), ("y", float), ("z", float), ("f", float), ("e", List[float])])
## This parser is intended to interpret the common firmware codes among all the ## This parser is intended to interpret the common firmware codes among all the
# different flavors # different flavors
class FlavorParser: class FlavorParser:
@ -33,7 +35,7 @@ class FlavorParser:
def __init__(self) -> None: def __init__(self) -> None:
CuraApplication.getInstance().hideMessageSignal.connect(self._onHideMessage) CuraApplication.getInstance().hideMessageSignal.connect(self._onHideMessage)
self._cancelled = False self._cancelled = False
self._message = None self._message = None # type: Optional[Message]
self._layer_number = 0 self._layer_number = 0
self._extruder_number = 0 self._extruder_number = 0
self._clearValues() self._clearValues()
@ -425,6 +427,7 @@ class FlavorParser:
if line.startswith("M"): if line.startswith("M"):
M = self._getInt(line, "M") M = self._getInt(line, "M")
if M is not None:
self.processMCode(M, line, current_position, current_path) self.processMCode(M, line, current_position, current_path)
# "Flush" leftovers. Last layer paths are still stored # "Flush" leftovers. Last layer paths are still stored
@ -463,7 +466,7 @@ class FlavorParser:
Logger.log("w", "File doesn't contain any valid layers") Logger.log("w", "File doesn't contain any valid layers")
settings = CuraApplication.getInstance().getGlobalContainerStack() settings = CuraApplication.getInstance().getGlobalContainerStack()
if not settings.getProperty("machine_center_is_zero", "value"): if settings is not None and not settings.getProperty("machine_center_is_zero", "value"):
machine_width = settings.getProperty("machine_width", "value") machine_width = settings.getProperty("machine_width", "value")
machine_depth = settings.getProperty("machine_depth", "value") machine_depth = settings.getProperty("machine_depth", "value")
scene_node.setPosition(Vector(-machine_width / 2, 0, machine_depth / 2)) scene_node.setPosition(Vector(-machine_width / 2, 0, machine_depth / 2))

View File

@ -162,7 +162,7 @@ class PostProcessingPlugin(QObject, Extension):
loaded_script = importlib.util.module_from_spec(spec) loaded_script = importlib.util.module_from_spec(spec)
if spec.loader is None: if spec.loader is None:
continue continue
spec.loader.exec_module(loaded_script) spec.loader.exec_module(loaded_script) # type: ignore
sys.modules[script_name] = loaded_script #TODO: This could be a security risk. Overwrite any module with a user-provided name? sys.modules[script_name] = loaded_script #TODO: This could be a security risk. Overwrite any module with a user-provided name?
loaded_class = getattr(loaded_script, script_name) loaded_class = getattr(loaded_script, script_name)

View File

@ -85,10 +85,11 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
# We use the Cura Connect monitor tab to get most functionality right away. # We use the Cura Connect monitor tab to get most functionality right away.
if PluginRegistry.getInstance() is not None: if PluginRegistry.getInstance() is not None:
self._monitor_view_qml_path = os.path.join( plugin_path = PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting")
PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), if plugin_path is None:
"resources", "qml", "MonitorStage.qml" Logger.log("e", "Cloud not find plugin path for plugin UM3NetworkPrnting")
) raise RuntimeError("Cloud not find plugin path for plugin UM3NetworkPrnting")
self._monitor_view_qml_path = os.path.join(plugin_path, "resources", "qml", "MonitorStage.qml")
# Trigger the printersChanged signal when the private signal is triggered. # Trigger the printersChanged signal when the private signal is triggered.
self.printersChanged.connect(self._clusterPrintersChanged) self.printersChanged.connect(self._clusterPrintersChanged)

View File

@ -66,10 +66,11 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self._received_print_jobs = False # type: bool self._received_print_jobs = False # type: bool
if PluginRegistry.getInstance() is not None: if PluginRegistry.getInstance() is not None:
self._monitor_view_qml_path = os.path.join( plugin_path = PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting")
PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), if plugin_path is None:
"resources", "qml", "MonitorStage.qml" Logger.log("e", "Cloud not find plugin path for plugin UM3NetworkPrnting")
) raise RuntimeError("Cloud not find plugin path for plugin UM3NetworkPrnting")
self._monitor_view_qml_path = os.path.join(plugin_path, "resources", "qml", "MonitorStage.qml")
# Trigger the printersChanged signal when the private signal is triggered # Trigger the printersChanged signal when the private signal is triggered
self.printersChanged.connect(self._clusterPrintersChanged) self.printersChanged.connect(self._clusterPrintersChanged)