Create firmware update progress window from QML

This commit is contained in:
fieldOfView 2018-10-03 09:17:51 +02:00
parent b4e186ce78
commit 718ac0a307
5 changed files with 151 additions and 122 deletions

View file

@ -3,26 +3,25 @@
from PyQt5.QtCore import QObject, QUrl, pyqtSignal, pyqtProperty
from UM.Resources import Resources
from cura.PrinterOutputDevice import PrinterOutputDevice
from cura.CuraApplication import CuraApplication
from enum import IntEnum
from threading import Thread
from typing import Union
MYPY = False
if MYPY:
from cura.PrinterOutputDevice import PrinterOutputDevice
class FirmwareUpdater(QObject):
firmwareProgressChanged = pyqtSignal()
firmwareUpdateStateChanged = pyqtSignal()
def __init__(self, output_device: PrinterOutputDevice) -> None:
def __init__(self, output_device: "PrinterOutputDevice") -> None:
super().__init__()
self._output_device = output_device
self._update_firmware_thread = Thread(target=self._updateFirmware, daemon=True)
self._firmware_view = None
self._firmware_location = ""
self._firmware_progress = 0
self._firmware_update_state = FirmwareUpdateState.idle
@ -33,7 +32,7 @@ class FirmwareUpdater(QObject):
self._firmware_location = QUrl(file).toLocalFile()
else:
self._firmware_location = file
self._showFirmwareInterface()
self._setFirmwareUpdateState(FirmwareUpdateState.updating)
self._update_firmware_thread.start()
@ -41,20 +40,6 @@ class FirmwareUpdater(QObject):
def _updateFirmware(self) -> None:
raise NotImplementedError("_updateFirmware needs to be implemented")
## Show firmware interface.
# This will create the view if its not already created.
def _showFirmwareInterface(self) -> None:
if self._firmware_view is None:
path = Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "FirmwareUpdateWindow.qml")
self._firmware_view = CuraApplication.getInstance().createQmlComponent(path, {"manager": self})
if not self._firmware_view:
return
self._onFirmwareProgress(0)
self._setFirmwareUpdateState(FirmwareUpdateState.idle)
self._firmware_view.show()
## Cleanup after a succesful update
def _cleanupAfterUpdate(self) -> None:
# Clean up for next attempt.