diff options
author | fieldOfView <aldo@fieldofview.com> | 2018-10-03 10:17:51 +0300 |
---|---|---|
committer | fieldOfView <aldo@fieldofview.com> | 2018-10-03 10:17:51 +0300 |
commit | 718ac0a30731dec368422b5d230945ee09f5595e (patch) | |
tree | f6e362a346a492995432c765781e2e9f1c82b14a /plugins/UltimakerMachineActions | |
parent | b4e186ce789c920ab4a1387910ea4a89ad3ce843 (diff) |
Create firmware update progress window from QML
Diffstat (limited to 'plugins/UltimakerMachineActions')
-rw-r--r-- | plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.py | 43 | ||||
-rw-r--r-- | plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml | 107 |
2 files changed, 139 insertions, 11 deletions
diff --git a/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.py b/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.py index 1f0e640f04..671ed22d5a 100644 --- a/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.py +++ b/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.py @@ -1,19 +1,58 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + from UM.Application import Application from UM.Settings.DefinitionContainer import DefinitionContainer from cura.MachineAction import MachineAction from UM.i18n import i18nCatalog from UM.Settings.ContainerRegistry import ContainerRegistry +from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject +from typing import Optional + +MYPY = False +if MYPY: + from cura.PrinterOutput.FirmwareUpdater import FirmwareUpdater + catalog = i18nCatalog("cura") ## Upgrade the firmware of a machine by USB with this action. class UpgradeFirmwareMachineAction(MachineAction): - def __init__(self): + def __init__(self) -> None: super().__init__("UpgradeFirmware", catalog.i18nc("@action", "Upgrade Firmware")) self._qml_url = "UpgradeFirmwareMachineAction.qml" ContainerRegistry.getInstance().containerAdded.connect(self._onContainerAdded) - def _onContainerAdded(self, container): + self._active_output_device = None + + Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated) + + def _onEngineCreated(self) -> None: + Application.getInstance().getMachineManager().outputDevicesChanged.connect(self._onOutputDevicesChanged) + + def _onContainerAdded(self, container) -> 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"): Application.getInstance().getMachineActionManager().addSupportedAction(container.getId(), self.getKey()) + + def _onOutputDevicesChanged(self) -> None: + if self._active_output_device: + self._active_output_device.activePrinter.getController().canUpdateFirmwareChanged.disconnect(self._onControllerCanUpdateFirmwareChanged) + output_devices = Application.getInstance().getMachineManager().printerOutputDevices + print(output_devices) + self._active_output_device = output_devices[0] if output_devices else None + if self._active_output_device: + self._active_output_device.activePrinter.getController().canUpdateFirmwareChanged.connect(self._onControllerCanUpdateFirmwareChanged) + + self.outputDeviceCanUpdateFirmwareChanged.emit() + + def _onControllerCanUpdateFirmwareChanged(self) -> None: + self.outputDeviceCanUpdateFirmwareChanged.emit() + + outputDeviceCanUpdateFirmwareChanged = pyqtSignal() + @pyqtProperty(QObject, notify = outputDeviceCanUpdateFirmwareChanged) + def firmwareUpdater(self) -> Optional["firmwareUpdater"]: + if self._active_output_device and self._active_output_device.activePrinter.getController().can_update_firmware: + return self._active_output_device.getFirmwareUpdater() + + return None
\ No newline at end of file diff --git a/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml b/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml index 1d0aabcae3..1c1f39edd0 100644 --- a/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml +++ b/plugins/UltimakerMachineActions/UpgradeFirmwareMachineAction.qml @@ -1,4 +1,4 @@ -// Copyright (c) 2016 Ultimaker B.V. +// Copyright (c) 2018 Ultimaker B.V. // Cura is released under the terms of the LGPLv3 or higher. import QtQuick 2.2 @@ -59,7 +59,8 @@ Cura.MachineAction enabled: parent.firmwareName != "" && canUpdateFirmware onClicked: { - activeOutputDevice.updateFirmware(parent.firmwareName) + firmwareUpdateWindow.visible = true; + activeOutputDevice.updateFirmware(parent.firmwareName); } } Button @@ -78,7 +79,7 @@ Cura.MachineAction { width: parent.width wrapMode: Text.WordWrap - visible: !printerConnected + visible: !printerConnected && !firmwareUpdateWindow.visible text: catalog.i18nc("@label", "Firmware can not be upgraded because there is no connection with the printer."); } @@ -89,14 +90,102 @@ Cura.MachineAction visible: printerConnected && !canUpdateFirmware text: catalog.i18nc("@label", "Firmware can not be upgraded because the connection with the printer does not support upgrading firmware."); } + } - FileDialog + FileDialog + { + id: customFirmwareDialog + title: catalog.i18nc("@title:window", "Select custom firmware") + nameFilters: "Firmware image files (*.hex)" + selectExisting: true + onAccepted: { - id: customFirmwareDialog - title: catalog.i18nc("@title:window", "Select custom firmware") - nameFilters: "Firmware image files (*.hex)" - selectExisting: true - onAccepted: activeOutputDevice.updateFirmware(fileUrl) + firmwareUpdateWindow.visible = true; + activeOutputDevice.updateFirmware(fileUrl); + } + } + + UM.Dialog + { + id: firmwareUpdateWindow + + width: minimumWidth + minimumWidth: 500 * screenScaleFactor + height: minimumHeight + minimumHeight: 100 * screenScaleFactor + + modality: Qt.ApplicationModal + + title: catalog.i18nc("@title:window","Firmware Update") + + Column + { + anchors.fill: parent + + Label + { + anchors + { + left: parent.left + right: parent.right + } + + text: { + if(manager.firmwareUpdater == null) + { + return ""; + } + switch (manager.firmwareUpdater.firmwareUpdateState) + { + case 0: + return ""; //Not doing anything (eg; idling) + case 1: + return catalog.i18nc("@label","Updating firmware."); + case 2: + return catalog.i18nc("@label","Firmware update completed."); + case 3: + return catalog.i18nc("@label","Firmware update failed due to an unknown error."); + case 4: + return catalog.i18nc("@label","Firmware update failed due to an communication error."); + case 5: + return catalog.i18nc("@label","Firmware update failed due to an input/output error."); + case 6: + return catalog.i18nc("@label","Firmware update failed due to missing firmware."); + } + } + + wrapMode: Text.Wrap + } + + ProgressBar + { + id: prog + value: (manager.firmwareUpdater != null) ? manager.firmwareUpdater.firmwareProgress : 0 + minimumValue: 0 + maximumValue: 100 + indeterminate: + { + if(manager.firmwareUpdater == null) + { + return false; + } + return manager.firmwareUpdater.firmwareProgress < 1 && manager.firmwareUpdater.firmwareProgress > 0; + } + anchors + { + left: parent.left; + right: parent.right; + } + } } + + rightButtons: [ + Button + { + text: catalog.i18nc("@action:button","Close"); + enabled: (manager.firmwareUpdater != null) ? manager.firmwareUpdater.firmwareUpdateState != 1 : true; + onClicked: firmwareUpdateWindow.visible = false; + } + ] } }
\ No newline at end of file |