mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Move updateFirmware to PrinterOutputDevice...
along with codestyle and typing fixes
This commit is contained in:
parent
04bca109ba
commit
a36deea651
7 changed files with 34 additions and 34 deletions
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
@ -231,3 +232,10 @@ class PrinterOutputDevice(QObject, OutputDevice):
|
|||
|
||||
def getFirmwareUpdater(self) -> Optional["FirmwareUpdater"]:
|
||||
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)
|
|
@ -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")
|
||||
|
||||
|
@ -33,7 +34,7 @@ class FirmwareUpdaterMachineAction(MachineAction):
|
|||
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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue