diff --git a/cura/PrinterOutput/FirmwareUpdater.py b/cura/PrinterOutput/FirmwareUpdater.py index 92e92437ad..c6d9513ee0 100644 --- a/cura/PrinterOutput/FirmwareUpdater.py +++ b/cura/PrinterOutput/FirmwareUpdater.py @@ -22,16 +22,16 @@ class FirmwareUpdater(QObject): self._update_firmware_thread = Thread(target=self._updateFirmware, daemon=True) - self._firmware_location = "" + self._firmware_file = "" self._firmware_progress = 0 self._firmware_update_state = FirmwareUpdateState.idle - def updateFirmware(self, file: Union[str, QUrl]) -> None: + def updateFirmware(self, firmware_file: Union[str, QUrl]) -> None: # the file path could be url-encoded. - if file.startswith("file://"): - self._firmware_location = QUrl(file).toLocalFile() + if firmware_file.startswith("file://"): + self._firmware_file = QUrl(firmware_file).toLocalFile() else: - self._firmware_location = file + self._firmware_file = firmware_file self._setFirmwareUpdateState(FirmwareUpdateState.updating) @@ -44,26 +44,26 @@ class FirmwareUpdater(QObject): def _cleanupAfterUpdate(self) -> None: # Clean up for next attempt. self._update_firmware_thread = Thread(target=self._updateFirmware, daemon=True) - self._firmware_location = "" + self._firmware_file = "" self._onFirmwareProgress(100) self._setFirmwareUpdateState(FirmwareUpdateState.completed) - @pyqtProperty(float, notify = firmwareProgressChanged) - def firmwareProgress(self) -> float: + @pyqtProperty(int, notify = firmwareProgressChanged) + def firmwareProgress(self) -> int: return self._firmware_progress @pyqtProperty(int, notify=firmwareUpdateStateChanged) def firmwareUpdateState(self) -> "FirmwareUpdateState": return self._firmware_update_state - def _setFirmwareUpdateState(self, state) -> None: + def _setFirmwareUpdateState(self, state: "FirmwareUpdateState") -> None: if self._firmware_update_state != state: self._firmware_update_state = state self.firmwareUpdateStateChanged.emit() # Callback function for firmware update progress. - def _onFirmwareProgress(self, progress, max_progress = 100) -> None: - self._firmware_progress = (progress / max_progress) * 100 # Convert to scale of 0-100 + def _onFirmwareProgress(self, progress: int, max_progress: int = 100) -> None: + self._firmware_progress = int(progress * 100 / max_progress) # Convert to scale of 0-100 self.firmwareProgressChanged.emit() diff --git a/cura/PrinterOutput/GenericOutputController.py b/cura/PrinterOutput/GenericOutputController.py index 9434feea62..c538ae79f8 100644 --- a/cura/PrinterOutput/GenericOutputController.py +++ b/cura/PrinterOutput/GenericOutputController.py @@ -20,15 +20,15 @@ class GenericOutputController(PrinterOutputController): self._preheat_bed_timer = QTimer() self._preheat_bed_timer.setSingleShot(True) self._preheat_bed_timer.timeout.connect(self._onPreheatBedTimerFinished) - self._preheat_printer = None #type: Optional[PrinterOutputModel] + self._preheat_printer = None # type: Optional[PrinterOutputModel] self._preheat_hotends_timer = QTimer() self._preheat_hotends_timer.setSingleShot(True) self._preheat_hotends_timer.timeout.connect(self._onPreheatHotendsTimerFinished) - self._preheat_hotends = set() #type: Set[ExtruderOutputModel] + self._preheat_hotends = set() # type: Set[ExtruderOutputModel] self._output_device.printersChanged.connect(self._onPrintersChanged) - self._active_printer = None #type: Optional[PrinterOutputModel] + self._active_printer = None # type: Optional[PrinterOutputModel] def _onPrintersChanged(self) -> None: if self._active_printer: @@ -54,7 +54,7 @@ class GenericOutputController(PrinterOutputController): self._preheat_hotends_timer.stop() for extruder in self._preheat_hotends: extruder.updateIsPreheating(False) - self._preheat_hotends = set() #type: Set[ExtruderOutputModel] + self._preheat_hotends = set() # type: Set[ExtruderOutputModel] def moveHead(self, printer: "PrinterOutputModel", x, y, z, speed) -> None: self._output_device.sendCommand("G91") diff --git a/cura/PrinterOutput/PrintJobOutputModel.py b/cura/PrinterOutput/PrintJobOutputModel.py index 70878a7573..1415db16bd 100644 --- a/cura/PrinterOutput/PrintJobOutputModel.py +++ b/cura/PrinterOutput/PrintJobOutputModel.py @@ -91,7 +91,7 @@ class PrintJobOutputModel(QObject): def assignedPrinter(self): return self._assigned_printer - def updateAssignedPrinter(self, assigned_printer: Optional["PrinterOutputModel"]): + def updateAssignedPrinter(self, assigned_printer: Optional["PrinterOutputModel"]) -> None: if self._assigned_printer != assigned_printer: old_printer = self._assigned_printer self._assigned_printer = assigned_printer diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index c63f9c35b5..236b658eba 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -4,7 +4,7 @@ from UM.Decorators import deprecated from UM.i18n import i18nCatalog from UM.OutputDevice.OutputDevice import OutputDevice -from PyQt5.QtCore import pyqtProperty, QObject, QTimer, pyqtSignal +from PyQt5.QtCore import pyqtProperty, pyqtSignal, QObject, QTimer, QUrl from PyQt5.QtWidgets import QMessageBox from UM.Logger import Logger @@ -12,9 +12,10 @@ from UM.FileHandler.FileHandler import FileHandler #For typing. from UM.Scene.SceneNode import SceneNode #For typing. from UM.Signal import signalemitter from UM.Qt.QtApplication import QtApplication +from UM.FlameProfiler import pyqtSlot from enum import IntEnum # For the connection state tracking. -from typing import Callable, List, Optional +from typing import Callable, List, Optional, Union MYPY = False if MYPY: @@ -230,4 +231,11 @@ class PrinterOutputDevice(QObject, OutputDevice): return self._firmware_name def getFirmwareUpdater(self) -> Optional["FirmwareUpdater"]: - return self._firmware_updater \ No newline at end of file + return self._firmware_updater + + @pyqtSlot(str) + def updateFirmware(self, firmware_file: Union[str, QUrl]) -> None: + if not self._firmware_updater: + return + + self._firmware_updater.updateFirmware(firmware_file) \ No newline at end of file diff --git a/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.py b/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.py index 981fb819eb..0a3e3a0ff0 100644 --- a/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.py +++ b/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.py @@ -15,6 +15,7 @@ MYPY = False if MYPY: from cura.PrinterOutput.FirmwareUpdater import FirmwareUpdater from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice + from UM.Settings.ContainerInterface import ContainerInterface catalog = i18nCatalog("cura") @@ -25,15 +26,15 @@ class FirmwareUpdaterMachineAction(MachineAction): self._qml_url = "FirmwareUpdaterMachineAction.qml" ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded) - self._active_output_device = None #type: Optional[PrinterOutputDevice] - self._active_firmware_updater = None #type: Optional[FirmwareUpdater] + self._active_output_device = None # type: Optional[PrinterOutputDevice] + self._active_firmware_updater = None # type: Optional[FirmwareUpdater] CuraApplication.getInstance().engineCreatedSignal.connect(self._onEngineCreated) def _onEngineCreated(self) -> None: CuraApplication.getInstance().getMachineManager().outputDevicesChanged.connect(self._onOutputDevicesChanged) - def _onContainerAdded(self, container) -> None: + def _onContainerAdded(self, container: "ContainerInterface") -> None: # Add this action as a supported action to all machine definitions if they support USB connection if isinstance(container, DefinitionContainer) and container.getMetaDataEntry("type") == "machine" and container.getMetaDataEntry("supports_usb_connection"): CuraApplication.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey()) diff --git a/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml b/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml index ab5bb89347..9a56dbb20a 100644 --- a/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml +++ b/plugins/FirmwareUpdater/FirmwareUpdaterMachineAction.qml @@ -16,7 +16,7 @@ Cura.MachineAction anchors.fill: parent; property bool printerConnected: Cura.MachineManager.printerConnected property var activeOutputDevice: printerConnected ? Cura.MachineManager.printerOutputDevices[0] : null - property var canUpdateFirmware: activeOutputDevice ? activeOutputDevice.activePrinter.canUpdateFirmware : false + property bool canUpdateFirmware: activeOutputDevice ? activeOutputDevice.activePrinter.canUpdateFirmware : false Column { @@ -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.activeMachine.getDefaultFirmwareName() + property string firmwareName: Cura.MachineManager.activeMachine.getDefaultFirmwareName() Button { id: autoUpgradeButton diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index 1fd2fdeb5c..b5ada76e6c 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -15,8 +15,6 @@ from cura.PrinterOutput.GenericOutputController import GenericOutputController from .AutoDetectBaudJob import AutoDetectBaudJob from .AvrFirmwareUpdater import AvrFirmwareUpdater -from PyQt5.QtCore import pyqtSlot, pyqtSignal, pyqtProperty, QUrl - from serial import Serial, SerialException, SerialTimeoutException from threading import Thread, Event from time import time, sleep @@ -98,13 +96,6 @@ class USBPrinterOutputDevice(PrinterOutputDevice): application = CuraApplication.getInstance() application.triggerNextExitCheck() - @pyqtSlot(str) - def updateFirmware(self, file: Union[str, QUrl]) -> None: - if not self._firmware_updater: - return - - self._firmware_updater.updateFirmware(file) - ## Reset USB device settings # def resetDeviceSettings(self) -> None: @@ -169,7 +160,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): self._baud_rate = baud_rate def connect(self): - self._firmware_name = None # after each connection ensure that the firmware name is removed + self._firmware_name = None # after each connection ensure that the firmware name is removed if self._baud_rate is None: if self._use_auto_detect: